Display UniConsent CMP to users.
__unicapi('openunic')
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.
__unicapi('agreeAll')
Open the second layer UI. This can be used if you like to customise the first layer and programmatic open the consent manager.
__unicapi('openOptions')
Open the vendor list UI. This can be used if you like to customise the first layer and programmatic open the consent manager.
__unicapi('openVendorList')
Get the consent signal of your custom vendors.
__unicapi(
'getUConsent',
2,
(uConsent, success) => {
if (success) {
// do something with tcData
} else {
// do something else
}
},
[1, 2, 3]
) // vendors Ids
Get the consent signal data of your custom vendors.
__unicapi(
'getUCData',
2,
(ucData, success) => {
if (success) {
// do something with tcData
} else {
// do something else
}
},
[1, 2, 3]
) // vendors Ids
Get the auditing consent ID for user's consent status.
__unicapi('getConsentId', 2, (consentId) => {
console.log(consentId);
});
// or
UnicI.getConsentId();
The auditing consent ID can also be retrieved from the user's local storage __unic
-> __unid
.
__tcfapi(
'getTCData',
2,
(tcData, success) => {
if (success) {
// do something with tcData
} else {
// do something else
}
},
[1, 2, 3]
) // vendors Ids
__tcfapi('ping', 2, (pingReturn) => {
// do something with pingReturn
})
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)
__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.
Example:
__uspapi('getUSPData', 1, (uspData, success) => {
if (success) {
// do something with uspData
} else {
// do something else
}
})
Response uspData:
{
"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:
__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:
;(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)
}
})()
Contact us: support@uniconsent.com