1
0
Fork 0
mirror of https://github.com/Findus23/plugin-IgnoreDNTEnabledByDefault.git synced 2024-08-27 19:52:17 +02:00
plugin-IgnoreDNTEnabledByDe.../IgnoreDNTEnabledByDefault.php

62 lines
1.5 KiB
PHP
Raw Normal View History

2019-02-10 21:03:39 +01:00
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\IgnoreDNTEnabledByDefault;
use Piwik\Tracker\Request;
class IgnoreDNTEnabledByDefault extends \Piwik\Plugin
{
public function registerEvents() {
return array(
'PrivacyManager.shouldIgnoreDnt' => 'handleDNTHeader'
);
}
public function isTrackerPlugin() {
return true;
}
public function handleDNTHeader(&$shouldIgnore) {
$shouldIgnore = $this->isUserAgentWithDoNotTrackAlwaysEnabled();
}
/**
* @return bool
*/
public function isUserAgentWithDoNotTrackAlwaysEnabled() {
$request = new Request($_REQUEST);
$userAgent = $request->getUserAgent();
$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/matomo-org/matomo/issues/8682
'Epiphany',
);
}
}