blob: 93c0e79fcaaaabcf8ccc9d2a78fab5ff2937cb9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
<?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\PrivacyManager;
use Piwik\Common;
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)
*
*/
class DoNotTrackHeaderChecker
{
/**
* Checks for DoNotTrack headers and if found, sets `$exclude` to `true`.
*/
public function checkHeaderInTracker(&$exclude)
{
if (!$this->isActive()
|| $exclude
) {
return;
}
if ((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')
) {
$request = new Request($_REQUEST);
$ua = $request->getUserAgent();
if (strpos($ua, 'MSIE 10') !== false
|| strpos($ua, 'Trident/7') !== false) {
Common::printDebug("INTERNET EXPLORER 10 and 11 enable DoNotTrack by default; so Piwik ignores DNT for all IE10 + IE11 browsers...");
return;
}
$exclude = true;
Common::printDebug("DoNotTrack found.");
$trackingCookie = IgnoreCookie::getTrackingCookie();
$trackingCookie->delete();
// this is an optional supplement to the site's tracking status resource at:
// /.well-known/dnt
// per Tracking Preference Expression (draft)
header('Tk: 1');
}
}
/**
* Deactivates DoNotTrack header checking. This function will not be called by the Tracker.
*/
public static function deactivate()
{
$config = new Config();
$config->doNotTrackEnabled = false;
}
/**
* Activates DoNotTrack header checking. This function will not be called by the Tracker.
*/
public static function activate()
{
$config = new Config();
$config->doNotTrackEnabled = true;
}
/**
* Returns true if server side DoNotTrack support is enabled, false if otherwise.
*
* @return bool
*/
public static function isActive()
{
$config = new Config();
return $config->doNotTrackEnabled;
}
}
|