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.
JSON.parse(localStorage.ONETRUST_WEB_STORE)[0].CONSENT
- Right click the response and select "Store string as global variable"
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 Name | Category ID |
---|---|
Strictly Necessary | C0001 |
Performance | C0002 |
Functional | C0003 |
Targeting | C0004 |
Social Media | C0005 |
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
Event | Description |
---|---|
onHideBanner | Triggered when banner is closed |
onShowBanner | Triggered when banner is shown |
onBannerClickedRejectAll | Triggered when user rejects all consent from banner |
onBannerClickedAcceptAll | Triggered when user allows all consent from banner |
onShowPreferenceCenter | Triggered when Preference Center is displayed |
onHidePreferenceCenter | Triggered when Preference Center is closed |
onPreferenceCenterRejectAll | Triggered when user rejects all consent from Preference Center |
onPreferenceCenterAcceptAll | Triggered when user allows all consent from Preference Center |
onPreferenceCenterConfirmChoices | Triggered when user clicked on save choices after updating consent values from Preference Center |
onPreferenceCenterPurposeLegitimateInterestChanged | Triggered when IAB purpose's legitimate interest value changes |
onPreferenceCenterPurposeConsentChanged | Triggered when user updates consent values for a particular category on Preference Center UI |
onShowVendorList | Triggered when the vendor list UI is shown |
onHideVendorList | Triggered when vendor list UI is closed or when back button is tapped. |
onVendorListVendorConsentChanged | Triggered when user updates consent values for a particular vendor ID on vendor list UI |
onVendorListVendorLegitimateInterestChanged | Triggered when user updates Legitimate interests values for a particular vendor ID on vendor list UI |
Updated 5 months ago