diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index 077b8669d53..73bedbcbc58 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -16,6 +16,7 @@ use Piwik\Piwik; use Piwik\Plugin\Manager; use Piwik\Plugins\SitesManager\SiteContentDetection\Matomo; +use Piwik\Plugins\SitesManager\SiteContentDetection\MatomoTagManager; use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract; use Piwik\Plugins\SitesManager\SiteContentDetection\WordPress; use Piwik\SiteContentDetector; @@ -251,6 +252,7 @@ public function getTrackingMethodsForSite() $recommendedMethod = null; $matomoIndex = null; + $matomoTagManagerIndex = null; foreach ($trackingMethods as $index => $tab) { // Note: We recommend the first method that is recommended (after sorting by priority) @@ -263,12 +265,20 @@ public function getTrackingMethodsForSite() if ($tab['id'] === Matomo::getId()) { $matomoIndex = $index; } + + if ($tab['id'] === MatomoTagManager::getId()) { + $matomoTagManagerIndex = $index; + } } - // fall back to javascript code recommendation if nothing was detected + // fall back to TagManager if plugin is active else fallback to javascript code recommendation if nothing was detected if (null === $recommendedMethod && null !== $matomoIndex) { - $recommendedMethod = $trackingMethods[$matomoIndex]; - unset($trackingMethods[$matomoIndex]); + $index = $matomoIndex; + if (null !== $matomoTagManagerIndex && Manager::getInstance()->isPluginActivated('TagManager')) { + $index = $matomoTagManagerIndex; + } + $recommendedMethod = $trackingMethods[$index]; + unset($trackingMethods[$index]); } Json::sendHeaderJSON(); diff --git a/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php b/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php index a240bf2bda5..6fdc9dbcec4 100644 --- a/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php +++ b/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php @@ -47,6 +47,15 @@ public function isDetected(?string $data = null, ?array $headers = null): bool return false; } + public function getRecommendationDetails(SiteContentDetector $detector): array + { + $details = parent::getRecommendationDetails($detector); + if (!$detector->wasDetected(self::getId())) { + $details['text'] = Piwik::translate('SitesManager_SetupMatomoTracker'); + } + return $details; + } + public function renderInstructionsTab(SiteContentDetector $detector): string { return '

' . Piwik::translate('SitesManager_SiteWithoutDataMatomoTagManager') . '

diff --git a/tests/UI/expected-screenshots/EmptySite_emptySiteDashboard.png b/tests/UI/expected-screenshots/EmptySite_emptySiteDashboard.png index 8c2cc090322..e47bb8bae05 100644 --- a/tests/UI/expected-screenshots/EmptySite_emptySiteDashboard.png +++ b/tests/UI/expected-screenshots/EmptySite_emptySiteDashboard.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e028f33300163b0bafb8db4f2f8189356e6d6e3d4d6730b653f4fab60f845431 -size 100042 +oid sha256:c61b8d454f1686e55acd009fae65440ae9feb87fe6344034f089573160c2525e +size 101010 diff --git a/tests/UI/expected-screenshots/EmptySite_trackingCode.png b/tests/UI/expected-screenshots/EmptySite_trackingCode.png index 243532ea708..625bda64317 100644 --- a/tests/UI/expected-screenshots/EmptySite_trackingCode.png +++ b/tests/UI/expected-screenshots/EmptySite_trackingCode.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:af0eb2652c8198650fcb15eccfe7f2226245e8e78a40ec7adfe9445acb1f4966 -size 112665 +oid sha256:ca6c9bcf9dd26e735d11ad27dd412fbf67f5645b0d35f6b5ace55bac50b133db +size 105195 diff --git a/tests/UI/expected-screenshots/EmptySite_trackingCodeJS.png b/tests/UI/expected-screenshots/EmptySite_trackingCodeJS.png new file mode 100644 index 00000000000..243532ea708 --- /dev/null +++ b/tests/UI/expected-screenshots/EmptySite_trackingCodeJS.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af0eb2652c8198650fcb15eccfe7f2226245e8e78a40ec7adfe9445acb1f4966 +size 112665 diff --git a/tests/UI/specs/EmptySite_spec.js b/tests/UI/specs/EmptySite_spec.js index 6344ad5d10a..b00c0019732 100644 --- a/tests/UI/specs/EmptySite_spec.js +++ b/tests/UI/specs/EmptySite_spec.js @@ -51,7 +51,7 @@ describe("EmptySite", function () { }); it('should show the tracking code when selected', async function () { - await page.evaluate(() => $('#start-tracking-detection a[href="#matomo"]')[0].click()); + await page.evaluate(() => $('#start-tracking-detection a[href="#matomotagmanager"]')[0].click()); // wait till url check field is filled with data, which means loading has finished. await page.waitForFunction(() => $('#baseUrl').val()); @@ -61,6 +61,16 @@ describe("EmptySite", function () { expect(await pageElement.screenshot()).to.matchImage('trackingCode'); }); + it('should show the JS tracking code', async function () { + await page.click('#start-tracking-back'); + await page.evaluate(() => $('#start-tracking-method-list a[href="#matomo"]')[0].click()); + + await makeTrackingCodeStatic(); + + const pageElement = await page.$('.page'); + expect(await pageElement.screenshot()).to.matchImage('trackingCodeJS'); + }); + it('should show the advanced tracking options when clicked', async function () { await page.evaluate(() => $('.advance-option a').click()); @@ -176,7 +186,7 @@ describe("EmptySite", function () { await page.goto(urlToTest); await page.waitForSelector('#start-tracking-method-list'); // wait till list is shown - await page.evaluate(() => $('#start-tracking-detection a[href="#matomo"]')[0].click()); + await page.evaluate(() => $('#start-tracking-method-list a[href="#matomo"]')[0].click()); // wait till url check field is filled with data, which means loading has finished. await page.waitForFunction(() => $('#baseUrl').val());