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);
}