When Consent Changes

Overview

When a user interacts with the CMP UI and updates their consent choices, the application needs to become aware so that 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 GPP String to 3rd Party SDKs
  • Routing the user to another location in the app
  • Displaying toast messages to the user
  • Logging updates to internal APIs
  • etc...

Recommended Approach for Consent Handling

OneTrust recommends you set up an observer for the OTConsentUpdated event to determine when a UI has been dismissed and query for consent to determine your next set of actions.

OTConsentUpdated

This is a generic event that's triggered any time a OneTrust UI is dismissed. Your app can set an observer for this to query for consent status and trigger appropriate next steps.

m.global.OTsdk.eventlistener.observeField("OTConsentUpdated","onOTConsentUpdated")
function onOTConsentUpdated(event)
    event = event.getData()
    if event <> invalid and event.response <> invalid and event.response
         sdkStatus = m.global.OTsdk.callFunc("getConsentStatusForGroupID","C0004")
         print "sdkStatus -> " sdkStatus
         ' perform next steps
    else
        ' error handling
    end if  
end function

If you'd like to have more information regarding the response returned by the events, you can retrieve the event data. Sample code below.

function eventlistener(event) as object
    event = event.getData()
    if type(event) = "roAssociativeArray" and event <> invalid and event.name <> invalid 'cmp eventlisteners
        if event.name = "dataDownloadSucess" or event.name = "OTConsentUpdated"
            print m.message + event.name + " eventlistener value = " event.response
        else
            print m.message + event.name + " eventlistener value = " FormatJson(event)
        end if
    end if
end function

Querying for Consent

You can query for consent on a category or SDK level.

Querying Consent Status for a Category

You can query for the current consent status of any category used by your app. This can be used to determine what privacy action is needed at app launch or anytime the consent status is needed without being notified by an event. Pass in the Category ID (eg. C0004) and the SDK will return the current consent status (integer value).

Value Returned

  • 1 = Consent is given.
  • 0 = Consent is not given.
  • -1 = Consent has not been collected (The SDK is not yet initialized OR there are no SDKs associated to this category).
m.global.OTsdk.callFunc("getConsentStatusForGroupID","C0001")
m.global.OTsdk.callFunc("getConsentStatusForGroupID","C0002")
m.global.OTsdk.callFunc("getConsentStatusForGroupID","C0003")
m.global.OTsdk.callFunc("getConsentStatusForGroupID","C0004")
m.global.OTsdk.callFunc("getConsentStatusForGroupID","C0005")

Parameters

  • Query type: Group or SDK level query type
  • Group ID: ID of the category to be queried. It can be found in the OneTrust tenant under CTV App Consent > Categorizations > Categories

🚧

There must be at least one SDK categorized to a category in order for it to appear on the CMP UI and for consent to be written for it. For example, if there are no SDKs categorized as 'Targeting', this category will not appear on the UI and no consents will be available for it (will return a -1 if queried).

Querying Consent Status for a specific SDK

Query the current consent status for any of the SDKs included in your application. This can be used to determine what privacy action is needed at application launch or anytime the consent status is needed without being notified by an event broadcast. Pass in the SDK ID and the method will return the current consent status (integer value).

Value Returned

  • 1 = Consent is given.
  • 0 = Consent is not given.
  • -1 = Consent has not been collected (The SDK is not initialized or there are no SDKs associated to this category).
m.global.OTsdk.callFunc("getConsentStatusForSDKId", "018dcc15-9f1b-7329-88bc-db0d09d28eb4")

Parameters

  • Query type: Group or SDK level query type
  • SDK ID: This is the ID of the SDK assigned to your app. It can be found under CTV Consent > SDKs > Your app > Instructions.

Querying Consent for Vendors

If your app uses IAB Vendors or Google Vendors, you can query for the consent status on a vendor level.

m.global.OTsdk.callFunc("getConsentStatusForVendorId", "vendorListType", "vendorID") returns a JSON containing all information regarding a vendor list you specify. Example code below.

Value Returned

  • 2 = Vendor mapped to an always active category (e.g. Strictly Necessary).
  • 1 = Consent is given.
  • 0 = Consent is not given.

Parameters

The method takes in three parameters:

  • Query type
  • OTVendorListMode (type of vendor list to retrieve)
    • google: returns a list of Google vendors.
    • iab: returns a list of IAB vendors.
  • vendorID

IAB Vendor

m.global.OTsdk.callFunc("getConsentStatusForVendorId", "iab", "755")

Google Vendor

m.global.OTsdk.callFunc("getConsentStatusForVendorId", "google", "8")

📘

Vendor IDs can be found in CTV Consent > Vendors

Recommended Approaches for Vendor Consent

When querying for vendor consent, we recommend setting an observer to listen for the OTConsentUpdated event. In the callback, query for desired vendor consent.

Listening for UI Interaction Events

🚧

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.

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 toast message to the user and navigate them to the App's home page.

Types of Events

EventDescription
onShowBannerTriggered when banner is shown.
onHideBannerTriggered when banner is closed.
onBannerClickedAcceptAllTriggered when user allows all consent from banner.
onBannerClickedRejectAllTriggered when user rejects all consent from banner.
onBannerClickedCloseTriggered when user closes from banner.
onShowPreferenceCenterTriggered when preference center is displayed.
onHidePreferenceCenterTriggered when preference center is closed.
onPreferenceCenterAcceptAllTriggered when user allows all consent from preference center.
onPreferenceCenterRejectAllTriggered when user rejects all consent from preference center.
onPreferenceCenterConfirmChoicesTriggered when user clicked on save choices after updating consent values from preference center.
onPreferenceCenterCloseTriggered when user closes from preference center.
onShowVendorListTriggered when vendor list UI is displayed from an IAB banner / IAB preference center.
onHideVendorListTriggered when vendor list UI is closed or when back button is clicked.
onVendorListAcceptAllTriggered when user allows all consent from vendor list.
onVendorListRejectAllTriggered when user rejects all consent from vendor list.
onVendorConfirmChoicesTriggered when user updates vendor consent / legitimate interests purpose values and save the choices from vendor list.
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.
onPreferenceCenterPurposeConsentChangedTriggered when user updates consent values for a particular category on preference center UI.
onPreferenceCenterPurposeLegitimateInterestChangedTriggered when user updates legitimate interest values for a particular category on preference center UI.
onShowSDKListTriggered when the SDK List UI is displayed.
onHideSDKListTriggered when the SDK List UI is closed or when back button is clicked.
onSDKListConfirmChoicesTriggered when user updates SDK consent and save the choices from SDK List.
onSDKListAcceptAllTriggered when user allows all consent from SDK List.
onSDKListRejectAllTriggered when user rejects all consent from SDK List.
onSdkListSdkConsentChangesTriggered when user opts in / out of an SDK on the SDK List view.
allSDKViewsDismissedTriggered when all the OT SDK Views are dismissed from the view hierarchy.

Setting it up

Set these UI interaction events before calling startSDK().

m.global.OTsdk.eventlistener.observeField("onShowBanner", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onHideBanner", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onBannerClickedAcceptAll", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onBannerClickedRejectAll", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onBannerClickedClose", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onShowPreferenceCenter", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onHidePreferenceCenter", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onPreferenceCenterAcceptAll", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onPreferenceCenterRejectAll", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onPreferenceCenterConfirmChoices", "eventlistener") m.global.OTsdk.eventlistener.observeField("onPreferenceCenterPurposeConsentChanged", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onPreferenceCenterPurposeLegitimateInterestChanged", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onShowVendorList", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onHideVendorList", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onVendorListAcceptAll", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onVendorListRejectAll", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onVendorConfirmChoices", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onVendorListVendorConsentChanged", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onVendorListVendorLegitimateInterestChanged", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onShowSDKList", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onHideSDKList", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onSDKListAcceptAll", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onSDKListRejectAll", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onSDKListConfirmChoices", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onSdkListSdkConsentChanged", "eventlistener")
m.global.OTsdk.eventlistener.observeField("allSDKViewsDismissed", "eventlistener")
m.global.OTsdk.eventlistener.observeField("OTConsentUpdated", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onSwitchUserProfileCallback", "eventlistener")
m.global.OTsdk.eventlistener.observeField("onDeleteProfileCallback", "eventlistener")
m.global.OTsdk.eventlistener.observeField("dataDownloadSucess", "eventlistener")

m.global.OTsdk.callFunc("startSDK", sdkParams)


function eventlistener(event) as object
    event = event.getData()
    if type(event) = "roAssociativeArray" and event <> invalid and event.name <> invalid 'cmp eventlisteners
        if event.name = "dataDownloadSucess" or event.name = "OTConsentUpdated"
            print m.message + event.name + " eventlistener value = " event.response
        else
            print m.message + event.name + " eventlistener value = " FormatJson(event)
        end if
    end if
end function