Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to return current user's geolocation "UserCountry.getLocationFromIP" #14496

Closed
mattab opened this issue May 29, 2019 · 3 comments · Fixed by #14497
Closed

API to return current user's geolocation "UserCountry.getLocationFromIP" #14496

mattab opened this issue May 29, 2019 · 3 comments · Fixed by #14497
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Milestone

Comments

@mattab
Copy link
Member

mattab commented May 29, 2019

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 mattab added the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label May 29, 2019
@mattab mattab added this to the 3.10.0 milestone May 29, 2019
@mattab
Copy link
Member Author

mattab commented Jun 29, 2019

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
Copy link
Member

tsteur commented Jun 29, 2019

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
Copy link
Member Author

mattab commented Jun 29, 2019

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants