This guide lists the steps to develop a consent interceptor for the Android SDK and use the interceptor to initialize the SDK after the user gives their consent.
Overview
The consent management is designed to be a filter for the event destinations and the natively added factories. Since the SDK initializes the native integration factories during the startup, you must first capture the user’s consent to the cookie categories.
You can add only one consent filter to the Android SDK.
For filtering, RudderStack uses the getConsentStatusForGroupId method of the OneTrust SDK.
Install OneTrust consent
This setup assumes the Android SDK and the OneTrust SDK are already added to your application.
Add OneTrust Consent Filter to your build.gradle (module level).
dependencies{// add other dependencies
...implementation'com.onetrust.cmp:native-sdk:202301.2.0.0'implementation('com.rudderstack.android.sdk:core:1.12.0')implementation('com.rudderstack.android.consentfilter:onetrustconsentfilter:1.1.0')...}
Move the RudderStack initialization consent callback. The following snippet shows a sample application file highlighting the initialization:
classCustomApplication:Application(){var_rudderClient:RudderClient?=null;valrudderClientget()=_rudderClientprivatevaloneTrustEventListener=object: OTEventListener(){overridefunonShowBanner(p0:OTUIDisplayReason?){}overridefunonHideBanner(){}overridefunonBannerClickedAcceptAll(){createRudderClientWithOneTrust()}overridefunonBannerClickedRejectAll(){createRudderClientWithOneTrust()}overridefunonShowPreferenceCenter(p0:OTUIDisplayReason?){}overridefunonHidePreferenceCenter(){}overridefunonPreferenceCenterAcceptAll(){createRudderClientWithOneTrust()}overridefunonPreferenceCenterRejectAll(){createRudderClientWithOneTrust()}overridefunonPreferenceCenterConfirmChoices(){createRudderClientWithOneTrust()}overridefunonShowVendorList(){}overridefunonHideVendorList(){}overridefunonVendorConfirmChoices(){}overridefunallSDKViewsDismissed(p0:String?){}overridefunonVendorListVendorConsentChanged(p0:String?,p1:Int){}overridefunonVendorListVendorLegitimateInterestChanged(p0:String?,p1:Int){}overridefunonPreferenceCenterPurposeConsentChanged(p0:String?,p1:Int){}overridefunonPreferenceCenterPurposeLegitimateInterestChanged(p0:String?,p1:Int){}}internalvalotPublishersHeadlessSDKbylazy{OTPublishersHeadlessSDK(this)}overridefunonCreate(){super.onCreate()setupOneTrust()}internalfunsetupOneTrust(){// set up one trust,
// uncomment the following line and pass the credentials
// otPublishersHeadlessSDK.startSDK()
otPublishersHeadlessSDK.addEventListener(oneTrustEventListener)}privatefuncreateRudderClientWithOneTrust(){_rudderClient=RudderClient.getInstance(this,WRITE_KEY,RudderConfig.Builder().withDataPlaneUrl(DATA_PLANE_URL).withTrackLifecycleEvents(true).withRecordScreenViews(false).withConsentFilter(RudderOneTrustConsentFilter(otPublishersHeadlessSDK)).build())}privatevalotSdkParamsget()=OTSdkParams.SdkParamsBuilder.newInstance().build()}
Create custom consent filter
Create a new Android library project.
Add the following to the dependencies section in the module-level build.gradle file:
dependencies{// add other dependencies
...compileOnly'com.rudderstack.android.sdk:core:1.12.0'...}
Create a class to implement RudderConsentFilterWithCloudIntegration:
publicfinalclassMyConsentFilterimplementsRudderConsentFilterWithCloudIntegration{@OverridepublicMap<String,Boolean>getConsentCategoriesMap(){// return the category id to consent map.
// The map should have the category id as key and true if consented,
// false otherwise
// Rudderstack SDK will filter out the destinations corresponding to
// categories that are not consented.
}}
Attach MyConsentFilter to the RudderStack Android SDK similar to the OneTrust consent filter:
_rudderClient=RudderClient.getInstance(this,WRITE_KEY,RudderConfig.Builder()// other methods
.withConsentFilter(MyConsentFilter()).build())
Additional settings for cloud mode
RudderStack supports OneTrust integration in cloud mode from Android SDK v1.12.0 and above.
You can specify the OneTrust cookie categories when sending events from your Android source in the cloud mode.
Set up your Android source in the RudderStack dashboard.
Connect it to a destination.
In the destination settings, enter the OneTrust category IDs in the Enter consent category IDs field:
You can find the category IDs in your OneTrust dashboard under Preference & Consent Management > Cookie Compliance > Categorizations > Categories.
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.