Universal Consent Purposes

📘

Universal Consent Purposes for Mobile is part of the Universal Consent and Preference Management (UCPM) offering and you must have a UCPM license to use this product.

Overview

Universal Consent serves a different use case than the CMP. 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 or Marketo. After consent has been collected, integration workflows can be triggered within the OneTrust tool.

Universal Consent requires a user identifier to function effectively. By default, consent is stored at the device level rather than being linked to a specific user. To enable advanced features—such as creating integration workflows and building user profiles in OneTrust—you can associate consent with a unique user identifier. This is done by utilizing the Cross Device functionality to create or update user profiles.

👍

For more information, see Unified Profile.

📘

Before proceeding, make sure that Universal Consent purposes has been configured inside of the OneTrust Admin Portal. For more information, see Universal Consent Purposes for Mobile App Consent.

To create integration workflows, see Connecting CMP Preferences with Universal Consent & Preference Management Profiles.

Initialize the SDK and Fetch Universal Consent Data

The OneTrust SDK retrieves an object that contains all the data needed to present the Universal Consent Preference Center and collect consent. The data returned is determined by the configurations made in the OneTrust Admin console.

📘

For more information on how to initialize the OneTrust SDK, see Initialize the SDK.

setUCPurposeFlow

During initialization, the app must set .setUCPurposeFlow("true") in SDK Params to fetch Universal Consent data. See more details here.

OTSdkParams.SdkParamsBuilder sdkParamsBuilder = OTSdkParams.SdkParamsBuilder.newInstance()
                        .setUCPurposeFlow("true");
OTSdkParams sdkParams = sdkParamsBuilder.build();

Return downloaded Universal Consent Purpose Data

After successfully initializing the SDK, you can return the downloaded data if desired.

getUCPurposeData

OTPublishersHeadlessSDK sdk = new OTPublishersHeadlessSDK(context);  

// Retrieve the Universal Consent Purpose data as a JSONObject 
JSONObject ucPurposeData = sdk.getUCPurposeData(); 

This method returns a JSONObject containing all UC configurations set in the OneTrust tenant. This includes the data needed to present the UI and manage consents collected.

Display the Universal Consent Preference Center

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 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 Events

Each time a user updates their Universal Consent choices, the SDK broadcasts an event the app can listen for to trigger a subsequent action.

Setting it up

Declare the broadcast listener variables.

private BroadcastReceiver purpose1Receiver;

Initialize and register the listeners in the onCreate method of the 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")); 

The callback above will return a JSON string that contains Topics, Custom Preferences and ID statuses of the Purpose you're listening for:

Sample payload:

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

Unregister listeners in the onDestroy method of the activity.

unregisterReceiver(purpose1Receiver);

The broadcast will only be triggered for purposes that have been updated. If any of the Topics or Custom Preferences of the purpose change, then SDK will trigger broadcasts for that purposeId.

Programmatically Set Universal Consent Values

The SDK exposes methods to programmatically 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 programmatically set the value of the associated purpose. The user can subsequently change their decision later in the preference center UI.

Update Purpose Consent

To update the top-level purpose 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);

🚧

As mentioned above, the application MUST call saveConsent after updateUCPurposeConsent to commit the change. If saveConsent is not called, consents will not be updated.