Skip to content

Javascript API

Fabian Pimminger edited this page Mar 21, 2023 · 4 revisions

Functions

Open Privacy Notice

Opens the cookie notice (modal or banner)

cookiefox.api.show()

Example Usage

<a href="javascript:void(0)" onclick="cookiefox.api.show()">Open Privacy Settings</a>


Get Consent

Returns the user consent as an object of categories (category consent mode) or a boolean value (single consent mode). Can also be null if consent is not yet initialized

cookiefox.api.getConsent()

Example Usage

let consent = cookiefox.api.getConsent()

Example Return

categories: {functional: true, statistics: true, marketing: true, external-media: true}


Set Consent

Sets the consent (true, false) in CookieFox. A category parameter must be present if the category consent mode is used - omit in single consent mode.

cookiefox.api.setConsent(consent)

cookiefox.api.setConsent(consent, category)

Example Usage

cookiefox.api.setConsent(true)

cookiefox.api.setConsent(true, 'marketing')

cookiefox.api.setConsent(false, 'statistics')


Events

Init

Is triggered after Cookiefox is initialised

cookiefox:init

Example Usage

document.addEventListener("cookiefox:init", function(){ console.log("Cookiefox Initialized"); });


Consent Changed

Is triggered after Cookiefox consent has been changed. This happens everytime the cookie notice is closed and once after the initial page load. This event should be used to watch consent changes. The consent (see getConsent() api) is returned in the detail property of the event object.

cookiefox:consent-changed

Example Usage

document.addEventListener("cookiefox:consent-changed", function(e){ console.log("Cookiefox Consent Changed", e.detail); });