public function enrichVisitWithLocation(&$visitorInfo, \Piwik\Tracker\Request $request) { require_once PIWIK_INCLUDE_PATH . "/plugins/UserCountry/LocationProvider.php"; $ipAddress = IP::N2P(Config::getInstance()->Tracker['use_anonymized_ip_for_visit_enrichment'] == 1 ? $visitorInfo['location_ip'] : $request->getIp()); $userInfo = array('lang' => $visitorInfo['location_browser_lang'], 'ip' => $ipAddress); $id = Common::getCurrentLocationProviderId(); $provider = LocationProvider::getProviderById($id); if ($provider === false) { $id = DefaultProvider::ID; $provider = LocationProvider::getProviderById($id); Common::printDebug("GEO: no current location provider sent, falling back to default '{$id}' one."); } $location = $provider->getLocation($userInfo); // if we can't find a location, use default provider if ($location === false) { $defaultId = DefaultProvider::ID; $provider = LocationProvider::getProviderById($defaultId); $location = $provider->getLocation($userInfo); Common::printDebug("GEO: couldn't find a location with Geo Module '{$id}', using Default '{$defaultId}' provider as fallback..."); $id = $defaultId; } Common::printDebug("GEO: Found IP {$ipAddress} location (provider '" . $id . "'): " . var_export($location, true)); if (empty($location['country_code'])) { // sanity check $location['country_code'] = \Piwik\Tracker\Visit::UNKNOWN_CODE; } // add optional location components $this->updateVisitInfoWithLocation($visitorInfo, $location); }
public function onExistingVisit(&$valuesToUpdate, VisitProperties $visitProperties, Request $request) { $visitCustomVariables = $request->getMetadata('CustomVariables', 'visitCustomVariables'); if (!empty($visitCustomVariables)) { $valuesToUpdate = array_merge($valuesToUpdate, $visitCustomVariables); } }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onExistingVisit(Request $request, Visitor $visitor, $action) { $firstActionTime = $visitor->getVisitorColumn('visit_first_action_time'); $totalTime = 1 + $request->getCurrentTimestamp() - $firstActionTime; $totalTime = $this->cleanupVisitTotalTime($totalTime); return $totalTime; }
/** * Checks for DoNotTrack headers and if found, sets `$exclude` to `true`. */ public function checkHeaderInTracker(&$exclude) { if ($exclude) { Common::printDebug("Visit is already excluded, no need to check DoNotTrack support."); return; } if (!$this->isActive()) { Common::printDebug("DoNotTrack support is not enabled, skip check"); 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') !== false || strpos($ua, 'Trident') !== false) { Common::printDebug("INTERNET EXPLORER enable DoNotTrack by default; so Piwik ignores DNT IE browsers..."); return; } Common::printDebug("DoNotTrack header found!"); $exclude = true; $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'); } else { Common::printDebug("DoNotTrack header not found"); } }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onNewVisit(Request $request, Visitor $visitor, $action) { // Adding &dp=1 will disable the provider plugin, this is an "unofficial" parameter used to speed up log importer $disableProvider = $request->getParam('dp'); if (!empty($disableProvider)) { return false; } // if provider info has already been set, abort $locationValue = $visitor->getVisitorColumn('location_provider'); if (!empty($locationValue)) { return false; } $ip = $visitor->getVisitorColumn('location_ip'); $privacyConfig = new PrivacyManagerConfig(); if (!$privacyConfig->useAnonymizedIpForVisitEnrichment) { $ip = $request->getIp(); } $ip = IPUtils::binaryToStringIP($ip); // In case the IP was anonymized, we should not continue since the DNS reverse lookup will fail and this will slow down tracking if (substr($ip, -2, 2) == '.0') { Common::printDebug("IP Was anonymized so we skip the Provider DNS reverse lookup..."); return false; } $hostname = $this->getHost($ip); $hostnameExtension = ProviderPlugin::getCleanHostname($hostname); // add the provider value in the table log_visit $locationProvider = substr($hostnameExtension, 0, 100); return $locationProvider; }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onExistingVisit(Request $request, Visitor $visitor, $action) { if ($request->getParam('ping') == 1) { return false; } return $this->onNewVisit($request, $visitor, $action); }
/** * Logs the provider in the log_visit table */ public function enrichVisitWithProviderInfo(&$visitorInfo, \Piwik\Tracker\Request $request) { // if provider info has already been set, abort if (!empty($visitorInfo['location_provider'])) { return; } $privacyConfig = new PrivacyManagerConfig(); $ip = IP::N2P($privacyConfig->useAnonymizedIpForVisitEnrichment ? $visitorInfo['location_ip'] : $request->getIp()); // In case the IP was anonymized, we should not continue since the DNS reverse lookup will fail and this will slow down tracking if (substr($ip, -2, 2) == '.0') { Common::printDebug("IP Was anonymized so we skip the Provider DNS reverse lookup..."); return; } $hostname = $this->getHost($ip); $hostnameExtension = $this->getCleanHostname($hostname); // add the provider value in the table log_visit $visitorInfo['location_provider'] = $hostnameExtension; $visitorInfo['location_provider'] = substr($visitorInfo['location_provider'], 0, 100); // improve the country using the provider extension if valid $hostnameDomain = substr($hostnameExtension, 1 + strrpos($hostnameExtension, '.')); if ($hostnameDomain == 'uk') { $hostnameDomain = 'gb'; } if (array_key_exists($hostnameDomain, Common::getCountriesList())) { $visitorInfo['location_country'] = $hostnameDomain; } }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onNewVisit(Request $request, Visitor $visitor, $action) { $referrerUrl = $request->getParam('urlref'); $currentUrl = $request->getParam('url'); $information = $this->getReferrerInformation($referrerUrl, $currentUrl, $request->getIdSite()); return $information['referer_url']; }
public static function shouldHandle(Request $request) { $name = $request->getParam('c_n'); $interaction = $request->getParam('c_i'); // if interaction is set we want it to be for instance an outlink, download, ... return !empty($name) && empty($interaction); }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onNewVisit(Request $request, Visitor $visitor, $action) { $language = $request->getBrowserLanguage(); if (empty($language)) { return ''; } return substr($language, 0, 20); }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onNewVisit(Request $request, Visitor $visitor, $action) { $daysSinceLastOrder = $request->getDaysSinceLastOrder(); if ($daysSinceLastOrder === false) { $daysSinceLastOrder = 0; } return $daysSinceLastOrder; }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onNewVisit(Request $request, Visitor $visitor, $action) { $resolution = $request->getParam('res'); if (!empty($resolution)) { return substr($resolution, 0, 9); } return $resolution; }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * * @return mixed|false */ public function onExistingVisit(Request $request, Visitor $visitor, $action) { $forcedUserId = $request->getForcedUserId(); if ($forcedUserId) { return $forcedUserId; } return false; }
public function trackRequest(Request $request) { $allParams = $request->getRawParams(); if (!empty($allParams['forceThrow'])) { throw new ForcedException("forced exception"); } return parent::trackRequest($request); }
public function onLookupAction(Request $request, Action $action) { $contentTarget = $request->getParam('c_t'); $contentTarget = trim($contentTarget); if (strlen($contentTarget) > 0) { return $contentTarget; } return false; }
/** * @param Request $request */ public function __construct(Request $request) { $this->spamFilter = new ReferrerSpamFilter(); $this->request = $request; $this->idSite = $request->getIdSite(); $userAgent = $request->getUserAgent(); $this->userAgent = Common::unsanitizeInputValue($userAgent); $this->ip = $request->getIp(); }
/** * The onNewVisit method is triggered when a new visitor is detected. This means here you can define an initial * value for this user. By returning boolean false no value will be saved. Once the user makes another action the * event "onExistingVisit" is executed. That means for each visitor this method is executed once. If you do not want * to perform any action on a new visit you can just remove this method. * * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed|false */ public function onNewVisit(Request $request, Visitor $visitor, $action) { $localDate = \DateTime::CreateFromFormat("H:i:s", $request->getLocalTime()); $isOddHour = HourParity\isOddHour($localDate); if ($isOddHour) { return 1; } return 0; }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onNewVisit(Request $request, Visitor $visitor, $action) { $userAgent = $request->getUserAgent(); $parser = $this->getUAParser($userAgent); $aBrowserInfo = $parser->getClient(); if (!empty($aBrowserInfo['short_name'])) { return $aBrowserInfo['short_name']; } return 'UNK'; }
private function getIpAddress($anonymizedIp, \Piwik\Tracker\Request $request) { $privacyConfig = new PrivacyManagerConfig(); $ip = $request->getIp(); if ($privacyConfig->useAnonymizedIpForVisitEnrichment) { $ip = $anonymizedIp; } $ipAddress = IP::N2P($ip); return $ipAddress; }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onNewVisit(Request $request, Visitor $visitor, $action) { $referrerUrl = $request->getParam('urlref'); $currentUrl = $request->getParam('url'); $information = $this->getReferrerInformation($referrerUrl, $currentUrl, $request->getIdSite()); if (!empty($information['referer_keyword'])) { return substr($information['referer_keyword'], 0, 255); } return $information['referer_keyword']; }
public function onLookupAction(Request $request, Action $action) { $contentPiece = $request->getParam('c_p'); if (empty($contentPiece)) { return false; } $contentPiece = trim($contentPiece); if (strlen($contentPiece) > 0) { return $contentPiece; } return false; }
public function onLookupAction(Request $request, Action $action) { $interaction = $request->getParam('c_i'); if (empty($interaction)) { return false; } $interaction = trim($interaction); if (strlen($interaction) > 0) { return $interaction; } return false; }
public function test_extract_withAction_shouldReadValueFromAction_NotFromPassedRequest() { $request = $this->buildRequest(); $action = new ActionPageview($request); // we create a new empty request here to make sure it actually reads the value from $action and not from $request $request = new Request(array()); $request->setMetadata('Actions', 'action', $action); $value = $this->buildExtraction('urlparam', 'module')->extract($request); $this->assertSame('CoreHome', $value); $value = $this->buildExtraction('action_name', 'My(.+)Title')->extract($request); $this->assertSame(' Test ', $value); }
/** * Check if the request is from a known spammer host. * * @param Request $request * @return bool */ public function isSpam(Request $request) { $spammers = $this->getSpammerListFromCache(); $referrerUrl = $request->getParam('urlref'); foreach ($spammers as $spammerHost) { if (stripos($referrerUrl, $spammerHost) !== false) { Common::printDebug('Referrer URL is a known spam: ' . $spammerHost); return true; } } return false; }
/** * Returns a 64-bit hash that attemps to identify a user. * Maintaining some privacy by default, eg. prevents the merging of several Piwik serve together for matching across instances.. * * @param $os * @param $browserName * @param $browserVersion * @param $plugin_Flash * @param $plugin_Java * @param $plugin_Director * @param $plugin_Quicktime * @param $plugin_RealPlayer * @param $plugin_PDF * @param $plugin_WindowsMedia * @param $plugin_Gears * @param $plugin_Silverlight * @param $plugin_Cookie * @param $ip * @param $browserLang * @return string */ protected function getConfigHash(Request $request, $os, $browserName, $browserVersion, $plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF, $plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie, $ip, $browserLang) { // prevent the config hash from being the same, across different Piwik instances // (limits ability of different Piwik instances to cross-match users) $salt = SettingsPiwik::getSalt(); $configString = $os . $browserName . $browserVersion . $plugin_Flash . $plugin_Java . $plugin_Director . $plugin_Quicktime . $plugin_RealPlayer . $plugin_PDF . $plugin_WindowsMedia . $plugin_Gears . $plugin_Silverlight . $plugin_Cookie . $ip . $browserLang . $salt; if (!$this->isSameFingerprintsAcrossWebsites) { $configString .= $request->getIdSite(); } $hash = md5($configString, $raw_output = true); return substr($hash, 0, Tracker::LENGTH_BINARY_ID); }
public function onLookupAction(Request $request, Action $action) { if (!$action instanceof ActionEvent) { return false; } $eventAction = $request->getParam('e_a'); $eventAction = trim($eventAction); if (strlen($eventAction) > 0) { return $eventAction; } return false; }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onNewVisit(Request $request, Visitor $visitor, $action) { $userAgent = $request->getUserAgent(); $parser = $this->getUAParser($userAgent); if ($parser->isBot()) { $os = Settings::OS_BOT; } else { $os = $parser->getOS(); $os = empty($os['short_name']) ? 'UNK' : $os['short_name']; } return $os; }
/** * This event is triggered before a new action is logged to the log_link_visit_action table. It overwrites any * looked up action so it makes usually no sense to implement both methods but it sometimes does. You can assign * any value to the column or return boolan false in case you do not want to save any value. * * @param Request $request * @param Visitor $visitor * @param Action $action * * @return mixed|false */ public function onNewAction(Request $request, Visitor $visitor, Action $action) { if (!$action instanceof ActionPageview) { // save value only in case it is a page view. return false; } $value = Common::getRequestVar('my_page_keywords', false, 'string', $request->getParams()); if (false === $value) { return $value; } $value = trim($value); return substr($value, 0, 255); }
/** * @param Request $request * @param bool|string $ip * @param bool|string $userAgent */ public function __construct(Request $request, $ip = false, $userAgent = false) { if ($ip === false) { $ip = $request->getIp(); } if ($userAgent === false) { $userAgent = $request->getUserAgent(); } $this->request = $request; $this->idSite = $request->getIdSite(); $this->userAgent = $userAgent; $this->ip = $ip; }
/** * @param Request $request * @param bool|string $ip * @param bool|string $userAgent */ public function __construct(Request $request, $ip = false, $userAgent = false) { $this->spamFilter = new ReferrerSpamFilter(); if (false === $ip) { $ip = $request->getIp(); } if (false === $userAgent) { $userAgent = $request->getUserAgent(); } $this->request = $request; $this->idSite = $request->getIdSite(); $this->userAgent = $userAgent; $this->ip = $ip; }