This article is a step-by-step hands-on implementation guide of how consent context can be used in the context of Amplitude. 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:
Analytics represented by the property “analytics consent”
Marketing represented by the property “marketing consent”
Personalisation represented by the property “personalisation consent”
In this guide we will be classifying Amplitude 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 Amplitude.
In our example Amplitude could collect any of the following consent context combinations expressed as property and property value.
Scenario walkthrough
Let’s consider the following scenario.
A user lands on the page and makes a choice when it comes to consent.
Consent for analytics purposes is granted. Therefore the Amplitude library was initialised.
The properties that we consider consent context are set as profile properties.
The “Button Selected” event is triggered.
The “Button Selected” event shows up in Amplitude with the appended properties to contextualise consent states.
Scenario implementation
The code is based on the Browser 2.0 documentation.
Initialisation happens according to the init. We omit pageviews for simplicity.
Set user properties:
const identifyEvent = new amplitude.Identify();
identifyEvent.set('consent analytics', true);
identifyEvent.set('consent marketing', false);
identifyEvent.set('consent personalisation', false);
amplitude.identify(identifyEvent);
Track the event:
amplitude.track("Button Selected",
{
"button color" : "red",
"button link" : "http://xyz.com/button_link"
}
);
How amplitude receives the event:
{
"$insert_id": "9e12c9bc-76c0-4129-8422-8bdb981f4d80",
"$schema": 13,
"_time": 1726914498685,
"amplitude_attribution_ids": null,
"amplitude_id": 996568199461,
"app": 338385,
"city": "Brussels",
"client_event_time": "2024-09-21 10:28:18.685000",
"client_upload_time": "2024-09-21 10:28:19.947000",
"country": "Belgium",
"data": {
"group_first_event": {
},
"group_ids": {
},
"path": "/2/httpapi"
},
"device_carrier": null,
"device_family": "Android",
"device_id": "aab6aad0-9740-4efe-8edf-fdef40330373",
"device_type": "Android",
"display_name": "Button Selected",
"dma": null,
"event_id": 192,
"event_properties": {
"button color": "red",
"button link": "http://xyz.com/button_link"
},
"event_time": "2024-09-21 10:28:18.685000",
"event_type": "Button Selected",
"group_properties": {
},
"groups": {
},
"ip_address": "37.185.164.131",
"language": "English",
"library": "amplitude-ts/2.10.0",
"location_lat": null,
"location_lng": null,
"os": "Chrome Mobile 128",
"os_name": "Chrome Mobile",
"os_version": "128",
"partner_id": null,
"paying": null,
"plan": {
},
"platform": "Web",
"processed_time": "2024-09-21 10:28:21.266000",
"region": "Brussels Capital",
"sample_rate": null,
"server_received_time": "2024-09-21 10:28:19.947000",
"server_upload_time": "2024-09-21 10:28:19.953000",
"session_id": 1726914400495,
"source_id": null,
"start_version": null,
"timeline_hidden": false,
"user_id": null,
"user_properties": {
"consent analytics": true,
"consent marketing": false,
"consent personalisation": false
},
"uuid": "e13877f4-19ec-4b6f-8e74-5a24be4f9e69",
"version_name": null
}
Note that the event “Button Selected” did not have the properties applied when the data was sent in. However, Amplitude appenends the current values of the profile 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