how can a user's country code be undefined but all the events associated with that user have country set to united states
This is a common scenario in Mixpanel, and it comes down to how profile geolocation and event geolocation are set independently of each other.
Why This Happens
Event geolocation is parsed at the time each event is tracked, using the IP address of the request at that moment.
Profile geolocation ($country_code on the user profile) is only updated when a profile property is set or updated (via a $set or $set_once operation). Critically, Mixpanel's default user properties are only updated when you send or update at least one property yourself. [User Properties]
So if a user has been tracked firing events (which correctly resolve to "United States" via their IP), but no profile update has ever been sent for that user, their profile will never have had geolocation set โ leaving $country_code as undefined/not set.
Other Possible Causes
Server-side profile updates: If profile properties are being set from a server, Mixpanel uses the server's IP address for geolocation, not the user's. If the server IP can't be mapped to a location (or is being suppressed with ip: 0), the profile country code could remain undefined. [Sending Data to Mixpanel]
$ip set to 0: If profile update requests explicitly pass ip: 0, Mixpanel skips geolocation parsing entirely for that profile update, leaving the country code unset. [Geolocation]
How to Fix It
To ensure the user profile has the correct country code, you can:
Pass the actual client IP using $ip in your profile update payload so Mixpanel can parse the correct location.
Manually set the geolocation properties directly on the profile:{ "$token": "project_token", "$distinct_id": "user_id", "$set": { "$country_code": "US", "$region": "California", "$city": "San Francisco" } }
Use latitude/longitude by passing $latitude and $longitude in the profile update payload. [Manual Geolocation Tracking]
โน๏ธย Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
