While using Mixpanel's API for a profile-batch-update, how do I set the Country and City of my users? Their are getting all the same City and Country from the computer I'm sending the request.
Hi Karon L., Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> đź‘‹
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
To set the correct Country and City for your users when using Mixpanel's API for profile batch updates, you need to manually specify these properties or prevent Mixpanel from automatically setting them based on your server's IP address. Here's how you can address this issue:1. Manually define geolocation properties:
You can explicitly set the $country_code
, $region
, and $city
properties in your profile update payload. This will override the default geolocation derived from the IP address. Example:
"$token": "project_token",
"$distinct_id": "user_id",
"$set": {
"my_property": "my_value",
"$country_code": "US",
"$region": "California",
"$city": "San Francisco"
}
}
```LBKS [Mixpanel Docs: Manual Geolocation Tracking](https://docs.mixpanel.com/docs/tracking-best-practices/geolocation#manual-geolocation-tracking)LBKS2. Ignore IP address:
To prevent Mixpanel from updating geolocation based on your server's IP, set the `$ip` property to "0" in your payload:LBKS
```LBKS {
"$token": "mytoken",
"$distinct_id": "user_id",
"$ip": "0",
"$set": {
"My_property": "my_value"
}
}
```LBKS [Mixpanel Docs: Ignore IP Address](https://docs.mixpanel.com/docs/tracking-best-practices/geolocation#ignore-ip-address)LBKS Alternatively, you can append `ip=0` to your request URL:
```LBKS [api.mixpanel.com/engage?verbose=1&ip=0](http://api.mixpanel.com/engage?verbose=1&ip=0)
```LBKSLBKS3. Use latitude and longitude:
If you have access to precise location data, you can use `$latitude` and `$longitude` properties:LBKS
```LBKS {
"$token": "mytoken",
"$distinct_id": "user_id",
"$latitude": 37.77,
"$longitude": -122.42,
"$set": {
"My_property": "my_value"
}
}
```LBKS [Mixpanel Docs: Define Latitude and Longitude](https://docs.mixpanel.com/docs/tracking-best-practices/geolocation#define-latitude-and-longitude)LBKSBy using one of these methods, you can ensure that your users' locations are set correctly and not all assigned to the location of your server.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
what if I have the IP for each user? How can I send them?
Let me check the knowledge base for you again. One moment! đź“š
If you have the IP address for each user, you can include it in your profile update payload to Mixpanel. This will allow Mixpanel to derive the correct geolocation data for each user based on their individual IP addresses. Here's how you can do it:1. For profile updates, you can include the $ip
property in your payload::LBKSLBKS```LBKS{
"$token":: "mytoken",
"ip": "136.24.0.114",
"$set": {
"My_property": "my_value"
}
}```Mixpanel Docs: Define IP AddressBy providing the user's actual IP address, Mixpanel will use this to determine the geolocation data ($city
, $region
, $country_code
) for the user profile.It's important to note that while Mixpanel uses the IP address to generate geolocation properties, the IP address itself is not stored. Mixpanel parses the IP address through MaxMind to generate the Country, Region, and City values, attaches these to your data, and then discards the IP address value before ingesting the data into your project.Mixpanel Docs: IP address ParsingRemember that if you're tracking from your server, you need to set the $ip
property of the profile updates to the client's IP address, not your server's IP. This ensures that the geolocation data reflects the user's actual location rather than your server's location.Mixpanel Docs: Server-Side Best PracticesBy following this approach, you can ensure that each user's geolocation data is accurately determined based on their individual IP addresses.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.