Quantcast
Channel: Support & Bugs - Matomo forums
Viewing all articles
Browse latest Browse all 5706

Geolocation wrong on internal network + possible solution

$
0
0

Our websites are accessed externally and internally (with an IP from the local network range).
GeoIp is installed and enabled.

Despite having set enable_language_to_country_guess=0, the geolocation information for users from the local network is set based on their browser language and therefore totally wrong.

This seems to happen in Common::extractCountryCodeFromBrowserLanguage and I’ve got the feeling that this function does not respect the config value correctly.

public static function extractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, $enableLanguageToCountryGuess)
{
	/** @var LanguageDataProvider $dataProvider */
	$dataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\LanguageDataProvider');

	$langToCountry = $dataProvider->getLanguageToCountryList();

	if ($enableLanguageToCountryGuess) {
		if (preg_match('/^([a-z]{2,3})(?:,|;|$)/', $browserLanguage, $matches)) {
			// match language (without region) to infer the country of origin
			if (array_key_exists($matches[1], $langToCountry)) {
				return $langToCountry[$matches[1]];
			}
		}
	}

        // the following code should run only if enableLanguageToCountryGuess is enabled

	if (!empty($validCountries) && preg_match_all('/[-]([a-z]{2})/', $browserLanguage, $matches, PREG_SET_ORDER)) {
		foreach ($matches as $parts) {
			// match location; we don't make any inferences from the language
			if (array_key_exists($parts[1], $validCountries)) {
				return $parts[1];
			}
		}
	}
	return self::LANGUAGE_CODE_INVALID;
}

I would prefer having an “unknown” country to having a wrong one (US, UK, DE…).
Is there any way to achieve this?

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5706

Trending Articles