diff options
-rw-r--r-- | plugins/Tour/API.php | 9 | ||||
-rw-r--r-- | plugins/Tour/Engagement/Challenge.php | 18 | ||||
-rw-r--r-- | plugins/Tour/Engagement/ChallengeSetupConsentManager.php | 189 | ||||
-rw-r--r-- | plugins/Tour/Engagement/Challenges.php | 4 | ||||
-rw-r--r-- | plugins/Tour/lang/en.json | 4 | ||||
-rw-r--r-- | plugins/Tour/tests/System/ConsentManagerDetectionTest.php | 52 |
6 files changed, 4 insertions, 272 deletions
diff --git a/plugins/Tour/API.php b/plugins/Tour/API.php index abf7f7026c..72c61e1a6e 100644 --- a/plugins/Tour/API.php +++ b/plugins/Tour/API.php @@ -48,19 +48,14 @@ class API extends \Piwik\Plugin\API $challenges = array(); foreach ($this->challenges->getChallenges() as $challenge) { - - if ($challenge->isDisabled()) { - continue; - } - - $challenges[] = [ + $challenges[] = array( 'id' => $challenge->getId(), 'name' => $challenge->getName(), 'description' => $challenge->getDescription(), 'isCompleted' => $challenge->isCompleted(), 'isSkipped' => $challenge->isSkipped(), 'url' => $challenge->getUrl() - ]; + ); } return $challenges; diff --git a/plugins/Tour/Engagement/Challenge.php b/plugins/Tour/Engagement/Challenge.php index 22836f6591..164561c8ce 100644 --- a/plugins/Tour/Engagement/Challenge.php +++ b/plugins/Tour/Engagement/Challenge.php @@ -26,11 +26,6 @@ abstract class Challenge private static $settings = null; - public function __construct() - { - - } - /** * The human readable name that will be shown in the onboarding widget. Should be max 3 or 4 words and represent an * action, like "Add a report" @@ -60,19 +55,6 @@ abstract class Challenge } /** - * By default challenges are enabled, if is not appropriate to display a challenge at this time because some condition - * has not been met then the challenge can be set as disabled by overriding this method. The constructor code will - * still be run every time the challenges are loaded. To disable a challenge based on plugin availablilty it is better - * to add a check to the Piwik\Plugins\Tour\Engagement::getChallenges() method - * - * @return false - */ - public function isDisabled() - { - return false; - } - - /** * A detailed description that describes the value of the action the user needs to complete, or some tips on how * to complete this challenge. Will be shown when hovering a challenge name. * @return string diff --git a/plugins/Tour/Engagement/ChallengeSetupConsentManager.php b/plugins/Tour/Engagement/ChallengeSetupConsentManager.php deleted file mode 100644 index 849102278a..0000000000 --- a/plugins/Tour/Engagement/ChallengeSetupConsentManager.php +++ /dev/null @@ -1,189 +0,0 @@ -<?php -/** - * Matomo - free/libre analytics platform - * - * @link https://matomo.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Plugins\Tour\Engagement; - -use Piwik\Common; -use Piwik\Http; -use Piwik\Piwik; -use Piwik\Site; - -class ChallengeSetupConsentManager extends Challenge -{ - - private $consentManagerId = null; - private $consentManagerName = null; - private $isConnected = false; - - /** - * @param string|null $siteData String of site content, content of the current site will be retrieved if left blank - */ - public function __construct(?string $siteData = null) - { - - parent::__construct(); - - if ($siteData === null) { - // Grab the current site main page as a string - if (!isset($_REQUEST['idSite'])) { - return; - } - $idSite = Common::getRequestVar('idSite', null, 'int'); - if (!$idSite) { - return; - } - - $url = Site::getMainUrlFor($idSite); - if (!$url) { - return; - } - - try { - $siteData = Http::sendHttpRequestBy('curl', $url, 60, null, null, - null, 0, false, true); - } catch (\Exception $e) { - } - - } - - if ($siteData === null) { - return; - } - - // Loop the consent manager definitions and attempt to detect based on string matching - $defs = $this->getConsentManagerDefinitions(); - foreach ($defs as $consentManagerId => $consentManagerDef) { - foreach ($consentManagerDef['detectStrings'] as $dStr) { - if (strpos($siteData, $dStr) !== false) { - $this->consentManagerId = $consentManagerId; - break 2; - } - } - } - - // If a consent manager was detected then perform an additional check to see if it has been connected to Matomo - if ($this->consentManagerId !== null) { - - if ($defs && array_key_exists($this->consentManagerId, $defs)) { - - $this->consentManagerName = $defs[$this->consentManagerId]['name']; - - foreach ($defs[$this->consentManagerId]['connectedStrings'] as $cStr) { - if (strpos($siteData, $cStr) !== false) { - $this->isConnected = true; - break; - } - } - } - } - - } - - /** - * Return an array of consent manager definitions which can be used to detect their prescence and show guide links - * - * @return array[] - */ - private function getConsentManagerDefinitions() : array - { - return [ - - 'osano' => [ - 'name' => 'Osano', - 'detectStrings' => ['osano.com'], - 'connectedStrings' => ["Osano.cm.addEventListener('osano-cm-consent-changed', (change) => { console.log('cm-change'); consentSet(change); });"], - 'url' => 'https://matomo.org/faq/how-to/#using-osano-consent-manager-with-matomo', - ], - - 'cookiebot' => [ - 'name' => 'Cookiebot', - 'detectStrings' => ['cookiebot.com'], - 'connectedStrings' => ["typeof _paq === 'undefined' || typeof Cookiebot === 'undefined'"], - 'url' => 'https://matomo.org/faq/how-to/#using-cookiebot-consent-manager-with-matomo', - ], - - 'cookieyes' => [ - 'name' => 'CookieYes', - 'detectStrings' => ['cookieyes.com'], - 'connectedStrings' => ['document.addEventListener("cookieyes_consent_update", function (eventData)'], - 'url' => 'https://matomo.org/faq/how-to/#using-cookieyes-consent-manager-with-matomo', - ], - - // Note: tarte au citron pro is configured server side so we cannot tell if it has been connected by - // crawling the website, however setup of Matomo with the pro version is automatic, so displaying the guide - // link for pro isn't necessary. Only the open source version is detected by this definition. - 'tarteaucitron' => [ - 'name' => 'Tarte au Citron', - 'detectStrings' => ['tarteaucitron.js'], - 'connectedStrings' => ['tarteaucitron.user.matomoHost'], - 'url' => 'https://matomo.org/faq/how-to/#using-tarte-au-citron-consent-manager-with-matomo', - ], - - 'klaro' => [ - 'name' => 'Klaro', - 'detectStrings' => ['klaro.js', 'kiprotect.com'], - 'connectedStrings' => ['KlaroWatcher()', "title: 'Matomo',"], - 'url' => 'https://matomo.org/faq/how-to/#using-klaro-consent-manager-with-matomo', - ], - - 'complianz' => [ - 'name' => 'Complianz', - 'detectStrings' => ['complianz-gdpr'], - 'connectedStrings' => ["if (!cmplz_in_array( 'statistics', consentedCategories )) { - _paq.push(['forgetCookieConsentGiven']);"], - 'url' => 'https://matomo.org/faq/how-to/#using-complianz-for-wordpress-consent-manager-with-matomo', - ], - ]; - } - - public function getName() - { - return Piwik::translate('Tour_ConnectConsentManager', [$this->consentManagerName]); - } - - public function getDescription() - { - return Piwik::translate('Tour_ConnectConsentManagerIntro', [$this->consentManagerName]); - } - - public function getId() - { - return 'setup_consent_manager'; - } - - public function getConsentManagerId() - { - return $this->consentManagerId; - } - - public function isCompleted() - { - - if (!$this->consentManagerName) { - return true; - } - - return $this->isConnected; - } - - public function isDisabled() - { - return ($this->consentManagerId === null); - } - - public function getUrl() - { - if ($this->consentManagerId === null) { - return ''; - } - - return $this->getConsentManagerDefinitions()[$this->consentManagerId]['url']; - - } - -}
\ No newline at end of file diff --git a/plugins/Tour/Engagement/Challenges.php b/plugins/Tour/Engagement/Challenges.php index ec09b96093..40b9cffece 100644 --- a/plugins/Tour/Engagement/Challenges.php +++ b/plugins/Tour/Engagement/Challenges.php @@ -38,11 +38,9 @@ class Challenges { /** @var Challenge[] $challenges */ $challenges = array( - StaticContainer::get(ChallengeTrackingCode::class), + StaticContainer::get(ChallengeTrackingCode::class), ); - $challenges[] = StaticContainer::get(ChallengeSetupConsentManager::class); - if ($this->isActivePlugin('Goals')) { $challenges[] = StaticContainer::get(ChallengeCreatedGoal::class); } diff --git a/plugins/Tour/lang/en.json b/plugins/Tour/lang/en.json index faa12422fc..a864ec16dc 100644 --- a/plugins/Tour/lang/en.json +++ b/plugins/Tour/lang/en.json @@ -50,8 +50,6 @@ "Part2Title": "Keep it up %1$s. You’re well on your way to becoming a Matomo expert.", "Part3Title": "You are on the right track %1$s. Continue, and become a Matomo expert.", "Part4Title": "Great progress %1$s. Only a few more challenges to complete.", - "OnlyVisibleToSuperUser": "Only you as a %1$ssuperuser%2$s can see this widget.", - "ConnectConsentManager": "Connect %1$s consent manager", - "ConnectConsentManagerIntro": "%1$s consent manager was detected on your website, learn how to connect %1$s and Matomo so they can work together." + "OnlyVisibleToSuperUser": "Only you as a %1$ssuperuser%2$s can see this widget." } } diff --git a/plugins/Tour/tests/System/ConsentManagerDetectionTest.php b/plugins/Tour/tests/System/ConsentManagerDetectionTest.php deleted file mode 100644 index e51d7774a5..0000000000 --- a/plugins/Tour/tests/System/ConsentManagerDetectionTest.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php -/** - * Matomo - free/libre analytics platform - * - * @link https://matomo.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Plugins\Tour\tests\System; - -use Piwik\Plugins\Tour\Engagement\ChallengeSetupConsentManager; -use Piwik\Tests\Framework\TestCase\SystemTestCase; - -/** - * @group ConsentManagerDetectionTest - * @group TourTest - * @group Plugins - */ -class ConsentManagerDetectionTest extends SystemTestCase -{ - - public function setUp(): void - { - parent::setUp(); - } - - public function test_detectConsentManager_disableWhenNotDetected() - { - $siteData = ''; - $challenge = new ChallengeSetupConsentManager($siteData); - $this->assertTrue($challenge->isDisabled()); - } - - public function test_detectConsentManager_detectedButNotConnected() - { - $siteData = '<html><head><script src="https://osano.com/uhs9879874hthg.js"></script></head><body>A site</body></html>'; - $challenge = new ChallengeSetupConsentManager($siteData); - $this->assertFalse($challenge->isDisabled()); - $this->assertFalse($challenge->isCompleted()); - $this->assertEquals('osano', $challenge->getConsentManagerId()); - } - - public function test_detectConsentManager_detectedAndConnected() - { - $siteData = "<html><head><script src='https://osano.com/uhs9879874hthg.js'></script><script>Osano.cm.addEventListener('osano-cm-consent-changed', (change) => { console.log('cm-change'); consentSet(change); });</script></head><body>A site</body></html>"; - $challenge = new ChallengeSetupConsentManager($siteData); - $this->assertFalse($challenge->isDisabled()); - $this->assertTrue($challenge->isCompleted()); - $this->assertEquals('osano', $challenge->getConsentManagerId()); - } - -} |