Universal Consent Purposes

📘

Important

Universal Consent Purposes for Mobile is part of the UCPM offering and you must have a UCPM license to use this module.

Overview

Universal Consent can be used to serve a different use case compared to the regular Mobile App Consent banner and this can also be configured within the Mobile SDK. Rather than collecting user consent to help manage SDKs and other technologies on the app, Universal Consent helps collect consent for purposes like promotional emails, newsletters, SMS messaging, etc. that typically require an integration with a third party system like Salesforce and Marketo. After a Universal Consent transaction is collected, integration workflows can be triggered within the OneTrust tool.

Universal Consent requires a user identifier to work properly. By default, consent will stored against the device, rather than a specific user identifier. In order to create a profile for the user in OneTrust and to benefit from features such as creating integration worfklows, you can tie the consent to a specific user identifier by set a data subject and keep their consent in sync with other collection methods, utilizing the Profile Sync Params guidance.

📘

Note

Before proceeding, make sure that Universal Consent purposes has been configured inside of the OneTrust Admin Portal. View instructions here

To create integration workflows please visit the following article

Initialize SDK

The OneTrust SDK retrieves an object that contains all the data needed to present the Universal Consent Preference Centre and collect consent for the specified purposes. The data returned is determined by the configurations made in the OneTrust Admin console. For more details on how to initialize the OneTrust SDK, please refer to the linked iOS and android documentation.

Display Universal Consent Preference Center

To load the Universal Consent preference center over the current screen, simply call:

new OTPublishersHeadlessSDK(this).showConsentPurposesUI(RenderNativeUIActivity.this);

Query for Universal Consent Values

The SDK exposes methods to retrieve the current state of the users' consent.

StatusExplanation
1Consent is given (An end user interacts with the SDK and gives consent.)
0Consent is not given (An end user interacts and does not give consent.)
-1Consent has not been collected (The SDK is not yet initialized for the end user.)

You can query the consent status for Universal Consent Purposes, Topic and Custom Preferences.

Get Purpose Consent

To query for the top-level purpose's consent:

new OTPublishersHeadlessSDK(this).getUCPurposeConsent("purposeId"); 
ArgumentTypeDescription
purposeIdStringThe GUID of the purpose to retrieve.

Get Custom Preferences Consent

To query for a custom preference nested under a purpose:

new OTPublishersHeadlessSDK(this).getUCPurposeConsent("customPreferenceOptionId", "customPreferenceId", "purposeId");
ArgumentTypeDescription
customPreferenceOptionIdStringThe GUID of the custom preference option
customPreferenceIdStringThe GUID of the custom preference group
purposeIdStringThe GUID of the purpose under which the custom preference is nested.

Broadcast Listener - Universal Purposes

Universal Consent Purposes broadcast steps are same as the normal category broadcasts. The app will be listening to each of the purpose Ids (intent filter will be purposeId GUID).
This code is to be added to the activity on which the user interacts (RenderNativeUIActivity in Demo app.)

First, declare the broadcast listener variables.

private BroadcastReceiver purpose1Receiver;

Second, initialize and register the listeners in the onCreate method of activity.

// Initialize purpose1 Receiver 
purpose1Receiver = new BroadcastReceiver() {
                @Override
  // Callback when consent changed for this UC Purpose.  
                public void onReceive(Context context, Intent intent) {
                  // Write Purpose related logic here...
                    Log.i("BroadcastService", "Intent name: " + intent.getAction() +
                            " status = " + intent.getStringExtra(OTBroadcastServiceKeys.UCP_EVENT_STATUS));
                }
            };
registerReceiver(purpose1Receiver, new IntentFilter("replace wth purposeId GUID")); 

This will give a JSON string which contains Topics, Custom Preferences and ID statuses with respect to the Purpose app is listening for in the following format:

{
	status: 0, 
	custom_preferences”: {
		"cpId": {
			“cpOptionID1”: 0, 
			”cpOptionID1”: 0
		}
	}, 
	”topics”: {
		"topicOpId1": 0,
		"topicOpId2": 1
	}
}

Finally, unregister listeners in the onDestroy method of activity

unregisterReceiver(purpose1Receiver);

The broadcast will be triggered only for those purpose IDs which have a change in its saved consent values. If any of the Topic and Custom Preference options consent of a purpose ID changes, then SDK will trigger broadcasts for that purposeId.

Programatically Set Universal Consent Values

The SDK exposes methods to programatically set the users' consent values. A common use case is when a sign-up form has a checkbox at the bottom to allow the user to opt into emails. In this case, the application would set the value of the associated purpose, and the user could change his or her decision later in the preference center.

📘

Note

After making consent updates, the application must call the saveConsent(OTConsentInteractionType.UC_PC_CONFIRM) function to commit the changes.

Update Purpose Consent

To update the top-level purpose's consent:

new OTPublishersHeadlessSDK(this).updateUCPurposeConsent("purposeId", true);
ArgumentTypeDescription
purposeIdStringThe GUID of the purpose to update
consentBooleanWhether or not consent has been granted for the specified item

Update Custom Preference Consent

To update a custom preference nested under a purpose:

new OTPublishersHeadlessSDK(this).updateUCPurposeConsent("customPreferenceOptionId", "customPreferenceId", "purposeId", false);
ArgumentTypeDescription
customPreferenceOptionIDStringThe GUID of the custom preference option
customPreferenceIdStringThe GUID of the custom preference group
purposeIdStringThe GUID of the purpose under which the custom preference is nested.
consentBooleanWhether or not consent has been granted for the specified item

Save Consent

After making updates to the consent values, the application must call the following method to commit the changes:

OTPublishersHeadlessSDK otPublishersHeadlessSDK = new OTPublishersHeadlessSDK(this); 
otPublishersHeadlessSDK.updateUCPurposeConsent("purposeId", true); 
otPublishersHeadlessSDK.saveConsent(OTConsentInteractionType.UC_PC_CONFIRM);