Skip to content

Commit

Permalink
Remove Cloudflare instruction from no data page (#21778)
Browse files Browse the repository at this point in the history
* Remove Cloudflare instruction from no data page

* adjust ui tests

* improve handling of cms instruction

* remove unused translation key

Co-authored-by: Marc Neudert <[email protected]>

---------

Co-authored-by: Marc Neudert <[email protected]>
  • Loading branch information
sgiehl and mneudert authored Jan 8, 2024
1 parent 5e2fbe6 commit 98cc5fe
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 127 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions plugins/SitesManager/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,17 @@ private function getCmsInstruction()
return '';
}

$detectedCms = $this->siteContentDetector->getSiteContentDetectionById(reset($detectedCMSes));
$detectedCms = null;

if (null === $detectedCms) {
foreach ($detectedCMSes as $detected) {
$detectedCms = $this->siteContentDetector->getSiteContentDetectionById($detected);

if (null !== $detectedCms && !empty($detectedCms::getInstructionUrl())) {
break;
}
}

if (null === $detectedCms || empty($detectedCms::getInstructionUrl())) {
return '';
}

Expand Down
43 changes: 0 additions & 43 deletions plugins/SitesManager/SiteContentDetection/Cloudflare.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@

namespace Piwik\Plugins\SitesManager\SiteContentDetection;

use Piwik\Piwik;
use Piwik\Request;
use Piwik\SiteContentDetector;
use Piwik\Url;
use Piwik\View;

class Cloudflare extends SiteContentDetectionAbstract
{
public static function getName(): string
Expand All @@ -33,16 +27,6 @@ public static function getContentType(): int
return self::TYPE_CMS;
}

public static function getInstructionUrl(): ?string
{
return Url::addCampaignParametersToMatomoLink('https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-cloudflare-setup/');
}

public static function getPriority(): int
{
return 40;
}

public function isDetected(?string $data = null, ?array $headers = null): bool
{
return (
Expand All @@ -54,31 +38,4 @@ public function isDetected(?string $data = null, ?array $headers = null): bool
!empty($headers['CF-RAY'])
);
}

public function renderInstructionsTab(SiteContentDetector $detector): string
{
$view = new View("@SitesManager/_cloudflareTabInstructions");
$view->idSite = Request::fromRequest()->getIntegerParameter('idSite');
$view->wasDetected = $detector->wasDetected(self::getId());
$view->sendHeadersWhenRendering = false;
return $view->render();
}

public function renderOthersInstruction(SiteContentDetector $detector): string
{
if ($detector->wasDetected(self::getId())) {
return ''; // don't show on others page if tab is being displayed
}

return sprintf(
'<p>%s</p>',
Piwik::translate(
'SitesManager_SiteWithoutDataCloudflareDescription',
[
'<a target="_blank" rel="noreferrer noopener" href="' . Url::addCampaignParametersToMatomoLink('https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-cloudflare-setup/') . '">',
'</a>'
]
)
);
}
}
1 change: 0 additions & 1 deletion plugins/SitesManager/SitesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ public function getClientSideTranslationKeys(&$translationKeys)
$translationKeys[] = 'SitesManager_ShowTrackingTag';
$translationKeys[] = 'SitesManager_SiteSearchUse';
$translationKeys[] = 'SitesManager_SiteWithoutDataChooseTrackingMethod';
$translationKeys[] = 'SitesManager_SiteWithoutDataCloudflareDescription';
$translationKeys[] = 'SitesManager_SiteWithoutDataGoogleTagManager';
$translationKeys[] = 'SitesManager_SiteWithoutDataGoogleTagManagerDescription';
$translationKeys[] = 'SitesManager_SiteWithoutDataHidePageForHour';
Expand Down
15 changes: 0 additions & 15 deletions plugins/SitesManager/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,7 @@
"ShowTrackingTag": "View Tracking code",
"Sites": "Websites",
"SiteSearchUse": "You can use Matomo to track and report what visitors are searching in your website's internal search engine.",
"SiteWithoutDataCloudflareDescription": "You can use the Matomo App in Cloudflare to track data, follow the instructions from %1$sthis guide%2$s.",
"SiteWithoutDataCloudflareIntro": "If you use Cloudflare, you can start tracking data in Matomo seamlessly using the Matomo App available in Cloudflare.",
"SiteWithoutDataCloudflareFollowStepsIntro": "Follow these steps to set it up:",
"SiteWithoutDataCloudflareFollowStep01": "%1$sLogin%2$s to your Cloudflare dashboard.",
"SiteWithoutDataCloudflareFollowStep02": "Click \"Websites\" on the left menu, and select the site on which you want to enable the Matomo tracking code.",
"SiteWithoutDataCloudflareFollowStep03": "Click \"Apps\" on the left menu.",
"SiteWithoutDataCloudflareFollowStep04": "Search for \"Matomo Analytics\" under the \"Search Apps\" input box.",
"SiteWithoutDataCloudflareFollowStep05": "Click on the \"Matomo Analytics\" app.",
"SiteWithoutDataCloudflareFollowStep06": "Click on \"Preview on your site\" button.",
"SiteWithoutDataCloudflareFollowStep07": "Configure the app by specifying the Matomo URL and Site ID for which you want to enable tracking.",
"SiteWithoutDataCloudflareFollowStep08": "Click \"Install on all pages\".",
"SiteWithoutDataCloudflareFollowStep09": "Review permissions and allow Cloudflare to share your email address with Matomo by clicking \"Continue\".",
"SiteWithoutDataCloudflareFollowStep10": "Wait for the app to install, and you will see the Matomo Analytics app installed under \"Your Installed Apps\" section.",
"SiteWithoutDataCloudflareFollowStepCompleted": "%1$sCongratulations!%2$s You have successfully installed the Matomo Analytics app on Cloudflare. To verify that hits are being tracked, visit your website and check that this data is visible in your Matomo instance.",
"SiteWithoutDataOtherWays": "Other ways",
"SiteWithoutDataOtherIntegrations": "Other integrations",
"SiteWithoutDataGoogleTagManager": "Google Tag Manager",
Expand Down Expand Up @@ -139,8 +126,6 @@
"GADetectedEmail": "%1$s was detected on your website. Did you know you can easily migrate your historical analytics data and settings from %2$s to Matomo? Learn more here: %3$s",
"GTMDetected": "Google Tag Manager was detected on your website. Did you know you can migrate your existing tags, triggers and variables from Google Tag Manager to Matomo Tag Manager? %1$sLearn more in this guide%2$s.",
"GTMDetectedEmail": "Google Tag Manager was detected on your website. Did you know you can migrate your existing tags, triggers and variables from Google Tag Manager to Matomo Tag Manager? Learn more here: %1$s",
"CloudflareDetected": "Cloudflare was detected on your website. Did you know you can use the Matomo app in your Cloudflare setup to track the website data? %1$sLearn more in this guide%2$s.",
"CloudflareDetectedEmail": "Cloudflare was detected on your website. Did you know you can use the Matomo app in your Cloudflare setup to track the website data? Learn more here: %1$s",
"SiteWithoutDataGoogleTagManagerIntro": "If you use Google Tag Manager, you can start tracking data in Matomo seamlessly using the \"Custom HTML Tag\" available in Google Tag Manager. %1$sLearn more%2$s.",
"SiteWithoutDataGoogleTagManagerFollowStepsIntro": "Follow these steps to set it up:",
"SiteWithoutDataGTMFollowStep1": "%1$sLogin%2$s into your Google Tag Manager account.",
Expand Down
25 changes: 0 additions & 25 deletions plugins/SitesManager/templates/_cloudflareTabInstructions.twig

This file was deleted.

3 changes: 0 additions & 3 deletions plugins/SitesManager/templates/_displayJavascriptCode.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
<h3>WordPress</h3>
<p>{{ 'SitesManager_SiteWithoutDataWordpressDescription'|translate(externallink('https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-wordpress/'),'</a>')|raw }}</p>

<h3>Cloudflare</h3>
<p>{{ 'SitesManager_SiteWithoutDataCloudflareDescription'|translate(externallink('https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-cloudflare-setup/'),'</a>')|raw }}</p>

<h3>Vue.js</h3>
<p>{{ 'SitesManager_SiteWithoutDataVueDescription'|translate(externallink('https://github.com/AmazingDreams/vue-matomo') ~ 'vue-matomo</a>', externallink('https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-websites-that-use-vue-js/'),'</a>')|raw }}</p>

Expand Down
4 changes: 0 additions & 4 deletions plugins/SitesManager/templates/_trackingCodeEmail.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
{% if 'GoogleTagManager' in trackers %}
{{ 'SitesManager_GTMDetectedEmail'|translate(externalrawlink('https://matomo.org/faq/tag-manager/migrating-from-google-tag-manager/'))|raw }}

{% endif %}
{% if 'Cloudflare' in cms %}
{{ 'SitesManager_CloudflareDetectedEmail'|translate(externalrawlink('https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-cloudflare-setup/'))|raw }}

{% endif %}

{% if 'VueJs' in jsFrameworks %}
Expand Down
3 changes: 0 additions & 3 deletions tests/UI/expected-screenshots/EmptySite_cloudflare.png

This file was deleted.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/UI/expected-screenshots/EmptySite_integrations.png
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_other.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 6 additions & 20 deletions tests/UI/specs/EmptySite_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ describe("EmptySite", function () {
testEnvironment.connectedConsentManagers = [];
testEnvironment.save();

await page.goto(urlToTest + "#?" + generalParams + "&activeTab=cloudflare");
await page.goto(urlToTest + "#?" + generalParams + "&activeTab=integrations");
await page.waitForSelector('#start-tracking-details'); // wait till details ar shown
await makeTrackingCodeStatic();

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

// take one full screenshot when a detected method is shown
it('should suggest cloudflare method when detected, other detections should be shown first', async function () {
testEnvironment.detectedContentDetections = ['Cloudflare', 'VueJs'];
it('should suggest wordpress method when detected, other detections should be shown first', async function () {
testEnvironment.detectedContentDetections = ['WordPress', 'VueJs'];
testEnvironment.connectedConsentManagers = [];
testEnvironment.save();

Expand All @@ -150,12 +150,12 @@ describe("EmptySite", function () {
await page.waitForSelector('#start-tracking-method-list'); // wait till list is shown

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

// only take shots from recommended method for other detections
it('should prefer gtm method over others when detected', async function () {
testEnvironment.detectedContentDetections = ['GoogleTagManager', 'WordPress', 'Cloudflare'];
testEnvironment.detectedContentDetections = ['GoogleTagManager', 'WordPress', 'VueJs'];
testEnvironment.connectedConsentManagers = [];
testEnvironment.save();

Expand All @@ -167,20 +167,6 @@ describe("EmptySite", function () {
expect(await pageElement.screenshot()).to.matchImage('detected_gtm');
});

it('should prefer wordpress method over cloudflare when detected', async function () {
testEnvironment.detectedContentDetections = ['WordPress', 'Cloudflare'];
testEnvironment.connectedConsentManagers = [];
testEnvironment.save();

await page.goto('about:blank');
await page.goto(urlToTest);
await page.waitForSelector('#start-tracking-method-list'); // wait till list is shown

const pageElement = await page.$('#start-tracking-detection');
expect(await pageElement.screenshot()).to.matchImage('detected_wordpress');
});


it('should should show a notification on the tracking code screen when a consent manager is detected', async function () {
testEnvironment.detectedContentDetections = ['Osano'];
testEnvironment.connectedConsentManagers = ['Osano'];
Expand Down

0 comments on commit 98cc5fe

Please sign in to comment.