Control Functionality
Introduction¶
The following methods can be accessed on the following object that the CMP registers on the window object in the browser:
window.__ucCmp
acceptAllConsents¶
Programmatic way to accept all consents
window.__ucCmp.acceptAllConsents()
| Input | Return Type |
|---|---|
| - | Promise<void> |
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 | Promise<void> |
clearUserSession¶
Programmatic way to clear the CMP localStorage entries
window.__ucCmp.clearUserSession()
| Input | Return Type |
|---|---|
| - | Promise<void> |
closeCmp¶
Programmatic way to close the CMP
window.__ucCmp.closeCmp()
| Input | Return Type |
|---|---|
| - | Promise<void> |
denyAllConsents¶
Programmatic way to deny all consents
window.__ucCmp.denyAllConsents()
| Input | Return Type |
|---|---|
| - | Promise<void> |
getActiveLanguage¶
Programmatic way to get the currently selected language in the CMP
window.__ucCmp.getActiveLanguage()
| Input | Return Type |
|---|---|
| - | Promise<string> |
getCmpConfig¶
Programmatic way to get the current CMP configuration
window.__ucCmp.getCmpConfig()
| Input | Return Type |
|---|---|
| - | Promise<Record<string, object>> |
getConsentDetails¶
Retrieves all the Consent Details
window.__ucCmp.getConsentDetails()
| Input | Return Type |
|---|---|
| - | Promise<ConsentDetails> |
getControllerId¶
Programmatic way to get the Controller ID
window.__ucCmp.getControllerId()
| Input | Return Type |
|---|---|
| - | Promise<string> |
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 |
|---|---|
| - | Promise<BaseService[]> |
isAgeVerificationEnabled¶
Programmatic way to check if age verification is configured and enabled, regardless of completion state
window.__ucCmp.isAgeVerificationEnabled()
| Input | Return Type |
|---|---|
| - | Promise<boolean> |
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 |
|---|---|
| - | Promise<boolean> |
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 |
|---|---|
| - | Promise<boolean> |
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 |
|---|---|
| - | Promise<boolean> |
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 |
|---|---|
| - | Promise<string[]> |
saveConsents¶
Saves the consents after being updated.
GDPR compliance
The type parameter distinguishes between EXPLICIT consent (an active, affirmative user action, e.g. clicking "Accept" or "Save") and IMPLICIT consent (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 correct type ensures 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 | 'EXPLICIT' | 'IMPLICIT' (optional, defaults to 'EXPLICIT') | Promise<void> |
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 |
|---|---|
| - | Promise<void> |
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) | Promise<void> |
showServiceDetails¶
Programmatic way to show the details of a service
window.__ucCmp.showServiceDetails(serviceId)
| Input | Input Type | Return Type |
|---|---|---|
| serviceId | string | Promise<void> |
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 | Promise<void> |
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 | Promise<void> |
updateTcfConsents¶
Programmatic way to update TCF consents
window.__ucCmp.updateTcfConsents(tcfConsents)
| Input | Input Type | Return Type |
|---|---|---|
| tcfConsents | TCFConsents | Promise<void> |
updateTheme¶
Programmatic way to update the CMP theme
window.__ucCmp.updateTheme(themeData)
| Input | Input Type | Return Type |
|---|---|---|
| themeData | ThemeData | Promise<void> |
hydrateEmbeddings¶
Programmatic way to rerender the Embeddings content.
This is particularly useful for Single Page Application (SPA) solutions.
window.__ucCmp.hydrateEmbeddings()
| Input | Return Type |
|---|---|
| - | Promise<void> |