diff --git a/plugins/PrivacyManager/DoNotTrackHeaderChecker.php b/plugins/PrivacyManager/DoNotTrackHeaderChecker.php index c8c6f9df9b7..231eafcffc0 100644 --- a/plugins/PrivacyManager/DoNotTrackHeaderChecker.php +++ b/plugins/PrivacyManager/DoNotTrackHeaderChecker.php @@ -9,8 +9,8 @@ namespace Piwik\Plugins\PrivacyManager; use Piwik\Common; +use Piwik\Piwik; use Piwik\Tracker\IgnoreCookie; -use Piwik\Tracker\Request; /** * Excludes visits where user agent's request contains either: @@ -18,7 +18,6 @@ * - X-Do-Not-Track header (used by AdBlockPlus and NoScript) * - DNT header (used by Mozilla) * - * Note: visits from Internet Explorer and other browsers that have DoNoTrack enabled by default will be tracked anyway. */ class DoNotTrackHeaderChecker { @@ -70,11 +69,11 @@ public function isDoNotTrackFound() return false; } - $request = new Request($_REQUEST); - $userAgent = $request->getUserAgent(); + $shouldIgnore = false; - if ($this->isUserAgentWithDoNotTrackAlwaysEnabled($userAgent)) { - Common::printDebug("INTERNET EXPLORER enable DoNotTrack by default; so Piwik ignores DNT IE browsers..."); + Piwik::postEvent('PrivacyManager.shouldIgnoreDnt', array(&$shouldIgnore)); + if($shouldIgnore) { + Common::printDebug("DoNotTrack header ignored by Matomo because of a plugin"); return false; } @@ -116,40 +115,4 @@ protected function isHeaderDntFound() return (isset($_SERVER['HTTP_X_DO_NOT_TRACK']) && $_SERVER['HTTP_X_DO_NOT_TRACK'] === '1') || (isset($_SERVER['HTTP_DNT']) && substr($_SERVER['HTTP_DNT'], 0, 1) === '1'); } - - /** - * - * @param $userAgent - * @return bool - */ - protected function isUserAgentWithDoNotTrackAlwaysEnabled($userAgent) - { - $browsersWithDnt = $this->getBrowsersWithDNTAlwaysEnabled(); - foreach($browsersWithDnt as $userAgentBrowserFragment) { - if (stripos($userAgent, $userAgentBrowserFragment) !== false) { - return true; - } - } - return false; - } - - /** - * Some browsers have DNT enabled by default. For those we will ignore DNT and always track those users. - * - * @return array - */ - protected function getBrowsersWithDNTAlwaysEnabled() - { - return array( - // IE - 'MSIE', - 'Trident', - - // Maxthon - 'Maxthon', - - // Epiphany - https://github.com/piwik/piwik/issues/8682 - 'Epiphany', - ); - } } diff --git a/plugins/PrivacyManager/tests/Unit/DoNotTrackHeaderCheckerTest.php b/plugins/PrivacyManager/tests/Unit/DoNotTrackHeaderCheckerTest.php index a0bf82e9587..e17dcc88154 100644 --- a/plugins/PrivacyManager/tests/Unit/DoNotTrackHeaderCheckerTest.php +++ b/plugins/PrivacyManager/tests/Unit/DoNotTrackHeaderCheckerTest.php @@ -80,37 +80,6 @@ public function test_isDoNotTrackFound_whenDntActivated_BrowserDoesNotHaveDntHea $this->assertFalse( $dntChecker->isDoNotTrackFound() ); } - public function getUserAgents_whereDNTIsAlwaysEnabled() - { - return array( - // IE - array('Mozilla/4.0 (compatible; MSIE 4.01; Mac_PowerPC)'), - array('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; OfficeLiveConnector.1.4; OfficeLivePatch.1.3)'), - array('Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko'), - - // Maxthon - array('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; MAXTHON 2.0)'), - array('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Maxthon/4.2.0.4000)'), - array('Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Maxthon/4.4.3.1000 Chrome/30.0.1599.101 Safari/537.36'), - - // With capital letters - array('Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) MAXTHON/4.4.3.1000 Chrome/30.0.1599.101 Safari/537.36'), - ); - } - - /** - * @dataProvider getUserAgents_whereDNTIsAlwaysEnabled - */ - public function test_isDoNotTrackFound_whenDntActivated_InternetExplorerDoNotTrackIsIgnored($userAgent) - { - $dntChecker = $this->makeDntHeaderCheckerEnabled(); - - $this->activateDoNotTrackInBrowser(); - - $_SERVER['HTTP_USER_AGENT'] = $userAgent; - $this->assertFalse($dntChecker->isDoNotTrackFound()); - } - /** * @return Config */ @@ -162,4 +131,4 @@ protected function activateDoNotTrackInBrowser() $_SERVER['HTTP_DNT'] = '1'; } } - \ No newline at end of file +