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 ISO 639-1 language 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 |
|---|---|
- |
|
closeCmp
Programmatic way to close the CMP
window.__ucCmp.closeCmp()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 |
|---|---|
- |
|
getCmpConfig
Programmatic way to get the current CMP configuration
window.__ucCmp.getCmpConfig()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 |
|---|---|
- |
|
getServicesBaseInfo
Programmatic way to get the base information (id, name, category, etc.) of all services configured in the CMP
window.__ucCmp.getServicesBaseInfo()Input | Return Type |
|---|---|
- |
|
isAgeVerificationEnabled
Programmatic way to check if age verification is configured and enabled, regardless of completion state
window.__ucCmp.isAgeVerificationEnabled()Input | Return Type |
|---|---|
- |
|
isAgeVerificationRequired
Programmatic way to check if age verification is required and not yet completed. When true, calling showFirstLayer() will display the age verification wall instead of the CMP first layer
window.__ucCmp.isAgeVerificationRequired()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 |
|---|---|
- |
|
refreshScripts
Programmatic way to recheck the unblocking of scripts, e.g. for Single Page Applications that add script tags dynamically
window.__ucCmp.refreshScripts()Input | Return Type |
|---|---|
- |
|
saveConsents
Saves the consents after being updated.
GDPR compliance
The
typeparameter distinguishes betweenEXPLICITconsent (an active, affirmative user action, e.g. clicking "Accept" or "Save") andIMPLICITconsent (inferred, e.g. from a prior GPC signal or a default state). Under the GDPR, valid consent must be freely given, specific, informed, and unambiguous — which in practice means it must result from an explicit user action. Passing the correcttypeensures the consent record accurately reflects how consent was obtained, which matters for compliance and audit purposes.
window.__ucCmp.saveConsents(type)Input | Input Type | Return Type |
|---|---|---|
type |
|
|
showFirstLayer
Programmatic way to show the first layer of the CMP. If age verification is required and not yet completed, the age verification wall will be shown instead. After the user approves age verification, subsequent calls will show the normal first layer
window.__ucCmp.showFirstLayer()Input | Return Type |
|---|---|
- |
|
showSecondLayer
Programmatic way to show the second layer of the CMP, optionally scrolled to a specific tab
window.__ucCmp.showSecondLayer(activeTab)Input | Input Type | Return Type |
|---|---|---|
activeTab | TabView | SecondLayerTabView (optional) |
|
showServiceDetails
Programmatic way to show the details of a service
window.__ucCmp.showServiceDetails(serviceId)Input | Input Type | Return Type |
|---|---|---|
serviceId | string |
|
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 servicesConsents = [
{id: 'HkocEodjb7', consent: true}, // Google Analytics
{id: 'S1_9Vsuj-Q', consent: false}, // Google Ads
]
await __ucCmp.updateServicesConsents(servicesConsents);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 |
|
updateTheme
Programmatic way to update the CMP theme
window.__ucCmp.updateTheme(themeData)Input | Input Type | Return Type |
|---|---|---|
themeData | ThemeData |
|
hydrateEmbeddings
Programmatic way to rerender the Embeddings content.
This is particularly useful for Single Page Application (SPA) solutions.
window.__ucCmp.hydrateEmbeddings()Input | Return Type |
|---|---|
- |
|