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

Country is not detected with GeoIP if IP is overridden via cip parameter #15192

Closed
damianmoore opened this issue Nov 24, 2019 · 9 comments
Closed
Labels
worksforme The issue cannot be reproduced and things work as intended.

Comments

@damianmoore
Copy link

I have a situation where I send tracking requests from the server on behalf of user. To make sure I track the user's correct IP address rather than my own server's address, I add the cip parameter to the request as referred to here. I've noticed that since doing this, the user's IP addresses are not geo-coded to have a country any more and just display as 'Unknown' with a question mark.

The code I am using can be viewed here. If you want a bit more background on my reasoning you can read the description of my GitHub project called Matomo Monorail.

I believe that if the cip parameter is included, this should be what gets fed into the GeoIP database. I have other sites tracking to the same Matomo installation via JS directly so am sure the country detection is working.

I'm using Matomo version 3.12.0 from the official Docker image (matomo:3.12.0-apache).

@tsteur
Copy link
Member

tsteur commented Nov 24, 2019

Hi there, I recommend you check if

  • You have "Use anonymized IP for visit enrichment" enabled in privacy => anonymise data
  • Make sure your requests are authenticated with a token having at least "write" permission

From what I can see in the code this should work and we're actually using this in many places ourselves and don't have any issues with it.

@damianmoore
Copy link
Author

Hi @tsteur, thanks for your reply. Can't find "Use anonymized IP for visit enrichment" exactly but "Anonymize Visitors' IP addresses" is unchecked - is this the same? Couldn't seem to see anything similar in global.ini.php either.

For the token permissions, under "API Authentication Token" I can only view or regenerate. Visits are definitely being logged though so I assume this means it has write permissions.

I've updated to version 3.13 in case these settings changed names but doesn't look like it.

@tsteur
Copy link
Member

tsteur commented Nov 28, 2019

Visits are definitely being logged though so I assume this means it has write permissions.

This does not mean the token was write permission. You'll need to double check if the token auth is correct, and whether the user for that token has write permission (eg a super user can check this but you can also check if that user has permission to create for example Goals).

@sgiehl
Copy link
Member

sgiehl commented Nov 29, 2019

@damianmoore Which GeoIP location provider have you configured in Matomo?

@damianmoore
Copy link
Author

@tsteur I can confirm the token_auth is correct and it belongs to the role for this user under "Manage Users" shows as "Super User".

@sgiehl The GeoIP stuff is baked into this Dockerfile which appears to be MaxMind's GeoLite2-City.

This screenshot is of the site where Matomo requests are proxied with cip and token added by the backend.

This screenshot is of a different site where requests go directly to Matomo and countries are detected from header IP.

Any other ideas for things I can check?

@tsteur
Copy link
Member

tsteur commented Dec 5, 2019

@damianmoore I would recommend to maybe enable tracker logging for a short time to investigate the issue further:

See https://developer.matomo.org/api-reference/tracking-api#debugging-the-tracker on how to enable tracker debug. (should be only enabled for a short time since this may be visible to your users if someone was to actually look at the response of tracking requests)
And you maybe want to enable logging to file see https://matomo.org/faq/troubleshooting/faq_115/ so you can see what happens for the requests that use cip.

@mattab
Copy link
Member

mattab commented Dec 24, 2019

Any update maybe @damianmoore - do you still experience the issue?

@mattab mattab added the worksforme The issue cannot be reproduced and things work as intended. label Jan 21, 2020
@mattab mattab closed this as completed Jan 21, 2020
@damianmoore
Copy link
Author

I've just figured out what was happening when I reported this issue and now have it all working without changing my API calls to Matomo. I had wrongly thought I had Geocoding set up because I saw countries displayed for other sites I had on my Matomo installation. I hadn't realised that Matomo infers country from browser language and I was not including this header when calling the API myself. Now I have DBIP configured correctly I have countries and much more accurate city level data.

@tsteur
Copy link
Member

tsteur commented Mar 30, 2020

Awesome, thanks for letting us know @damianmoore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
worksforme The issue cannot be reproduced and things work as intended.
Projects
None yet
Development

No branches or pull requests

4 participants