Skip to main content

JavaScript API

Interact with our CMP from your own code

Thierry Maasdam avatar
Written by Thierry Maasdam
Updated over 2 weeks ago

Consent Studio API for JavaScript

With the Consent Studio JavaScript API, you can leverage our consent banner logic for your own applications.

Getting Started

The Consent Studio consent banner instance is stored in window.consentStudio (or: consentStudio).

The API for JS can be accessed through window.consentStudio.api.

Our API is categorized as follows:

  • The consent banner (consentBanner)

  • The consent state (consentState)


The consent banner

Show the consent banner

/** Show the Consent Studio consent banner */
window.consentStudio.api.consentBanner.show();

Hide the consent banner

/** Show the Consent Studio consent banner */
window.consentStudio.api.consentBanner.show();


The consent state

The consent state represents the userโ€™s preferences regarding the use of cookies and other data processing. You can use the following methods to interact with the consent state.

Reading the consent state

List all the consented categories

This method retrieves all the categories that consent has been granted for.

/** 
* @returns {array<string>}
*/
window.consentStudio.api.consentState.get();

Check if the user has given functional consent

This method checks whether the user has consented to functional data processing.

/** 
* @returns {bool}
*/
window.consentStudio.api.consentState.hasFunctional();

Check if the user has given analytics consent

This method checks whether the user has consented to analytics data processing.

/** 
* @returns {bool}
*/
window.consentStudio.api.consentState.hasAnalytics();

Check if the user has given marketing consent

This method checks whether the user has consented to marketing data processing.

/** 
* @returns {bool}
*/
window.consentStudio.api.consentState.hasMarketing();

Changing the consent state

Make sure that consent state changes are derived from lawful prompts: well-informed, explicit and freely given.

Grant analytics consent

This method grants analytics consent.

/** 
* @returns {void}
*/
window.consentStudio.api.consentState.grantAnalytics();

Deny analytics consent

This method denies analytics consent.

/** 
* @returns {void}
*/
window.consentStudio.api.consentState.denyAnalytics();

Grant marketing consent

This method grants marketing consent.

/** 
* @returns {void}
*/
window.consentStudio.api.consentState.grantMarketing();

Deny marketing consent

This method denies marketing consent.

/** 
* @returns {void}
*/
window.consentStudio.api.consentState.denyMarketing();
Did this answer your question?