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

remove special handling of browsers with DNT enabled by default #13686

Merged
merged 4 commits into from Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 5 additions & 42 deletions plugins/PrivacyManager/DoNotTrackHeaderChecker.php
Expand Up @@ -9,16 +9,15 @@
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:
*
* - 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
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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',
);
}
}
Expand Up @@ -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
*/
Expand Down Expand Up @@ -162,4 +131,4 @@ protected function activateDoNotTrackInBrowser()
$_SERVER['HTTP_DNT'] = '1';
}
}