top of page
Writer's pictureGlenn Vanderlinden

Consent context for Mixpanel implementation guide

This article is a step-by-step hands-on implementation guide of how consent context can be used in the context of Mixpanel. In order to get a better understanding of the concept consent context, please read our introduction article. 


Tool classification and consent value


In the following example we will be considering three types of consent that can be granted or no by a user:


  1. Analytics represented by the property “analytics consent”

  2. Marketing represented by the property “marketing consent”

  3. Personalisation represented by the property “personalisation consent”


In this guide we will be classifying Mixpanel as an analytics platform. Therefore the value for the property “analytics consent” as part of our consent context is required to be set to “true” in order for the data to successfully stream into Mixpanel. 


In our example Mixpanel could collect any of the following consent context combinations expressed as property and property value.


Scenario walkthrough


In order to simplify this exercise we will illustrate it using a client-side Mixpanel SDK.

Let’s consider the following scenario.

  1. A user lands on the page and makes a choice when it comes to consent.

  2. Consent for analytics purposes is granted. Therefore the Mixpanel library was initialised.

  3. The properties that we consider consent context are set as super properties. Note that super properties are only available in the client-side SDKs. The alternative for server-side tracking is to handle that yourself on the server.

  4. The “Button Selected” event is triggered.

  5. The “Button Selected” event shows up in Mixpanel with the appended properties to contextualise consent states.


Scenario implementation


The code is based on the Javascript SDK documentation. Super property functionality is limited to front-end SDKS. Server-side tracking requires manual/homebrew replication of the functionality.

Initialisation happens according to the init. We omit pageviews for simplicity. 


Set super properties:

mixpanel.register({
    "consent analytics" : true,
    "consent marketing" : false,
    "consent personalisation" : false
});

Send user properties:

mixpanel.people.set({ 
    "consent analytics" : true,
    "consent marketing" : false,
    "consent personalisation" : false
});

Send track call:

mixpanel.track("Button Selected",
  {
    "button color" : "red",
    "button link" : "http://xyz.com/button_link"    
  }
);

How Mixpanel receives the event:

{
  "event": "Button Selected",
  "properties": {
    "time": 1727107632.791,
    "distinct_id": "$device:1921f9d823bf96e-0732f094a5349f-17525637-74ece-1921f9d823bf96e",
    "$browser": "Chrome",
    "$browser_version": 128,
    "$city": "Brussels",
    "$current_url": "http://localhost:1337/",
    "$device": "Android",
    "$device_id": "1921f9d823bf96e-0732f094a5349f-17525637-74ece-1921f9d823bf96e",
    "$initial_referrer": "$direct",
    "$initial_referring_domain": "$direct",
    "$insert_id": "spaoknsjctlfyp7v",
    "$lib_version": "2.55.1",
    "$mp_api_endpoint": "api-js.mixpanel.com",
    "$mp_api_timestamp_ms": 1727107634930,
    "$os": "Android",
    "$region": "Brussels Capital",
    "$screen_height": 362,
    "$screen_width": 1323,
    "button color": "red",
    "button link": "http://xyz.com/button_link",
    "consent analytics": true,
    "consent marketing": false,
    "consent personalisation": false,
    "mp_country_code": "BE",
    "mp_lib": "web",
    "mp_processing_time_ms": 1727107636111,
    "mp_sent_by_lib_version": "2.55.1"
  }
}

Note that the event “Button Selected” did not have the properties applied when the data was sent in. However, Mixpanel appends the values of the super properties to the ingested event. We can leverage this to build consent context for the moment at which the data point was ingested.


For a more detailed walkthrough on how user properties can be leveraged you can consult our guide


In-platform result


When building cohorts with the purpose to share it with marketing channels the following rule can then be applied. This ensures the data point was captured with the correct consent.

The latest value for any of the consent types can also be read directly from the user’s profile and used while building the cohort.


Interested? Feel free to reach out!

Comments


bottom of page