Properties, methods, events and callback functions

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

NameTypeDefaultDescription
consent.necessarybooltrueTrue if current user has accepted necessary cookies.
The property is read only.
consent.preferencesboolfalseTrue if current user has accepted preference cookies.
The property is read only.
consent.statisticsboolfalseTrue if current user has accepted statistics cookies.
The property is read only.
consent.marketingboolfalseTrue if current user has accepted marketing cookies.
The property is read only.
consentedboolfalseTrue if the user has accepted cookies.
The property is read only.
declinedboolfalseTrue if the user has declined the use of cookies.
The property is read only.
hasResponseboolfalseTrue if the user has responded to the dialog with either ‘accept’ or ‘decline’.
The property is read only.
doNotTrackboolfalseTrue 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

NameParametersDescription
showNoneForces the cookie consent dialog to show.
hideNoneForces the cookie consent dialog to hide.
renewNoneDeletes 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.
getScriptstring 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.
runScriptsNoneEvaluates 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.
withdrawNoneWithdraw my consent for this website.
<a href="javascript: CookieConsent.renew()">Renew or change your cookie consent</a>

Callbacks (Asynchronous event handling)

NameDescription
CookieConsentCallback_OnLoadThe asynchronous callback is triggered when the cookie banner has loaded to get the user’s consent.
CookieConsentCallback_OnAcceptThe 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_OnDeclineThe 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)

NameDescription
onloadThe event is triggered when the cookie banner has loaded to get the user’s consent.
onacceptThe 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.
ondeclineThe 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

NameTypeMandatoryDescription
data-cbidstringyesThe unique ID for your Cookie Info subscription.
data-typestringnoOverrides the default dialog type with one of the following values:<br/>”optin”, “optout”, “optinout”, “leveloptin”, “inlineoptin”
data-levelstringnoOverrides the default consent method with one of the following values:
“implied”, “strict”
data-culturestringnoTo 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.
<script id="CookieConsent" data-culture="EN" src="https://consent.cookiebot.com/uc.js" data-cbid="00000000-0000-0000-0000-000000000000" type="text/javascript"></script>

Probeer nu 14 dagen gratis Cookiebot

Cookie scanner, cookie banner, cookieverklaring en cookie toestemming in één.

  • Cookies op je website gebruiken volgens AVG, ePrivacy en cookie wetgeving
  • Cookiebeheer volledig geautomatiseerd
  • Cookie banner op basis van jouw huisstijl
  • Automatisch opgestelde cookieverklaring, altijd up to date

De Cookiebot oplossing draait op 1.4 miljoen Websites, beheert 5.2 miljard maandelijkse User Consents en Ondersteunt 47+ talen.