Skip to content

Commit e23a016

Browse files
author
Ben
committed
Merge branch '5.x-dev' into m20607-copy-code
2 parents a2aa193 + d3d9819 commit e23a016

10 files changed

Lines changed: 10349 additions & 4540 deletions

File tree

Context/WebContext.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
use Piwik\Container\StaticContainer;
1313
use Piwik\Development;
1414
use Piwik\Piwik;
15+
use Piwik\Url;
1516
use Piwik\Plugins\TagManager\Context\Storage\StorageInterface;
1617
use Piwik\Plugins\TagManager\Context\WebContext\JavaScriptTagManagerLoader;
1718
use Piwik\Plugins\TagManager\Context\BaseContext\TemplateLocator;
19+
use Piwik\Plugins\TagManager\Input\AccessValidator;
1820
use Piwik\Plugins\TagManager\Model\Container;
1921
use Piwik\Plugins\TagManager\Model\Environment;
2022
use Piwik\Plugins\TagManager\Model\Salt;
2123
use Piwik\Plugins\TagManager\Model\Tag;
2224
use Piwik\Plugins\TagManager\Model\Trigger;
2325
use Piwik\Plugins\TagManager\Model\Variable;
26+
use Piwik\Plugins\TagManager\SystemSettings;
27+
use Piwik\Plugins\TagManager\Template\Trigger\PageViewTrigger;
2428
use Piwik\Plugins\TagManager\Template\Variable\VariablesProvider;
2529
use Piwik\SettingsPiwik;
2630

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

297+
private function getPageViewTriggerEditUrl($idSite, $idContainer)
298+
{
299+
$url = '';
300+
$settings = new SystemSettings();
301+
$validator = new AccessValidator($settings);
302+
if (!$validator->hasWriteCapability($idSite)) {
303+
return $url;
304+
}
305+
$container = Request::processRequest('TagManager.getContainer', ['idSite' => $idSite, 'idContainer' => $idContainer]);
306+
if (!empty($container['draft']['idcontainerversion'])) {
307+
$triggers = Request::processRequest('TagManager.getContainerTriggers', ['idSite' => $idSite, 'idContainer' => $idContainer, 'idContainerVersion' => $container['draft']['idcontainerversion']]);
308+
if (!empty($triggers)) {
309+
foreach ($triggers as $trigger) {
310+
if (!empty($trigger['type']) && $trigger['type'] == PageViewTrigger::ID) {
311+
$url = SettingsPiwik::getPiwikUrl() . 'index.php?' . Url::getQueryStringFromParameters([
312+
'module' => 'TagManager',
313+
'action' => 'manageTriggers',
314+
'idSite' => $idSite,
315+
'idContainer' => $idContainer,
316+
]) . '#idTrigger=' . $trigger['idtrigger'];
317+
break;
318+
}
319+
}
320+
}
321+
}
322+
return $url;
323+
}
324+
292325
}

TagManager.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,12 @@ public function addTagManagerCode(&$out)
268268
$out .= $view->render();
269269
}
270270

271-
public function embedReactTagManagerTrackingCode(&$out, $step2, $step3)
271+
public function embedReactTagManagerTrackingCode(&$out)
272272
{
273273
Piwik::checkUserHasSomeViewAccess();
274274
$model = $this->getContainerModel();
275275
$view = new View("@TagManager/trackingCodeReact");
276276
$view->action = Piwik::getAction();
277-
$view->step2 = $step2;
278-
$view->step3 = $step3;
279277
$view->showContainerRow = $model->getNumContainersTotal() > 1;
280278
$out .= $view->render();
281279
}
@@ -817,6 +815,16 @@ public function getClientSideTranslationKeys(&$result)
817815
$result[] = 'TagManager_UrlParameterVariableNameDescription';
818816
$result[] = 'TagManager_MatomoTagManagerTrackingInfoLine1';
819817
$result[] = 'TagManager_MatomoTagManagerTrackingInfoLine2';
818+
$result[] = 'TagManager_SiteWithoutDataReactIntro';
819+
$result[] = 'TagManager_SiteWithoutDataReactFollowStep1';
820+
$result[] = 'TagManager_SiteWithoutDataReactFollowStep1_1';
821+
$result[] = 'TagManager_SiteWithoutDataReactFollowStep1_2';
822+
$result[] = 'TagManager_SiteWithoutDataReactFollowStep1_3';
823+
$result[] = 'TagManager_SiteWithoutDataReactFollowStep1_4';
824+
$result[] = 'TagManager_SiteWithoutDataReactFollowStep2';
825+
$result[] = 'TagManager_SiteWithoutDataReactFollowStep3';
826+
$result[] = 'TagManager_SiteWithoutDataReactFollowStepCompleted';
827+
$result[] = 'SitesManager_SiteWithoutDataCloudflareFollowStepsIntro';
820828
}
821829

822830
public function getStylesheetFiles(&$stylesheets)

lang/en.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,15 @@
895895
"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\".",
896896
"UserInteractionTriggerName": "User Interaction",
897897
"UserInteractionTriggerDescription": "Triggered when user interacts with the site, i. e. touch, move, scroll or mouse click event is executed by the user on site.",
898-
"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."
898+
"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.",
899+
"SiteWithoutDataReactIntro": "Tracking your React.js website or app is easy with Matomo, even for Single Page Applications.",
900+
"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:",
901+
"SiteWithoutDataReactFollowStep1_1": "Navigate to your %1$sPageview trigger%2$s.",
902+
"SiteWithoutDataReactFollowStep1_2": "Replace \"%1$sPage URL%2$s\" with \"%1$sHistory Source%2$s\".",
903+
"SiteWithoutDataReactFollowStep1_3": "Add \"%1$shashchange%2$s\" as the input value. %3$sLearn more in this guide%4$s.",
904+
"SiteWithoutDataReactFollowStep1_4": "Click \"%1$sUPDATE%2$s\" to save your changes.",
905+
"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.",
906+
"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.",
907+
"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."
899908
}
900909
}

templates/trackingCodeReact.twig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
vue-entry="TagManager.TrackingCodeReactPage"
33
current-action="{{ action|json_encode }}"
44
show-container-row="{{ showContainerRow|json_encode }}"
5-
step2="{{ step2|json_encode }}"
6-
step3="{{ step3|json_encode }}"
75
>
86
</div>

0 commit comments

Comments
 (0)