Zum Inhalt

Javascript APIs

CCM19 offers several Javascript APIs that can be used to access Cookie Manager functionalities and respond to user interactions.

Global object

The direct control options of CCM19 are bundled in the global Javascript object CCM:

Variable/method Type Description
CCM.acceptedCookies string[] List of the names of all accepted cookies.
CCM.acceptedEmbeddings [ { id: string, name: string, } , ... ] List of all accepted embeddings. (as of version 2020.10.28)
CCM.availableLocales() string[] List of active languages - e.g. ['de_DE', 'en_US'] (from version 2022.03.24)
CCM.closeControlPanel() Closes the dialog for selecting the purposes to be accepted.
CCM.closeWidget() Closes the cookie dialog.
CCM.consent boolean Indicates whether the site visitor has defined and saved their consent settings. This can also mean that everything has been rejected.
CCM.crossDomainConsentString string Fragment identifier for manually composing a URL for Consent sharing. (as of version 2020.10.14)
CCM.fullConsentGiven boolean Indicates whether the page visitor has consented to all options. A positive result implies the same for CCM.consent. (after version 2023.03.29)
CCM.navigate(url[, replace[, navigateTop]]) Navigates to a different URL (like location.href = url), but takes the consent split into account. replace controls whether location.replace is used and navigateTop controls whether the complete page is navigated in frames. (from version 2020.10.14)
CCM.openControlPanel() Opens the dialog for selecting the purposes to be accepted.
CCM.openWidget() Opens the cookie dialog again.
CCM.switchLocale(localeName) Switches the language - see CCM.availableLocales()(from version 2022.03.24)
CCM.ucid ?string The unique consent ID, or zero if no Consent has been issued.
CCM.version string Contains the current CCM19 version. (from version 2020.10.28)

Alternatively, the dialogs can also be controlled via links with the targets #CCM.openWidget, #CCM.closeWidget, #CCM.openControlPanel and #CCM.closeControlPanel.

Extension for ad-free and tracking-free networks

If the option "My website is part of an ad-free and tracking-free network " is active in the Developer settings > Frontend behavior area of the domain, the following endpoints are defined and can be used in the frontend.

The following endpoints were published with version 2023.03.20 and are not available in older versions.

Variable/method Type Description
CCM.denyAllPrivileges() Function Alias for CCM.revokeAllPrivileges().
CCM.grantAllPrivileges() Function Allow all categories, bindings, TCF providers, etc. This function assumes that full consent has been signaled by the site visitor. Depending on CCM.requiresConsentUpdate, renewed consent may be required. Please call only once per user interaction, not repeatedly per page view.Since version 2023.07.17, the event ccm19WidgetClosed is also triggered.
CCM.revokeAllPrivileges() Function Reject all categories, bindings, TCF providers, etc. This function assumes that this has been signaled by the site visitor. Technically necessary bindings are still loaded. Please call only once per user interaction, not repeatedly per page view.Since version 2023.07.17, the event ccm19WidgetClosed is also triggered.
CCM.requiresConsentUpdate boolean Signals that CCM19 expects an update of the consent settings. This means that either - no Consent has yet been configured (first page visit) or - something legally relevant has changed in the CCM19 configuration or - the specified validity period has expired. This value should be checked and taken into account each time the page is accessed.In the above cases, the event ccm19WidgetOpened is also triggered since version 2023.07.17.
CCM.embeddings Object[] Returns an array of all embeddings and makes the textual content available for further use. Translations for all languages that are active for the frontend are provided for both the embeddings and their assets (cookies). - CCM.embeddings[].name - CCM.embeddings[].vendor - CCM.embeddings[].l10n.de_DE - CCM.embeddings[].l10n.en_US - CCM.embeddings[].l10n._ - CCM.embeddings[].assets[].name - CCM.embeddings[].assets[].type - CCM.embeddings[].assets[].l10n With l10n._, the language entries of the fallback language (defined for each customer account) are available for retrieval in addition to the active locales. As not every CMP configuration provides the same languages for the banner, a generally available entry is available; however, the language of the entries depends on the configuration. (after version 2024.03.13)
CCM.tcf.customVendors string[] Contains all vendors that are defined in CCM19 integrations but are not TCF vendors. (from version 2023.06.01)
CCM.tcf.enabled boolean Indicates whether support for the IAB framework is active.
CCM.tcf.stacks int[] Contains the TCF stacks that represent the given CCM19 configuration of a website. (from version 2023.06.01)
CCM.tcf.vendors Object[] In addition to the vendor ID, each object also contains the purposes used. With CCM.tcf.vendors.map(x => x.id) the IDs of all active vendors can be read out. Until version 2023.05.25, this property was still implemented as an object instead of an array; the adjustment was made in consultation with the first user of this feature.

As the above interfaces are only available if the corresponding option for ad-free and tracking-free networks is active, the network operator should check the availability in their code to prevent access to undefined properties. The own code should therefore be bracketed as follows, for example.

if (typeof window.CCM == 'object' && typeof window.CCM.denyAllPrivileges == 'function') {
    // option "My website is part of an ad-free and tracking-free network" is active
    // and the properties can be accessed.
}
else {
    console.log('Please activate option in CCM19.');
}

Javascript events

Some events in CCM19 are mapped to CustomEvents on the window object and can be reacted to with window.addEventListener(...).

Event detail property Description
ccm19CookieAccepted { name: string, code: string, purpose: string, mandatory: boolean, } A cookie was accepted by the user. This event is triggered for each cookie that is listed in the accepted purposes; these events occur when the visitor grants consent and are repeated on each subsequent page visit when the page is loaded. Obsolete: Please change to*ccm19EmbeddingAccepted.*
ccm19EmbeddingAccepted { name: string, code: string, purpose: string, mandatory: boolean, } An embedding was accepted by the user. These events occur when the visitor grants consent and are repeated for each page view. (from version 2020.10.28)
ccm19WidgetClosed null Is triggered as soon as the last visible CCM19 widget element is closed. This can be the result of a click on a save button that leads to the widget being closed.
ccm19WidgetOpened null Is triggered as soon as the first CCM19 widget element is displayed. This can be the initial opening when the page is called up or an interaction at a later time, e.g. via the settings icon.
ccm19WidgetLoaded null Is triggered as soon as CCM19 has been initialized.