When Consent Changes

Overview

When a User updates their consent choices or interacts with the SDK UI, the application needs to become aware of that so it can control the next set of actions like:

  • Allowing or Restricting processing of 3rd party SDKs based on their categorization
  • Passing latest User consent values to 3rd Party SDKs
  • Passing the IAB's encoded TC String to 3rd party SDKs
  • Passing the IAB's USP String to 3rd Party SDKs
  • Routing the User to another location in the App
  • Displaying messages to the User of their changes
  • Logging updates to internally owned APIs
  • etc...

Notification Object

The notification object contains an integer that that indicates the consent of the user.

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

Consent Storage

OneTrust stores user consent in local storage under ONETRUST_WEB_STORE. To export in a user friendly format, you can format as a JSON.

  1. JSON.parse(localStorage.ONETRUST_WEB_STORE)[0].CONSENT
  2. Right click the response and select "Store string as global variable"
  3. JSON.parse(tempvariable)

Querying Consent Status for a Category

Query the current consent status for any of the Categories included in your application. This can be used to determine what privacy action is needed at app launch or anytime the consent status is needed. Simply pass in the Category ID (eg. C0001) and the method will return the current consent status.

Here are the default values as set by OneTrust:

Category NameCategory ID
Strictly NecessaryC0001
PerformanceC0002
FunctionalC0003
TargetingC0004
Social MediaC0005

This will give you the data from all the categories at once instead of a single or specific category.

oneTrustTV.getPurposeConsentStatus(undefined,(e,s)=>console.log(s))

You can query using this parameter to get the data from a specific category using a group ID.

oneTrustTV.getPurposeConsentStatus("C0004",(e,s)=>console.log(s))

You can query using this parameter to get the data from multiple categories using multiple group IDs.

oneTrustTV.getPurposeConsentStatus(["C0004","C0002"],(e,s)=>console.log(s))

e = error

s = success

Returns

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

Interaction Events

When a User interacts with the OT SDK UI, the SDK sends an interaction event that the application can listen for.

function watch() {
  const observable = oneTrustTV.eventListener(); 
  observable.subscribe(console.log); 
} 

watch();

See the list of events available below.

Recommended Approach

Utilize interaction events to determine when you need to query for and action on consent.

function watch() {
  const observable = oneTrustTV.eventListener(); 
  observable.subscribe(e => {oneTrustTV.getPurposeConsentStatus(undefined,(e,s)=>console.log(s))}); 
} 

watch();

Listening for UI Interaction Events

Note: UI Interaction Events are only relevant if the app is using the out of the box OneTrust UI. If you have built your own UI, disregard this section.

When a user interacts with the CMP UI, the SDK sends an interaction event that the application can listen for and action on.

Use Case : The app needs to trigger certain actions based on interaction with the UI.

Example : User selects the "Confirm My Choices" button on the OT Preference Center UI, which saves their consent choices. An app might want to listen for the onPreferenceCenterConfirmChoices to show a success message to the user and navigate them to the app's home page.

Types of Events

EventDescription
onHideBannerTriggered when banner is closed
onShowBannerTriggered when banner is shown
onBannerClickedRejectAllTriggered when user rejects all consent from banner
onBannerClickedAcceptAllTriggered when user allows all consent from banner
onShowPreferenceCenterTriggered when Preference Center is displayed
onHidePreferenceCenterTriggered when Preference Center is closed
onPreferenceCenterRejectAllTriggered when user rejects all consent from Preference Center
onPreferenceCenterAcceptAllTriggered when user allows all consent from Preference Center
onPreferenceCenterConfirmChoicesTriggered when user clicked on save choices after updating consent values from Preference Center
onPreferenceCenterPurposeLegitimateInterestChangedTriggered when IAB purpose's legitimate interest value changes
onPreferenceCenterPurposeConsentChangedTriggered when user updates consent values for a particular category on Preference Center UI
onShowVendorListTriggered when the vendor list UI is shown
onHideVendorListTriggered when vendor list UI is closed or when back button is tapped.
onVendorListVendorConsentChangedTriggered when user updates consent values for a particular vendor ID on vendor list UI
onVendorListVendorLegitimateInterestChangedTriggered when user updates Legitimate interests values for a particular vendor ID on vendor list UI