Mixpanel automatically populates the `$country_code` property for both events and user profiles based on geolocation data derived from the IP address of the request. Here’s how it works:
1. For events, Mixpanel uses the property `mp_country_code`, while for user profiles, it uses `$country_code`.
2. When an event is tracked or a profile is updated, Mixpanel extracts the IP address from the request.
3. The IP address is then cross-referenced against MaxMind’s GeoIP database to estimate the country.
4. Mixpanel sets the country code as a 2-letter country code in the raw data.
5. In the Mixpanel UI, this 2-letter code is parsed and displayed as the full country name.
It’s important to note that:
- The IP address itself is not stored by Mixpanel and is discarded after geolocation data is derived.
- For user profiles, geolocation properties are only updated when you send or update at least one property yourself.
- You can manually set or override these properties if needed.
Helpful links:
If you want to disable geolocation tracking or manually set the country code, you can refer to Mixpanel’s documentation here: https://docs.mixpanel.com/docs/tracking-best-practices/geolocation#manual-geolocation-tracking