@mattab opened this Issue on May 29th 2019 Member

Goal of this issue is to make our existing API UserCountry.getLocationFromIP return the geolocation information for the requesting IP address by default.

Currently, the API requires an ip parameter. Example API request

But if we make it default to the current requester IP address then it will provide some great value and open new use cases. For example some users want to customise the website's content based on the user's geolocation. So they could simply call the API for example via: https://analytics.example.comorg/?module=API&method=UserCountry.getLocationFromIP&format=json in JavaScript.

@mattab commented on June 29th 2019 Member

Added to our existing FAQ How do I get the Visitor Geo Location data from the Visitor IP? the following text:

Since Matomo 3.10.0 you can also use this API in JavaScript / JSON by simply calling the API without specifying the ip URL parameter. This is valuable because when you're running in the browser in JavaScript it is not possible to get the IP address. So by simply calling this API: https://analytics.example.comorg/?module=API&method=UserCountry.getLocationFromIP&format=json in JavaScript you will get the geo location data for the current user requesting this request. This would be useful when you want to personalise the website's content based on the user's geolocation for example.

@tsteur commented on June 29th 2019 Member

This will work only when anonymous access is enabled and has access to a site.

You may want to mention this. You may want to also mention that this allows other users to use the API which may not be wanted considering other services charge for such things as it can cause performance trouble etc.

@mattab commented on June 29th 2019 Member

This will work only when anonymous access is enabled and has access to a site.

I had not noticed this, thanks for pointing out. Added to faq https://matomo.org/faq/how-to/faq_182/

This Issue was closed on May 29th 2019
Powered by GitHub Issue Mirror