Skip to content

Commit

Permalink
Merge branch '5.x-dev' into m20607-copy-code
Browse files Browse the repository at this point in the history
  • Loading branch information
bx80 committed Jun 14, 2023
2 parents a2aa193 + d3d9819 commit e23a016
Show file tree
Hide file tree
Showing 10 changed files with 10,349 additions and 4,540 deletions.
35 changes: 34 additions & 1 deletion Context/WebContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
use Piwik\Container\StaticContainer;
use Piwik\Development;
use Piwik\Piwik;
use Piwik\Url;
use Piwik\Plugins\TagManager\Context\Storage\StorageInterface;
use Piwik\Plugins\TagManager\Context\WebContext\JavaScriptTagManagerLoader;
use Piwik\Plugins\TagManager\Context\BaseContext\TemplateLocator;
use Piwik\Plugins\TagManager\Input\AccessValidator;
use Piwik\Plugins\TagManager\Model\Container;
use Piwik\Plugins\TagManager\Model\Environment;
use Piwik\Plugins\TagManager\Model\Salt;
use Piwik\Plugins\TagManager\Model\Tag;
use Piwik\Plugins\TagManager\Model\Trigger;
use Piwik\Plugins\TagManager\Model\Variable;
use Piwik\Plugins\TagManager\SystemSettings;
use Piwik\Plugins\TagManager\Template\Trigger\PageViewTrigger;
use Piwik\Plugins\TagManager\Template\Variable\VariablesProvider;
use Piwik\SettingsPiwik;

Expand Down Expand Up @@ -285,8 +289,37 @@ public function getInstallInstructionsReact($container, $environment)
return [[
'description' => Piwik::translate('TagManager_ContextWebInstallInstructions', array('"<head>"')),
'embedCode' => $embedCode,
'helpUrl' => 'https://developer.matomo.org/guides/tagmanager/embedding'
'helpUrl' => 'https://developer.matomo.org/guides/tagmanager/embedding',
'pageViewTriggerEditUrl' => $this->getPageViewTriggerEditUrl($container['idsite'], $container['idcontainer'])
]];
}

private function getPageViewTriggerEditUrl($idSite, $idContainer)
{
$url = '';
$settings = new SystemSettings();
$validator = new AccessValidator($settings);
if (!$validator->hasWriteCapability($idSite)) {
return $url;
}
$container = Request::processRequest('TagManager.getContainer', ['idSite' => $idSite, 'idContainer' => $idContainer]);
if (!empty($container['draft']['idcontainerversion'])) {
$triggers = Request::processRequest('TagManager.getContainerTriggers', ['idSite' => $idSite, 'idContainer' => $idContainer, 'idContainerVersion' => $container['draft']['idcontainerversion']]);
if (!empty($triggers)) {
foreach ($triggers as $trigger) {
if (!empty($trigger['type']) && $trigger['type'] == PageViewTrigger::ID) {
$url = SettingsPiwik::getPiwikUrl() . 'index.php?' . Url::getQueryStringFromParameters([
'module' => 'TagManager',
'action' => 'manageTriggers',
'idSite' => $idSite,
'idContainer' => $idContainer,
]) . '#idTrigger=' . $trigger['idtrigger'];
break;
}
}
}
}
return $url;
}

}
14 changes: 11 additions & 3 deletions TagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,12 @@ public function addTagManagerCode(&$out)
$out .= $view->render();
}

public function embedReactTagManagerTrackingCode(&$out, $step2, $step3)
public function embedReactTagManagerTrackingCode(&$out)
{
Piwik::checkUserHasSomeViewAccess();
$model = $this->getContainerModel();
$view = new View("@TagManager/trackingCodeReact");
$view->action = Piwik::getAction();
$view->step2 = $step2;
$view->step3 = $step3;
$view->showContainerRow = $model->getNumContainersTotal() > 1;
$out .= $view->render();
}
Expand Down Expand Up @@ -817,6 +815,16 @@ public function getClientSideTranslationKeys(&$result)
$result[] = 'TagManager_UrlParameterVariableNameDescription';
$result[] = 'TagManager_MatomoTagManagerTrackingInfoLine1';
$result[] = 'TagManager_MatomoTagManagerTrackingInfoLine2';
$result[] = 'TagManager_SiteWithoutDataReactIntro';
$result[] = 'TagManager_SiteWithoutDataReactFollowStep1';
$result[] = 'TagManager_SiteWithoutDataReactFollowStep1_1';
$result[] = 'TagManager_SiteWithoutDataReactFollowStep1_2';
$result[] = 'TagManager_SiteWithoutDataReactFollowStep1_3';
$result[] = 'TagManager_SiteWithoutDataReactFollowStep1_4';
$result[] = 'TagManager_SiteWithoutDataReactFollowStep2';
$result[] = 'TagManager_SiteWithoutDataReactFollowStep3';
$result[] = 'TagManager_SiteWithoutDataReactFollowStepCompleted';
$result[] = 'SitesManager_SiteWithoutDataCloudflareFollowStepsIntro';
}

public function getStylesheetFiles(&$stylesheets)
Expand Down
11 changes: 10 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,15 @@
"UrlParameterVariableNameDescription": "For example when your page has URL parameters such as \"?lang=NZ\" and you want to get the value \"NZ\", then you need to enter \"lang\".",
"UserInteractionTriggerName": "User Interaction",
"UserInteractionTriggerDescription": "Triggered when user interacts with the site, i. e. touch, move, scroll or mouse click event is executed by the user on site.",
"UserInteractionTriggerHelp": "This trigger is triggered when the user interacts with the page (touch, mousemove, scroll, mouse click). Loading and processing JS on a website usually blocks page rendering and impacts performance. Defering JS via this trigger until after the page was rendered and user interacts with the page can be useful to avoid negative impacts on Page Speed and Core Web Vitals scores. Note: User interaction is triggered only once when the user interacts with the page for the first time after page load."
"UserInteractionTriggerHelp": "This trigger is triggered when the user interacts with the page (touch, mousemove, scroll, mouse click). Loading and processing JS on a website usually blocks page rendering and impacts performance. Defering JS via this trigger until after the page was rendered and user interacts with the page can be useful to avoid negative impacts on Page Speed and Core Web Vitals scores. Note: User interaction is triggered only once when the user interacts with the page for the first time after page load.",
"SiteWithoutDataReactIntro": "Tracking your React.js website or app is easy with Matomo, even for Single Page Applications.",
"SiteWithoutDataReactFollowStep1": "%1$sSkip this step%2$s if you are not tracking a %1$sSingle Page Application (SPA)%2$s or %1$sProgressive Web Application (PWA)%2$s. For SPA/PWAs, the most common way to accurately track pageviews is by using the %1$sHistory Changes trigger%2$s:",
"SiteWithoutDataReactFollowStep1_1": "Navigate to your %1$sPageview trigger%2$s.",
"SiteWithoutDataReactFollowStep1_2": "Replace \"%1$sPage URL%2$s\" with \"%1$sHistory Source%2$s\".",
"SiteWithoutDataReactFollowStep1_3": "Add \"%1$shashchange%2$s\" as the input value. %3$sLearn more in this guide%4$s.",
"SiteWithoutDataReactFollowStep1_4": "Click \"%1$sUPDATE%2$s\" to save your changes.",
"SiteWithoutDataReactFollowStep2": "Select the right container for your website. %1$sNote:%2$s Matomo automatically pre-configures a container when you add a site. By default, this container is selected in the fields below. If you are planning to use a single container for multiple websites, make sure to select that specific container.",
"SiteWithoutDataReactFollowStep3": "Inject the %1$sMatomo Tag Manager JS%2$s code into your %3$s (or other relevant files), we recommend doing this using the \"%4$s\" method. The example below shows how to add the %1$sMatomo Tag Manager JS%2$s code into a \"%5$s\" app in %6$s.",
"SiteWithoutDataReactFollowStepCompleted": "%1$sCongratulations!%2$s You have successfully installed the Matomo Analytics tracking code via the Matomo Tag Manager. To verify that hits are being tracked, visit your website and check that this data is visible in your Matomo instance."
}
}
2 changes: 0 additions & 2 deletions templates/trackingCodeReact.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
vue-entry="TagManager.TrackingCodeReactPage"
current-action="{{ action|json_encode }}"
show-container-row="{{ showContainerRow|json_encode }}"
step2="{{ step2|json_encode }}"
step3="{{ step3|json_encode }}"
>
</div>
Loading

0 comments on commit e23a016

Please sign in to comment.