Pass the consent category IDs as contextual information in events for server-side SDKs and other sources.
This guide explains how to add the consent data to event payloads to implement the consent-based filtering logic (allow or block) on downstream destinations.
Irrespective of the source or destination, RudderStack honors the consent ID values included in the consentManagement
object in the context of event payloads. Several RudderStack SDKs provide native integrations with popular consent management providers and automatically add this data for you.
You can also add the consent data to the event payloads manually to apply the filtering logic (allow or block) for downstream destinations. You can use this approach for:
The following snippets highlight some sample instrumentations to send the consent management data to OneTrust via various RudderStack sources:
curl --location '<DATA_PLANE_URL>/v1/track' \
--header 'Content-Type: application/json' \
--data '{
"type": "track",
"event": "Product Purchased",
"properties": {
"name": "Sweatshirt",
"price": 14.99
},
"context": {
"consentManagement": {
"allowedConsentIds": ["<category_id_1>", "<category_id_2>"], // Required
"deniedConsentIds": ["<category_id_3>", "<category_id_4>"], // Required
"provider": "oneTrust",
"resolutionStrategy": "and" // Required for "oneTrust" / "ketch" / "iubenda"; Not required for "custom"
},
"traits": {
"email": "alex@example.com.com",
"plan": "Free Tier"
},
"library": {
"name": "http"
},
},
"originalTimestamp": "2024-11-30T14:31:15.032Z",
"messageId": "39342c15-e6aa-4dd6-8882-5a04befd796a",
"userId": "4hs323dsh421ddb",
"anonymousId": "32cc095e-5b8f-43d0-b69c-c4623d1be5c7",
"integrations": {
"All": true
},
"sentAt": "2024-11-30T14:31:16.998Z"
}'
You can pass the consent data to your iOS SDK by setting it as custom contextual information, as shown:
RSOption* option = [[RSOption alloc] init];
[option putCustomContext:@{
@"allowedConsentIds": @[@"<category_id_1>", @"<category_id_2>"], // Required
@"deniedConsentIds": @[@"<category_id_3>", @"<category_id_4>"], // Required
@"provider": @"oneTrust",
@"resolutionStrategy": @"and", // Required for "oneTrust" / "ketch" / "iubenda"; Not required for "custom"
} withKey:@"consentManagement"];
[[RSClient sharedInstance] track:@"Track Event" properties:properties options:option];
See the iOS SDK documentation for more information on setting the custom context.
You can pass the consent data to your Android SDK by setting it as custom contextual information, as shown:
val options = RudderOption()
.putCustomContext(
"consentManagement",
mapOf(
"allowedConsentIds" to listOf("<category_id_1>", "<category_id_2>"), // Required
"deniedConsentIds" to listOf("<category_id_3>", "<category_id_4>"), // Required
"provider" to "oneTrust",
"resolutionStrategy" to "and" // Required for "oneTrust" / "ketch" / "iubenda"; Not required for "custom"
)
)
rudderClient.track("Track event", properties, options)
See the Android SDK documentation for more information on setting the custom context.
client.track({
userId: "1hKOmRA4GRlm",
event: "Item Viewed",
properties: {
revenue: 19.95,
shippingMethod: "Premium",
},
context: {
"allowedConsentIds": ["<category_id_1>", "<category_id_2>"], // Required
"deniedConsentIds": ["<category_id_3>", "<category_id_4>"], // Required
"provider": "oneTrust",
"resolutionStrategy": "and" // Required for "oneTrust" / "ketch" / "iubenda"; Not required for "custom"
}
})