API Reference

Active Methods

Get Application JSON Data

This method returns the app data JSON response as a promise. The first parameter will be your oneTrustTV.Settings() configuration and the second parameter will be a boolean indicating whether or not the shouldShowBanner() or isBannerShown() values should be reset. This should always be set to false.

const configs =  {
  key: '',
  languageCode: '',
  version: '',
  storageLocation: '',
  countryCodeOverride: '', //optional
  regionCodeOverride: '', //optional
  redirect: '' //optional if app is an SPA
}

const appData = oneTrustTV.Api(configs,false)
appData.then(response => console.log(response.response)).catch(e => console.log(e))

Sample response:

Get Redirect Path

This method returns the redirect path when the CMP UI is dismissed. Only applicable for multi page apps.

oneTrustTV.GetRedirectPath()

Get Root Element

This method returns the root element for the CMP UI.

oneTrustTV.GetRootElement()

Set Key Settings

This method sets the values needed for initialization but does not download any data.

oneTrustTV.Settings({
  key: '',
  languageCode: '',
  version: '',
  storageLocation: '',
  countryCodeOverride: '', //optional
  regionCodeOverride: '', //optional
  redirect: '' //optional if app is an SPA
});

Get Data Subject ID

This method returns the current data subject ID.

oneTrustTV.anonymousDsid(cb => console.log(cb))

UI Event Listeners

This method subscribes you to OneTrust UI events.

otEventListeners = oneTrustTV.eventListener().subscribe((msg) => {
  console.log(msg)
})
otEventListers.unsubscribe()

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

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

Get Purpose Consent

This method returns the consent status of a category.

oneTrustTV.getPurposeConsentStatus('categoryID', (err, suc)=> console.log(err, suc))

Examples:

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.)

Is Banner Shown

This method determines whether or not the banner UI has been shown.

oneTrustTV.isBannerShown((cb)=> console.log(cb.status))

Returns

  • 1 = Banner UI is/has been shown
  • -1 = Banner UI has not been shown

SDK logging

This method returns logging information based on SDK activity. Stored under ONETRUST_LOGGER in local storage. Logging is disabled by default.

Enables the log.

oneTrustTV.logger("enable",(e,s)=>console.log(e,s))

Clears the log.

oneTrustTV.logger("clear",(e,s)=>console.log(e,s))

Disables the log.

oneTrustTV.logger('disable', (e,s) => console.log(e,s));

Save consent

This method saves the user's consent to local storage and sends a consent receipt to OneTrust servers (if enabled).

oneTrustTV.saveConsent('banner', (e,s)=> console.log(e,s))

Parameters

  • Interaction Type
  • Callback
Interaction Types (String)
Banner - Allow All
Banner - Reject All
Banner - Close
Preference Center - Allow All
Preference Center - Reject All
Preference Center - Confirm

Set Remote Key Codes

This method allows you to set the remote key mappings based on TV platform (LG, Samsung, etc.).

oneTrustTV.setRemoteKeycodes({
  '214': 'left',
  '205': 'left',
  '213': 'right',
  '206': 'right',
  '212': 'down',
  '204': 'down',
  '211': 'up',
  '203': 'up',
  '195': 'ok',
  '196': 'back'
}, false); 

Parameters

  • Remote keycode JSON (keycode: keyname)
  • (Optional) boolean - enable/disable mouse functionality

Multi Profile Consent

Rename Profile

This methods renames the current profile ID with a new one.

oneTrustTV.renameProfile('old user id', 'new user id', cb=> console.log(cb))

Parameters:

  • Current/Old ID
  • New ID
  • Callback

Delete Profile

This method deletes profiles if multi profiles have been set up.

oneTrustTV.deleteProfile('null', cb => console.log(cb))

When null is passed in the first parameter, the first profile is deleted. You can also specify the ID of the profile to be deleted.

Switch Profile

oneTrustTV.switchProfile(document.getElementById('root'), 'identifier', false, false, (closecb) => console.log(closecb))
ParameterDescription
getElementByIdReference to the div where the UI will be be shown.
New profileProfile name to switch to
Use local dataBoolean. If true, new profile will use locally cached data
Data re-downloadBoolean. If true, cached data will be cleared and data will be redownloaded
CallbackCallback

Programmatically Update Purpose Consent

This method allows you to update consent for a specific purpose/category.

oneTrustTV.updatePurposeConsent('STACK42', true, cb=> console.log(cb))

oneTrustTV.updatePurposeConsent('C0002', true, cb=> console.log(cb))

oneTrustTV.updatePurposeConsent('C0004', false, cb=> console.log(cb))

Parameter

  • Purpose/Category ID
  • Boolean (on or off)

Programmatically Update Legitimate Interest Consent

This method allows you to update the legitimate interest consent for a specific IAB purpose.

oneTrustTV.updatePurposeLegitInterest('IAB2V2_2', true, cb=> console.log(cb))
oneTrustTV.updatePurposeLegitInterest('IAB2V2_4', false, cb=> console.log(cb))

Parameter

  • Purpose ID
  • Boolean (on or off)

To Be Deprecated

Get Header Configs

This method returns header configs.

oneTrustTV.GetHeaderConfigs()

Sample response:

Get Profile Sync Auth Token

This method returns the JWT used for cross device.

oneTrustTV.GetSyncProfileAuth()

Set Data Subject ID

This method sets the data subject ID.

oneTrustTV.SetDataSubjectIdConfigs("test")

Get Vendor Count

This method returns the number of vendors for IAB TCF purposes.

oneTrustTV.getVendorCount('IAB2V2_1', (cb) => console.log(cb))
oneTrustTV.getVendorCount('V2STACK42', (cb) => console.log(cb))

Multi-Profile

This method checks whether the multi profile feature has been enabled in the current template.

oneTrustTV.isMultiProfileAllowed(cb => console.log(cb))

Switch User Profile

This method switches user profiles if multiple exists (multi profile only).

oneTrustTV.switchUserProfile('identifier')