mixpanel/mixpanel-js

No Geolocation info when using a Proxy. X-REAL-IP ignored?

Closed this issue · 2 comments

When using the mixpanel sdk (2.38.1) directly with the mixpanel backend, my events get city and country information filled in.

But when setting the api_host property to proxy through my backend, the Geolocation info does not show up.

I have double and tripple checked that my backend does indeed set the X-REAL-IP header on the request going out to the mixpanel ingestion api, with the correct IP inside.

I tried 'x-real-ip' 'X-REAL-IP' and 'X-Real-Ip', I even tried 'X-Forwarded-For' as well, but nothing seems to work. What am I missing?

I also noticed that the request the SDK sends always includes ?ip=1 among other things in the search query. I'm not sure if this significant. It does this regardless of setting the api_host, so it probably doesn't mean much.

Any help?

Yes, your proxy should forward the request exactly as received. Without the ip=1 param the API will not look at the IP address and won't fill out geolocation fields. Beyond that, setting the appropriate headers in your proxy is all you need. Here's an nginx config that we recommend: https://github.com/mixpanel/tracking-proxy/blob/126203cda52abd1564b8d82ab5dd88f67e7c27a5/nginx.conf#L29-L35

NOTE: This comment initially showed some example code I was using to call mixpanel, there's nothing interesting in there, except a huge mistake where I accidentally cut-off the searchParams, without realising it. I thought I WAS sending the search params all along, but I was not.

I'm very sorry for the false alarm. After including the search params, everything works as expected.