The Cookie Info script loads and constructs a client side JavaScript object named ‘CookieConsent’ which exposes the following public properties, methods, events and callback functions. See the tutorial on how to deploy the Cookie Info script to your website template.

Properties

Name Type Default Description
consent.necessary bool true True if current user has accepted necessary cookies.
The property is read only.
consent.preferences bool false True if current user has accepted preference cookies.
The property is read only.
consent.statistics bool false True if current user has accepted statistics cookies.
The property is read only.
consent.marketing bool false True if current user has accepted marketing cookies.
The property is read only.
consented bool false True if the user has accepted cookies.
The property is read only.
declined bool false True if the user has declined the use of cookies.
The property is read only.
hasResponse bool false True if the user has responded to the dialog with either ‘accept’ or ‘decline’.
The property is read only.
doNotTrack bool false True if the user has enabled the web browser’s ‘Do not track’ (DNT) setting. If DNT is enabled Cookie Info will not set the third party cookie CookieConsentBulkTicket used for bulk consent.
The property is read only.

Methods

Name Parameters Description
show None Forces the cookie consent dialog to show.
hide None Forces the cookie consent dialog to hide.
renew None Deletes any registered consent in the website user’s browser and shows the cookie consent dialog to the website user to renew or change the user’s consent state.
getScript string URL,
bool async,
func callback
Loads a JavaScript-file. URL: Absolute path to the JavaScript-file.
async (Optional): Determines if the script should load asynchronously.
callback (Optional): JavaScript function to execute when the script has finished loading.
runScripts None Evaluates all loaded script tags of type “text/plain” with the attribute “data-cookieconsent” and executes the scripts in accordance with the user’s consent state. For use by websites that load content dynamically, e.g. in single page applications. Scripts are only executed once, so this function is safe to call several times, e.g. every time new content is loaded.
withdraw None Withdraw my consent for this website.

Example: Create link that makes it possible for the user to change or renew a cookie consent

<a href="javascript: CookieConsent.renew()">Renew or change your cookie consent</a>

Callbacks (Asynchronous event handling)

Name Description
CookieConsentCallback_OnLoad The asynchronous callback is triggered when the cookie banner has loaded to get the user’s consent.
CookieConsentCallback_OnAccept The asynchronous callback is triggered when the user clicks the accept-button of the cookie consent dialog and whenever a consented user loads a page.
CookieConsentCallback_OnDecline The asynchronous callback is triggered when the user declines the use of cookies by clicking the decline-button in the cookie consent dialog. The callback is also triggered whenever a user that has declined the use of cookies loads a page.

Example: Load Google Analytics if the user has accepted Cookies

<script type="text/javascript">

function CookieConsentCallback_OnAccept() {
if (CookieConsent.consent.statistics)
{
enableGoogleAnalytics();
}
}

var _gaq = [];
function enableGoogleAnalytics() {
_gaq.push(['_setAccount', 'UA-00000000-0']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
}

</script>

Events (Synchronous event handling)

Name Description
onload The event is triggered when the cookie banner has loaded to get the user’s consent.
onaccept The event is triggered if the user accepts the use of cookies. The event is also triggered if the user has consented at an earlier visit to the website.
ondecline The event is triggered if the user declines the use of cookies by clicking the decline-button in the cookie consent dialog. The event is also triggered if the user already has declined at an earlier visit to the website.

Script tag data attributes

Name Type Mandatory Description
data-cbid string yes The unique ID for your Cookie Info subscription.
data-type string no Overrides the default dialog type with one of the following values:<br/>”optin”, “optout”, “optinout”, “leveloptin”, “inlineoptin”
data-level string no Overrides the default consent method with one of the following values:
“implied”, “strict”
data-culture string no To force a specific language variant of the consent dialog, set the value of this attribute to a culture neutral ISO 639-1 language code, e.g. “EN” for English. Setting this attribute with a valid language overrides the “Auto-detect user language” setting in the Cookie Info manager.

Example: Force the consent dialog to show in English

<script id="CookieConsent" data-culture="EN" src="https://consent.cookiebot.com/uc.js" data-cbid="00000000-0000-0000-0000-000000000000" type="text/javascript"></script>

Delen