PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.3.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.3.0
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Tracker / Settings.php
matomo / app / core / Tracker Last commit date
Db 5 years ago Handler 5 years ago TableLogAction 5 years ago Visit 5 years ago Action.php 5 years ago ActionPageview.php 5 years ago Cache.php 5 years ago Db.php 5 years ago Failures.php 6 years ago FingerprintSalt.php 6 years ago GoalManager.php 5 years ago Handler.php 5 years ago IgnoreCookie.php 5 years ago LogTable.php 5 years ago Model.php 5 years ago PageUrl.php 5 years ago Request.php 5 years ago RequestProcessor.php 5 years ago RequestSet.php 5 years ago Response.php 5 years ago ScheduledTasksRunner.php 5 years ago Settings.php 5 years ago TableLogAction.php 5 years ago TrackerCodeGenerator.php 5 years ago TrackerConfig.php 5 years ago Visit.php 5 years ago VisitExcluded.php 5 years ago VisitInterface.php 5 years ago Visitor.php 5 years ago VisitorNotFoundInDb.php 5 years ago VisitorRecognizer.php 5 years ago
Settings.php
164 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9 namespace Piwik\Tracker;
10
11 use Piwik\Config;
12 use Piwik\Container\StaticContainer;
13 use Piwik\Date;
14 use Piwik\Tracker;
15 use Piwik\DeviceDetector\DeviceDetectorFactory;
16 use Piwik\SettingsPiwik;
17
18 class Settings // TODO: merge w/ visitor recognizer or make it it's own service. the class name is required for BC.
19 {
20 const OS_BOT = 'BOT';
21
22 /**
23 * If `true`, the config ID for a visitor will be the same no matter what site is being tracked.
24 * If `false, the config ID will be different.
25 *
26 * @var bool
27 */
28 private $isSameFingerprintsAcrossWebsites;
29
30 public function __construct($isSameFingerprintsAcrossWebsites)
31 {
32 $this->isSameFingerprintsAcrossWebsites = $isSameFingerprintsAcrossWebsites;
33 }
34
35 public function getConfigId(Request $request, $ipAddress)
36 {
37 list($plugin_Flash, $plugin_Java, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF,
38 $plugin_WindowsMedia, $plugin_Silverlight, $plugin_Cookie) = $request->getPlugins();
39
40 $userAgent = $request->getUserAgent();
41
42 $deviceDetector = StaticContainer::get(DeviceDetectorFactory::class)->makeInstance($userAgent);
43 $aBrowserInfo = $deviceDetector->getClient();
44
45 if (empty($aBrowserInfo['type']) || 'browser' !== $aBrowserInfo['type']) {
46 // for now only track browsers
47 unset($aBrowserInfo);
48 }
49
50 $browserName = !empty($aBrowserInfo['short_name']) ? $aBrowserInfo['short_name'] : 'UNK';
51 $browserVersion = !empty($aBrowserInfo['version']) ? $aBrowserInfo['version'] : '';
52
53 if ($deviceDetector->isBot()) {
54 $os = self::OS_BOT;
55 } else {
56 $os = $deviceDetector->getOS();
57 $os = empty($os['short_name']) ? 'UNK' : $os['short_name'];
58 }
59
60 $client = $deviceDetector->getClient();
61 if (!empty($client['name']) && $client['name'] === 'Internet Explorer') {
62 // we assume cookies are disabled... when in tracker cookies are disabled, this ensures when upgrading to this version
63 // that no fingerprint changes in the 30min window during the upgrade...
64 // We don't include it anymore as it otherwise may cause new visits to be created when switching between
65 // cookies disabled and enabled in IE11 or older. Before Matomo 3.13.7 when cookies were disabled, then
66 // this value was set to 0. For people with cookies enabled the fingerprint is not as relevant as the visitorId
67 // is used to identify a visitor
68 $plugin_Cookie = '0';
69 }
70
71 $browserLang = substr($request->getBrowserLanguage(), 0, 20); // limit the length of this string to match db
72 $trackerConfig = Config::getInstance()->Tracker;
73
74 $fingerprintSalt = '';
75
76 // fingerprint salt won't work when across multiple sites since all sites could have different timezones
77 // also cant add fingerprint salt for a specific day when we dont create new visit after midnight
78 if (!$this->isSameFingerprintsAcrossWebsites && !empty($trackerConfig['create_new_visit_after_midnight'])) {
79 $cache = Cache::getCacheWebsiteAttributes($request->getIdSite());
80 $date = Date::factory((int) $request->getCurrentTimestamp());
81 $fingerprintSaltKey = new FingerprintSalt();
82 $dateString = $fingerprintSaltKey->getDateString($date, $cache['timezone']);
83
84 if (!empty($cache[FingerprintSalt::OPTION_PREFIX . $dateString])) {
85 $fingerprintSalt = $cache[FingerprintSalt::OPTION_PREFIX . $dateString];
86 } else {
87 // we query the DB directly for requests older than 2-3 days...
88 $fingerprintSalt = $fingerprintSaltKey->getSalt($dateString, $request->getIdSite());
89 }
90
91 $fingerprintSalt .= $dateString;
92
93 if (defined('PIWIK_TEST_MODE') && PIWIK_TEST_MODE) {
94 $fingerprintSalt = ''; // use fixed value so they don't change randomly in tests
95 }
96 }
97
98 return $this->getConfigHash(
99 $request,
100 $os,
101 $browserName,
102 $browserVersion,
103 $plugin_Flash,
104 $plugin_Java,
105 $plugin_Quicktime,
106 $plugin_RealPlayer,
107 $plugin_PDF,
108 $plugin_WindowsMedia,
109 $plugin_Silverlight,
110 $plugin_Cookie,
111 $ipAddress,
112 $browserLang,
113 $fingerprintSalt);
114 }
115
116 /**
117 * Returns a 64-bit hash that attempts to identify a user.
118 * Maintaining some privacy by default, eg. prevents the merging of several Piwik serve together for matching across instances..
119 *
120 * @param $os
121 * @param $browserName
122 * @param $browserVersion
123 * @param $plugin_Flash
124 * @param $plugin_Java
125 * @param $plugin_Quicktime
126 * @param $plugin_RealPlayer
127 * @param $plugin_PDF
128 * @param $plugin_WindowsMedia
129 * @param $plugin_Silverlight
130 * @param $plugin_Cookie
131 * @param $ip
132 * @param $browserLang
133 * @param $fingerprintHash
134 * @return string
135 */
136 protected function getConfigHash(Request $request, $os, $browserName, $browserVersion, $plugin_Flash, $plugin_Java,
137 $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF,
138 $plugin_WindowsMedia, $plugin_Silverlight, $plugin_Cookie, $ip,
139 $browserLang, $fingerprintHash)
140 {
141 // prevent the config hash from being the same, across different Piwik instances
142 // (limits ability of different Piwik instances to cross-match users)
143 $salt = SettingsPiwik::getSalt();
144
145 $configString =
146 $os
147 . $browserName . $browserVersion
148 . $plugin_Flash . $plugin_Java . '0' . $plugin_Quicktime . $plugin_RealPlayer . $plugin_PDF
149 . $plugin_WindowsMedia . '0' . $plugin_Silverlight . $plugin_Cookie
150 . $ip
151 . $browserLang
152 . $salt
153 . $fingerprintHash;
154
155 if (!$this->isSameFingerprintsAcrossWebsites) {
156 $configString .= $request->getIdSite();
157 }
158
159 $hash = md5($configString, $raw_output = true);
160
161 return substr($hash, 0, Tracker::LENGTH_BINARY_ID);
162 }
163 }
164