/** * @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; }
private function getCountryUsingProviderExtensionIfValid($ipAddress) { if (!Manager::getInstance()->isPluginInstalled('Provider')) { return false; } $hostname = $this->getHost($ipAddress); $hostnameExtension = ProviderProvider::getCleanHostname($hostname); $hostnameDomain = substr($hostnameExtension, 1 + strrpos($hostnameExtension, '.')); if ($hostnameDomain == 'uk') { $hostnameDomain = 'gb'; } if (array_key_exists($hostnameDomain, Common::getCountriesList())) { return $hostnameDomain; } return false; }
private function getCountryUsingProviderExtensionIfValid($ipAddress) { if (!Manager::getInstance()->isPluginInstalled('Provider')) { return false; } $hostname = $this->getHost($ipAddress); $hostnameExtension = ProviderProvider::getCleanHostname($hostname); $hostnameDomain = substr($hostnameExtension, 1 + strrpos($hostnameExtension, '.')); if ($hostnameDomain == 'uk') { $hostnameDomain = 'gb'; } /** @var RegionDataProvider $regionDataProvider */ $regionDataProvider = StaticContainer::get('Piwik\\Intl\\Data\\Provider\\RegionDataProvider'); if (array_key_exists($hostnameDomain, $regionDataProvider->getCountryList())) { return $hostnameDomain; } return false; }