Introduction
The following methods can be accessed on the following object that the CMP registers on the window object in the browser:
window.__ucCmpacceptAllConsents
Programmatic way to accept all consents
window.__ucCmp.acceptAllConsents()Input | Return Type |
|---|---|
- |
|
changeLanguage
Programmatic way to change the language in the CMP
Two character country code, e.g. "en" = set language to English
window.__ucCmp.changeLanguage(language)Input | Input Type | Return Type |
|---|---|---|
language | string |
|
clearUserSession
Programmatic way to clear the CMP localStorage entries
window.__ucCmp.clearUserSession()Input | Return Type |
|---|---|
- |
|
denyAllConsents
Programmatic way to deny all consents
window.__ucCmp.denyAllConsents()Input | Return Type |
|---|---|
- |
|
getActiveLanguage
Programmatic way to get the currently selected language in the CMP
window.__ucCmp.getActiveLanguage()Input | Return Type |
|---|---|
- |
|
getConsentDetails
Retrieves all the Consent Details
window.__ucCmp.getConsentDetails()Input | Return Type |
|---|---|
- |
|
getControllerId
Programmatic way to get the Controller ID
window.__ucCmp.getControllerId()Input | Return Type |
|---|---|
- |
|
isConsentRequired
Programmatic way to check if consent is required (no consent given or resurface). Return value is only available after UI has initialized.
function customConsentHandler(consentIsRequired) {
console.log('consentIsRequired', consentIsRequired);
}
if (!window.__ucCmp || !__ucCmp.isInitialized()) {
window.addEventListener('UC_UI_INITIALIZED', function() {
customConsentHandler(__ucCmp.isConsentRequired());
});
} else {
const isConsentRequired = await __ucCmp.isConsentRequired()
customConsentHandler(isConsentRequired);
}Input | Return Type |
|---|---|
- |
|
isInitialized
Programmatic way to check if the app is initialized
const isInitialized = await window.__ucCmp.isInitialized()
if (isInitialized) {
console.log('CMP is already initialized');
} Input | Return Type |
|---|---|
- |
|
saveConsents
Saves the consents after being updated.
window.__ucCmp.saveConsents()Input | Return Type |
|---|---|
- |
|
updateCategoriesConsents
Updates consents for whole categories of services
const categoriesConsents = [
{id: 'marketing', consent: true}, // Marketing Category
{id: 'functional', consent: false}, // Functional Category
]
window.__ucCmp.updateCategoriesConsents(categoriesConsents)Input | Input Type | Return Type |
|---|---|---|
categoriesConsents | CategoriesConsents |
|
updateServicesConsents
Updates consents for individual or multiple services
const serviceConsents = [
{id: 'HkocEodjb7', consent: true}, // Google Analytics
{id: 'S1_9Vsuj-Q', consent: false}, // Google Ads
]
await __ucCmp.updateServicesConsents(serviceConsents);Input | Input Type | Return Type |
|---|---|---|
servicesConsents | ServicesConsents |
|
updateTcfConsents
Programmatic way to update TCF consents
window.__ucCmp.updateTcfConsents(tcfConsents)Input | Input Type | Return Type |
|---|---|---|
tcfConsents | TCFConsents |
|