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

Full refactor of site content detection and no data page logic #21029

Merged
merged 35 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f3d040a
refactor site content detection and no data page
sgiehl Jul 3, 2023
3a087f7
tagmanager submodule
sgiehl Jul 4, 2023
334c028
start to refactor consent manager handling
sgiehl Jul 5, 2023
490e64d
fix method name
sgiehl Jul 14, 2023
6fe3be8
small code refactoring
sgiehl Jul 14, 2023
e78042e
handle active tab through classes
sgiehl Jul 14, 2023
bc5d831
improve code and fix some tests
sgiehl Jul 15, 2023
83ee226
update fixtures
sgiehl Jul 15, 2023
e1a2644
migrate and add new tests for SiteContentDetection classes
sgiehl Jul 16, 2023
7b3e20b
remove state from detection classes again
sgiehl Jul 17, 2023
039628c
fix some stuff
sgiehl Jul 17, 2023
821e9d9
pass detector to render method
sgiehl Jul 18, 2023
59b26fe
remove not needed constant
sgiehl Jul 18, 2023
0ac14ff
fix caching
sgiehl Jul 18, 2023
0403d60
code cleanup
sgiehl Jul 18, 2023
f73de93
hide listing on others tab if corresponding tab is displayed
sgiehl Jul 31, 2023
3f63003
hide spa/pwa on others pages
sgiehl Aug 3, 2023
430c492
remove incorrectly copied code
sgiehl Aug 3, 2023
6ef6174
Move detectConsentManager from Tour to SitesManager API
sgiehl Aug 31, 2023
7a71610
fix new checks for GA
sgiehl Sep 1, 2023
e98f24b
updates expected screenshot
sgiehl Sep 1, 2023
5b87205
improve detectConsentManager api method
sgiehl Sep 4, 2023
d5d53ea
use correct template var
sgiehl Sep 4, 2023
080c622
removes no longer used translation key
sgiehl Sep 7, 2023
b85a2de
Moved SPA/PWA class to TagManager
sgiehl Sep 7, 2023
018320d
updates submodule
sgiehl Sep 7, 2023
d5ccf19
fix typo
sgiehl Sep 7, 2023
f1c7052
fix translation string
sgiehl Sep 7, 2023
456a34b
cs
sgiehl Sep 7, 2023
3e2199f
Move tracking code tab to new Matomo detection class and remove dupli…
sgiehl Sep 8, 2023
83cfab6
apply some review feedback
sgiehl Sep 11, 2023
72bd6fc
submodule update
sgiehl Sep 11, 2023
53e35e8
clean up installation controller
sgiehl Sep 11, 2023
b953439
update version to 5.0.0-rc3
sgiehl Sep 15, 2023
2fe4218
submodule update
sgiehl Sep 15, 2023
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
423 changes: 186 additions & 237 deletions core/SiteContentDetector.php
michalkleiner marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/CoreAdminHome/Tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function checkSiteHasTrackedVisits($idSite)
{
$this->rememberTrackingCodeReminderRan($idSite);

if (!SitesManager::shouldPerormEmptySiteCheck($idSite)) {
if (!SitesManager::shouldPerformEmptySiteCheck($idSite)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
}

#tracking-code li .trackingCodeAdvancedOptions .advance-option {
.site-without-data #matomo li .trackingCodeAdvancedOptions .advance-option {
margin-top: 1rem;
margin-left: 1.25rem
}
4 changes: 2 additions & 2 deletions plugins/CoreAdminHome/templates/trackingCodeGenerator.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<a href="#/trackingApi">{{ 'CoreAdminHome_HttpTrackingApi'|translate }}</a>
<a href="#/singlePageApplication">{{ 'SitesManager_SiteWithoutDataSinglePageApplication'|translate }}</a>
<a href="#/google-tag-manager">{{ 'SitesManager_SiteWithoutDataGoogleTagManager'|translate }}</a>
<a href="#/wordpress">Wordpress</a>
<a href="#/wordpress">WordPress</a>
<a href="#/cloudflare">Cloudflare</a>
<a href="#/vue">Vue.js</a>
<a href="#/react">React.js</a>
Expand Down Expand Up @@ -71,7 +71,7 @@
<p>{{ 'CoreAdminHome_GoogleTagManagerDescription'|translate('<a href="https://matomo.org/faq/new-to-piwik/how-do-i-use-matomo-analytics-within-gtm-google-tag-manager/" rel="noreferrer noopener" target="_blank">','</a>')|raw }}</p>
</div>

<div vue-entry="CoreHome.ContentBlock" content-title="Wordpress" anchor="wordpress">
<div vue-entry="CoreHome.ContentBlock" content-title="WordPress" anchor="wordpress">
<p>{{ 'CoreAdminHome_WordpressDescription'|translate('<a href="https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-wordpress/" target="_blank">','</a>')|raw }}</p>
</div>

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 29 additions & 29 deletions plugins/CoreAdminHome/vue/dist/CoreAdminHome.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/CoreAdminHome/vue/dist/CoreAdminHome.umd.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default defineComponent({
{
module: 'API',
format: 'json',
method: 'Tour.detectConsentManager',
method: 'SitesManager.detectConsentManager',
idSite,
filter_limit: '-1',
},
Expand Down
40 changes: 8 additions & 32 deletions plugins/Installation/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Piwik\Plugins\Diagnostics\DiagnosticService;
use Piwik\Plugins\LanguagesManager\LanguagesManager;
use Piwik\Plugins\SitesManager\API as APISitesManager;
use Piwik\Plugins\SitesManager\SitesManager;
use Piwik\Plugins\UsersManager\API as APIUsersManager;
use Piwik\Plugins\UsersManager\NewsletterSignup;
use Piwik\Plugins\UsersManager\UserUpdater;
Expand Down Expand Up @@ -393,29 +394,13 @@ public function trackingCode()

$javascriptGenerator = new TrackerCodeGenerator();
$jsTag = $javascriptGenerator->generate($idSite, Url::getCurrentUrlWithoutFileName());
$rawJsTag = TrackerCodeGenerator::stripTags($jsTag);

$showMatomoLinks = true;
Piwik::postEvent('SitesManager.showMatomoLinksInTrackingCodeEmail', array(&$showMatomoLinks));

$trackingUrl = trim(SettingsPiwik::getPiwikUrl(), '/') . '/' . $javascriptGenerator->getPhpTrackerEndpoint();

$this->siteContentDetector->detectContent([SiteContentDetector::ALL_CONTENT]);

$emailBody = $this->renderTemplateAs('@SitesManager/_trackingCodeEmail', array(
'jsTag' => $rawJsTag,
'showMatomoLinks' => $showMatomoLinks,
'trackingUrl' => $trackingUrl,
'idSite' => $idSite,
'gtmUsed' => $this->siteContentDetector->gtm,
'ga3Used' => $this->siteContentDetector->ga3,
'ga4Used' => $this->siteContentDetector->ga4,
'cloudflare' => $this->siteContentDetector->cloudflare,
'jsFramework' => $this->siteContentDetector->jsFramework,
'consentManagerName' => $this->siteContentDetector->consentManagerName,
'consentManagerUrl' => $this->siteContentDetector->consentManagerUrl,
'consentManagerIsConnected' => $this->siteContentDetector->isConnected
), $viewType = 'basic');

// Needs to be generated as super user, as API requests would otherwise fail
$emailBody = Access::doAsSuperUser(
function () use ($idSite) {
return SitesManager::renderTrackingCodeEmail($idSite);
}
);

// Load the Tracking code and help text from the SitesManager
$viewTrackingHelp = new \Piwik\View('@SitesManager/_displayJavascriptCode');
Expand All @@ -426,15 +411,6 @@ public function trackingCode()
$viewTrackingHelp->piwikUrl = Url::getCurrentUrlWithoutFileName();
$viewTrackingHelp->isInstall = true;

$viewTrackingHelp->gtmUsed = $this->siteContentDetector->gtm;
$viewTrackingHelp->ga3Used = $this->siteContentDetector->ga3;
$viewTrackingHelp->ga4Used = $this->siteContentDetector->ga4;
$viewTrackingHelp->cloudflare = $this->siteContentDetector->cloudflare;
$viewTrackingHelp->jsFramework = $this->siteContentDetector->jsFramework;
$viewTrackingHelp->consentManagerName = $this->siteContentDetector->consentManagerName;
$viewTrackingHelp->consentManagerUrl = $this->siteContentDetector->consentManagerUrl;
$viewTrackingHelp->consentManagerIsConnected = $this->siteContentDetector->isConnected;

$view->trackingHelp = $viewTrackingHelp->render();
$view->displaySiteName = $siteName;

Expand Down
23 changes: 16 additions & 7 deletions plugins/PrivacyManager/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use Piwik\Plugins\CustomJsTracker\File;
use Piwik\Plugins\LanguagesManager\LanguagesManager;
use Piwik\Plugins\LanguagesManager\API as APILanguagesManager;
use Piwik\Plugins\SitesManager\SiteContentDetection\ConsentManagerDetectionAbstract;
use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract;
use Piwik\SiteContentDetector;
use Piwik\Scheduler\Scheduler;
use Piwik\Tracker\TrackerCodeGenerator;
Expand Down Expand Up @@ -175,16 +177,23 @@ public function consent()

$view = new View('@PrivacyManager/askingForConsent');

$this->siteContentDetector->detectContent([SiteContentDetector::CONSENT_MANAGER]);
$this->siteContentDetector->detectContent([SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER]);
$consentManager = $this->siteContentDetector->getDetectsByType(SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER);
$view->consentManagerName = null;
if ($this->siteContentDetector->consentManagerId) {
$view->consentManagerName = $this->siteContentDetector->consentManagerName;
$view->consentManagerUrl = $this->siteContentDetector->consentManagerUrl;
$view->consentManagerIsConnected = $this->siteContentDetector->isConnected;
if (!empty($consentManager)) {
$consentManager = $this->siteContentDetector->getSiteContentDetectionById(reset($consentManager));
if ($consentManager instanceof ConsentManagerDetectionAbstract) {
$view->consentManagerName = $consentManager::getName();
$view->consentManagerUrl = $consentManager::getInstructionUrl();
$view->consentManagerIsConnected = in_array(
$consentManager::getId(),
$this->siteContentDetector->connectedConsentManagers
);
}
}

$consentManagers = SiteContentDetector::getConsentManagerDefinitions();
$knownConsentManagers = array_combine(array_column($consentManagers, 'name'), array_column($consentManagers, 'url'));
$consentManagers = SiteContentDetector::getKnownConsentManagers();
$knownConsentManagers = array_combine(array_column($consentManagers, 'name'), array_column($consentManagers, 'instructionUrl'));

$view->knownConsentManagers = $knownConsentManagers;
$this->setBasicVariablesView($view);
Expand Down
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.
34 changes: 33 additions & 1 deletion plugins/SitesManager/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use Piwik\Piwik;
use Piwik\Plugin\SettingsProvider;
use Piwik\Plugins\CorePluginsAdmin\SettingsMetadata;
use Piwik\Plugins\SitesManager\SiteContentDetection\ConsentManagerDetectionAbstract;
use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract;
use Piwik\Plugins\WebsiteMeasurable\Settings\Urls;
use Piwik\ProxyHttp;
use Piwik\Scheduler\Scheduler;
Expand All @@ -32,6 +34,7 @@
use Piwik\SettingsPiwik;
use Piwik\SettingsServer;
use Piwik\Site;
use Piwik\SiteContentDetector;
use Piwik\Tracker\Cache;
use Piwik\Tracker\TrackerCodeGenerator;
use Piwik\Translation\Translator;
Expand Down Expand Up @@ -84,11 +87,15 @@ class API extends \Piwik\Plugin\API

private $timezoneNameCache = [];

public function __construct(SettingsProvider $provider, SettingsMetadata $settingsMetadata, Translator $translator)
/** @var SiteContentDetector */
private $siteContentDetector;

public function __construct(SettingsProvider $provider, SettingsMetadata $settingsMetadata, Translator $translator, SiteContentDetector $siteContentDetector)
{
$this->settingsProvider = $provider;
$this->settingsMetadata = $settingsMetadata;
$this->translator = $translator;
$this->siteContentDetector = $siteContentDetector;
}

/**
Expand Down Expand Up @@ -1764,4 +1771,29 @@ public function getNumWebsitesToDisplayPerPage()

return SettingsPiwik::getWebsitesCountToDisplay();
}


/**
* Detect consent manager details for a site
*
* @internal
* @unsanitized
*/
public function detectConsentManager(int $idSite, int $timeOut = 60): ?array
{
Piwik::checkUserHasViewAccess($idSite);

$this->siteContentDetector->detectContent([SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER], $idSite, null, $timeOut);
$consentManagers = $this->siteContentDetector->getDetectsByType(SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER);
if (!empty($consentManagers)) {
/** @var ConsentManagerDetectionAbstract $consentManager */
$consentManager = $this->siteContentDetector->getSiteContentDetectionById(reset($consentManagers));
return ['name' => $consentManager::getName(),
'url' => $consentManager::getInstructionUrl(),
'isConnected' => in_array($consentManager::getId(), $this->siteContentDetector->connectedConsentManagers)
];
}

return null;
}
}
Loading