Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DoNotTrack.php « DoNotTrack « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e609f5e9af360d9a1fb91227b8f4049590ab8ba2 (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
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 * @category Piwik_Plugins
 * @package Piwik_DoNotTrack
 */

/**
 * Ignore visits where user agent's request contains either:
 * - X-Do-Not-Track header (used by AdBlockPlus and NoScript)
 * - DNT header (used by Mozilla)
 *
 * @package Piwik_DoNotTrack
 */
class Piwik_DoNotTrack extends Piwik_Plugin
{
	/**
	 * Return information about this plugin.
	 *
	 * @see Piwik_Plugin
	 *
	 * @return array
	 */
	public function getInformation()
	{
		return array(
			'description' => Piwik_Translate('DoNotTrack_PluginDescription'),
			'author' => 'Piwik',
			'author_homepage' => 'http://piwik.org/',
			'version' => Piwik_Version::VERSION,
			'translationAvailable' => false,
			'TrackerPlugin' => true,
		);
	}

	public function getListHooksRegistered()
	{
		return array(
			'Tracker.Visit.isExcluded' => 'checkHeader',
		);
	}

	/**
	 * @param Piwik_Event_Notification $notification  notification object
	 */
	function checkHeader($notification)
	{
		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'))
		{
			$ua = Piwik_Tracker_Visit::getUserAgent($_REQUEST);
			if(strpos($ua, 'MSIE 10') !== false)
			{
				printDebug("INTERNET EXPLORER 10 Enables DNT by default, so Piwik ignores DNT for all IE10 browsers...");
				return;
			}

			$exclude =& $notification->getNotificationObject();
			$exclude = true;
			printDebug("DoNotTrack found.");

			$trackingCookie = Piwik_Tracker_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');
		}
	}
}