Execute JavaScript code and determining the consent signal

UniConsent CMP v2 API

  • openunic

Display UniConsent CMP to users.

Copied
__unicapi('openunic')
  • agreeAll

The user agreed to all the consent options. You can implement your programmatic first layer of the CMP and trigger the agreeAll event once the user clicked "Agree All" button at your programmatic first layer UI.

Copied
__unicapi('agreeAll')
  • openOptions

Open the second layer UI. This can be used if you like to customise the first layer and programmatic open the consent manager.

Copied
__unicapi('openOptions')
  • openVendorList

Open the vendor list UI. This can be used if you like to customise the first layer and programmatic open the consent manager.

Copied
__unicapi('openVendorList')
  • getUConsent

Get the consent signal of your custom vendors.

Copied
__unicapi(
'getUConsent',
2,
(uConsent, success) => {
if (success) {
// do something with tcData
} else {
// do something else
}
},
[1, 2, 3]
) // vendors Ids
  • getUCData

Get the consent signal data of your custom vendors.

Copied
__unicapi(
'getUCData',
2,
(ucData, success) => {
if (success) {
// do something with tcData
} else {
// do something else
}
},
[1, 2, 3]
) // vendors Ids
  • getTCData
Copied
__tcfapi(
'getTCData',
2,
(tcData, success) => {
if (success) {
// do something with tcData
} else {
// do something else
}
},
[1, 2, 3]
) // vendors Ids
  • ping
Copied
__tcfapi('ping', 2, (pingReturn) => {
// do something with pingReturn
})
  • addEventListener
Copied
const callback = (tcData, success) => {
if (success && tcData.eventStatus === 'tcloaded') {
// do something with tcData.tcString
// remove the ourself to not get called more than once
__tcfapi(
'removeEventListener',
2,
(success) => {
if (success) {
// oh good...
}
},
tcData.listenerId
)
} else {
// do something else
}
}
__tcfapi('addEventListener', 2, callback)
  • getVendorList
Copied
__tcfapi(
'getVendorList',
2,
(gvl, success) => {
if (success) {
// do something with gvl
} else {
// do something else
}
},
'LATEST'
)

You can find all the API at: IAB TCF Document.

U.S. Privacy User Signal Mechanism "USP API" (CCPA Compliance Mechanism)

Example:

Copied
__uspapi('getUSPData', 1, (uspData, success) => {
if (success) {
// do something with uspData
} else {
// do something else
}
})

Response uspData:

Copied
{
"version": 1, /* number indicating the U.S. Privacy spec version */
"uspString": "1YN" /* string; not applicable: "1--" */ /* number; 1 applies, 0 doesn't apply, -1 not set */
}

Make sure your ad stack get the consent from users before kicking off.

Example:

Copied
__tcfapi('addEventListener', 2, function (tcData, success) {
if (success && tcData.unicLoad === true) {
if (!window._initAds) {
window._initAds = true
// your code to kick off the ads
console.log('_initAds started.')
}
}
})

Example:

Copied
;(function waitCMP() {
var readyCMP
if (!readyCMP && window['dataLayer']) {
window['dataLayer'].forEach(function (event) {
if (event['event'] === 'unic_data') {
readyCMP = 1
console.log(event)
// your other codes;
}
})
}
if (!readyCMP) {
setTimeout(waitCMP, 100)
}
})()