Skip to content

Commit

Permalink
further adjustments to various method details
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Sep 15, 2023
1 parent 514f67a commit 19b5bc3
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 73 deletions.
60 changes: 41 additions & 19 deletions plugins/SitesManager/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ public function getTrackingMethodsForSite()

foreach ($this->siteContentDetector->getSiteContentDetectionsByType() as $detections) {
foreach ($detections as $obj) {
$tabContent = $obj->renderInstructionsTab($this->siteContentDetector);
$othersInstruction = $obj->renderOthersInstruction($this->siteContentDetector);
$instructionUrl = $obj->getInstructionUrl();
$tabContent = $obj->renderInstructionsTab($this->siteContentDetector);
$othersInstruction = $obj->renderOthersInstruction($this->siteContentDetector);
$instructionUrl = $obj->getInstructionUrl();
$recommendationDetails = $obj->getRecommendationDetails($this->siteContentDetector);

/**
* Event that can be used to manipulate the content of a certain tab on the no data page
Expand All @@ -177,7 +178,10 @@ public function getTrackingMethodsForSite()
'content' => $tabContent,
'icon' => $obj::getIcon(),
'priority' => $obj::getPriority(),
'wasDetected' => $this->siteContentDetector->wasDetected($obj::getId())
'wasDetected' => $this->siteContentDetector->wasDetected($obj::getId()),
'recommendationTitle' => $recommendationDetails['title'],
'recommendationText' => $recommendationDetails['text'],
'recommendationButton' => $recommendationDetails['button'],
];
}

Expand Down Expand Up @@ -219,33 +223,51 @@ public function getTrackingMethodsForSite()

// add integration and others tab
$trackingMethods[] = [
'id' => 'Integrations',
'name' => Piwik::translate('SitesManager_Integrations'),
'type' => SiteContentDetectionAbstract::TYPE_OTHER,
'content' => $this->renderIntegrationsTab($instructionUrls),
'icon' => './plugins/SitesManager/images/integrations.svg',
'priority' => 10000,
'wasDetected' => false
'id' => 'Integrations',
'name' => Piwik::translate('SitesManager_Integrations'),
'type' => SiteContentDetectionAbstract::TYPE_OTHER,
'content' => $this->renderIntegrationsTab($instructionUrls),
'icon' => './plugins/SitesManager/images/integrations.svg',
'priority' => 10000,
'wasDetected' => false,
'recommendationTitle' => '',
'recommendationText' => '',
'recommendationButton' => '',
];
$trackingMethods[] = [
'id' => 'Other',
'name' => Piwik::translate('SitesManager_SiteWithoutDataOtherWays'),
'type' => SiteContentDetectionAbstract::TYPE_OTHER,
'content' => $this->renderOthersTab($othersInstructions),
'icon' => './plugins/SitesManager/images/others.svg',
'priority' => 10001,
'wasDetected' => false
'id' => 'Other',
'name' => Piwik::translate('SitesManager_SiteWithoutDataOtherWays'),
'type' => SiteContentDetectionAbstract::TYPE_OTHER,
'content' => $this->renderOthersTab($othersInstructions),
'icon' => './plugins/SitesManager/images/others.svg',
'priority' => 10001,
'wasDetected' => false,
'recommendationTitle' => '',
'recommendationText' => '',
'recommendationButton' => '',
];

$recommendedMethod = null;
$matomoIndex = null;

foreach ($trackingMethods as $index => $tab) {
// Note: We never show Matomo (JavaScript Code) as recommended even if it was detected
// Note: We recommend the first method that was detected - unless it was Matomo JavaScript Tracker itself
// as that should only be recommended if nothing else was detected
if ($tab['wasDetected'] && $tab['id'] !== Matomo::getId()) {
$recommendedMethod = $tab;
unset($trackingMethods[$index]);
break;
}

if ($tab['id'] === Matomo::getId()) {
$matomoIndex = $index;
}
}

// fall back to javascript code recommendation if nothing was detected
if (null === $recommendedMethod && null !== $matomoIndex) {
$recommendedMethod = $trackingMethods[$matomoIndex];
unset($trackingMethods[$matomoIndex]);
}

Json::sendHeaderJSON();
Expand Down
7 changes: 7 additions & 0 deletions plugins/SitesManager/SiteContentDetection/Matomo.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public function renderInstructionsTab(SiteContentDetector $detector): string
return $view->render();
}

public function getRecommendationDetails(SiteContentDetector $detector): array
{
$details = parent::getRecommendationDetails($detector);
$details['text'] = Piwik::translate('SitesManager_SetupMatomoTracker');
return $details;
}

private function getNotification(SiteContentDetector $detector = null): array
{
if (empty($detector)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Piwik\Plugins\SitesManager\SiteContentDetection;

use Piwik\Piwik;
use Piwik\SiteContentDetector;

abstract class SiteContentDetectionAbstract
Expand Down Expand Up @@ -110,4 +111,19 @@ public function renderOthersInstruction(SiteContentDetector $detector): string
{
return '';
}

/**
* Returns details used to render the recommendation on no data screen
*
* @param SiteContentDetector $detector
* @return array
*/
public function getRecommendationDetails(SiteContentDetector $detector): array
{
return [
'title' => Piwik::translate('SitesManager_SiteWithoutDataInstallWithXRecommendation', [static::getName()]),
'text' => Piwik::translate('SitesManager_SiteWithoutDataRecommendationText', [static::getName()]),
'button' => Piwik::translate('SitesManager_SiteWithoutDataInstallWithX', [static::getName()]),
];
}
}
6 changes: 6 additions & 0 deletions plugins/SitesManager/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@
"SiteWithoutDataOtherInstallMethods": "Other methods to install Matomo",
"SiteWithoutDataOtherInstallMethodsIntro": "We offer multiple tracking paths — pick yours to unlock data-driven success.",
"SiteWithoutDataHidePageForHour": "Hide page for an hour",
"MoreMethods": "More methods to install Matomo",
"CmsAndWebsiteBuilders": "CMS and website builders",
"SiteWithoutDataRecommendationText": "We have detected %1$s on your site, so you can set up Matomo within a few minutes with our official %1$s integration.",
"SiteWithoutDataInstallWithXRecommendation": "Install Matomo with %1$s (recommended for you)",
"SiteWithoutDataInstallWithX": "Install with %1$s",
"SetupMatomoTracker": "You can set up Matomo within a few minutes by following our step-by-step guide.",
"EmailInstructionsButtonText": "Email instructions",
"SiteWithoutDataVueDescription": "You can use the \"%1$s\" npm package to integrate Matomo to track data, follow the instructions from this %2$sguide%3$s.",
"VueDetected": "Vue.js was detected on your website. Did you know you can use the \"%1$s\" npm package to integrate Matomo into your site? %2$sLearn more in this guide%3$s.",
Expand Down
9 changes: 1 addition & 8 deletions plugins/SitesManager/stylesheets/SitesManager.less
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,6 @@ td.editable-site-field:hover {

}

.start-tracking-method {
display: none;

p {
padding-bottom: 0.25rem;
}
}

h3 {
font-weight: bold;
}
Expand Down Expand Up @@ -381,6 +373,7 @@ td.editable-site-field:hover {

.tagManagerTrackingCode {
padding-top: 1rem;
display: inline-block;

> .row, > .row .row {
margin-bottom: -0.5rem !important;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h2>{{ 'SitesManager_StepByStepGuide'|translate }}</h2>

{% if wasDetected %}
<div class="system notification notification-info">
{{ 'SitesManager_CloudflareDetected'|translate('<a target="_blank" rel="noreferrer noopener" href="https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-cloudflare-setup/">','</a>')|raw }}
Expand Down
2 changes: 2 additions & 0 deletions plugins/SitesManager/templates/_gtmTabInstructions.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h2>{{ 'SitesManager_StepByStepGuide'|translate }}</h2>

{% if wasDetected %}
<div class="system notification notification-info">
{{ 'SitesManager_GTMDetected'|translate('<a href="https://matomo.org/faq/tag-manager/migrating-from-google-tag-manager/" target="_blank" rel="noreferrer noopener">', '</a>')|raw }}
Expand Down
2 changes: 2 additions & 0 deletions plugins/SitesManager/templates/_integrationsTab.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h2>{{ 'SitesManager_CmsAndWebsiteBuilders'|translate }}</h2>

{% if instruction %}
<p>{{ instruction|raw }}</p>

Expand Down
2 changes: 2 additions & 0 deletions plugins/SitesManager/templates/_matomoTabInstructions.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h2>{{ 'SitesManager_StepByStepGuide'|translate }}</h2>

{% if notificationMessage is defined and notificationMessage %}
<p></p><p></p>
<div class="system notification notification-info {{ isNotificationsMerged ? ' merged-notification' : ''}}">
Expand Down
2 changes: 2 additions & 0 deletions plugins/SitesManager/templates/_othersTab.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h2>{{ 'SitesManager_MoreMethods'|translate }}</h2>

<p>{{ 'SitesManager_OtherWaysTabDescription'|translate }}</p>
<p>Matomo URL: <code vue-directive="CoreHome.CopyToClipboard">{{ matomoUrl }}</code></p>
<p>{{ 'SitesManager_EmailInstructionsYourSiteId'|translate('<code vue-directive="CoreHome.CopyToClipboard">' ~ idSite ~ '</code>')|raw }}</p>
Expand Down
2 changes: 2 additions & 0 deletions plugins/SitesManager/templates/_vueTabInstructions.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h2>{{ 'SitesManager_StepByStepGuide'|translate }}</h2>

{% if wasDetected %}
<div class="system notification notification-info">
{{ 'SitesManager_VueDetected'|translate('<a target="_blank" rel="noreferrer noopener" href="https://github.com/AmazingDreams/vue-matomo">vue-matomo</a>','<a target="_blank" rel="noreferrer noopener" href="https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-websites-that-use-vue-js/">','</a>')|raw }}
Expand Down
10 changes: 2 additions & 8 deletions plugins/SitesManager/templates/_wordpressTabInstructions.twig
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<script type="text/javascript" charset="utf-8">
$(document).on( 'click', '#wordpress-email-instructions', function() {
var emailTrackingCodeLink = $('.emailTrackingCode');
if (emailTrackingCodeLink.length) {
emailTrackingCodeLink[0].click();
}
});
</script>
<h2>{{ 'SitesManager_StepByStepGuide'|translate }}</h2>

<p>{{ 'SitesManager_SiteWithoutDataWordpressIntroductionLine1'|translate('<a target="_blank" rel="noreferrer noopener" href="https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-wordpress/">', '</a>')|raw }}</p>
<p>{{ 'SitesManager_SiteWithoutDataWordpressIntroductionLine2'|translate('<a target="_blank" rel="noreferrer noopener" href="https://matomo.org/faq/new-to-piwik/how-do-i-manually-insert-the-matomo-tracking-code-on-wordpress/">', '</a>', '<a target="_blank" rel="noreferrer noopener" href="https://matomo.org/faq/new-to-piwik/start-tracking-with-a-wordpress-com-site-that-cannot-use-plugins/">', '</a>')|raw }}</p>
<br>
Expand Down
Loading

0 comments on commit 19b5bc3

Please sign in to comment.