In Matomo (Piwik) we recommend to configure Geo Location so that your visitors are accurately tracked. Once it is setup, you can use a geolocation database to get an IP to Country, or IP to City, or IP to Region information. We have added a simple API that you can re-use, called
To use it, go to Matomo, click API, click on “UserCountry” then on the getLocationFromIp call.
Click to see a typical response from the
UserCountry.getLocationFromIP API call.
You may use this simple Web API provided by Matomo to add geo location functionality to your Apps, for example.
- This will work only when anonymous access is enabled and has access to at least one website.
- because this API request takes around 200ms or more, this is too slow for your website to depend on this request to personalise content. We would only recommend it when personalising elements on the page that are optional (after the main page was loaded) to ensure your website loads quickly.