Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code to make MTM as recommended install by default instead of JS code #22420

Draft
wants to merge 7 commits into
base: 5.x-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions plugins/SitesManager/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -250,7 +251,7 @@ public function getTrackingMethodsForSite()
];

$recommendedMethod = null;
$matomoIndex = null;
$matomoIndex = $matomoTagManagerIndex = null;
AltamashShaikh marked this conversation as resolved.
Show resolved Hide resolved

foreach ($trackingMethods as $index => $tab) {
// Note: We recommend the first method that is recommended (after sorting by priority)
Expand All @@ -263,12 +264,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<h3>' . Piwik::translate('SitesManager_SiteWithoutDataMatomoTagManager') . '</h3>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/UI/expected-screenshots/EmptySite_trackingCode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 1 addition & 17 deletions tests/UI/specs/EmptySite_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -61,22 +61,6 @@ describe("EmptySite", function () {
expect(await pageElement.screenshot()).to.matchImage('trackingCode');
});

it('should show the advanced tracking options when clicked', async function () {
AltamashShaikh marked this conversation as resolved.
Show resolved Hide resolved
await page.evaluate(() => $('.advance-option a').click());

// wait till checkbox isn't disabled anymore, which means loading has finished.
await page.waitForFunction(() => !$('#javascript-tracking-all-subdomains').is(':disabled'));

const pageElement = await page.$('.page');
expect(await pageElement.screenshot()).to.matchImage('showAdvancedTrackingOptions');
});

it('should hide the advanced tracking options when clicked', async function () {
await page.evaluate(() => $('.advance-option a').click());

await page.waitForSelector('#javascript-advanced-options', {hidden: true, timeout: 1000});
});

it('should show SPA/PWA details when clicked', async function () {
await page.click('#start-tracking-back');
await page.evaluate(() => $('#start-tracking-method-list a[href="#spapwa"]')[0].click());
Expand Down
Loading