Keeping Properties Consistent Across Client & Server Libraries

Super properties are client-side properties that accompany each event a user sends to your Mixpanel project. You can use super properties to create custom global properties that are present with all your events.

When you use multiple integration libraries in your Mixpanel reports, you should maintain super properties across each Mixpanel library.

This article shows you how to pass data from the client-side to your server for:

  • Custom super properties
  • Mixpanel default super properties

In the JavaScript library, it is important to note the library loads asynchronously to prevent Mixpanel from blocking other processes from running on your web application.

For a proper return from mixpanel.get_property(), you must wait until the Mixpanel library is fully loaded. To do so, you will want to place any mixpanel.get_property() calls within the “loaded” callback of your Mixpanel initialization “mixpanel.init()” function so the call is only fired once the library completely loads.

You should modify your mixpanel.init() method on any page where you grab a super property from the cookie, such as:

mixpanel.init( "YOUR TOKEN", {'loaded': function() { 
var superProperty = mixpanel.get_property("SuperProperty");

After you’ve grabbed the variables from local memory, you can pass them to your server and use these properties with your server-side events.

Passing Mixpanel Default Super Properties

In addition to the custom super properties you can send with events, Mixpanel also tracks a set of default super properties in the client-side libraries.

Mixpanel stores these default properties in two ways:

  • Store data in local memory (exactly like custom super properties).
  • Parse and interpret the user’s user agent.

For the properties set in local memory, such as utm_source, you can use the exact same steps outlined in the previous section to grab these super properties and pass them to your server.

For the other default super properties, you cannot pass the user agent directly into Mixpanel and have it automatically parsed. To keep consistency across your event reporting, you’ll want to apply the same parsing logic on your backend to interpret the user agent. Applying this logic ensures you don’t have conflicting property keys and values between your client-side and server-side events in Mixpanel.

Below you can find a breakdown of all Mixpanel's default JavaScript super properties, which location they are stored, and links to the explicit logic to parse the user agent to mimic this behavior in your own implementation:

Stored in the Mixpanel cookie:

  • distinct_id - returned with mixpanel.get_distinct_id() 
  • Initial Referrer - $initial_referrer
  • Initial Referring Domain - $initial_referring_domain
  • All UTM properties - utm_campaign etc.

Queried on the user agent for each event:

You’ll notice this list does not include any geolocation properties. Those properties (city, region, country) are handled differently than others because they are set on Mixpanel’s backend.

Gathering geolocation data is based on the IP address of the request. When the request hits Mixpanel's servers, it routes through a third party lookup service (MaxMind), which returns Mixpanel's location-based property values.

In the case of server-side integrations, you can manually append the IP address of your user so that Mixpanel doesn’t interpret requests as having come from the single location where your server is located.

As an important note, assigning location by IP address is handled differently for event tracking and people updates. For events, the IP address is treated as a regular property within the array. You would simply include a property “ip” with your user’s client IP address, as you can see below in PHP:

$mp -> track("Event", array("Property" => "Value", "ip" => "Insert Client IP"));

For a people request, the IP address is appended, after the properties dictionary, as another argument to the people update.

You’ll want to pass the client IP address to Mixpanel as an additional argument of the request, as follows:

$mp -> people -> set($distinct_id, array("Property" => "Value"), "Insert Client IP");

These steps ensure Mixpanel uses the IP address that you manually pass to determine geolocation information, and will ignore the address of the actual request from your server.

Did this answer your question?



Please sign in to leave a comment.