Reference

JavaScript API

Open the banner from your own button, read the visitor's choice and react when it changes.

Once the banner script has loaded, a CookieTrue object is available on the page.

#Methods

CallWhat it does
CookieTrue.show()Shows the banner
CookieTrue.showSettings()Opens the category settings
CookieTrue.acceptAll()Accepts every category
CookieTrue.rejectAll()Rejects every optional category
CookieTrue.setConsent({ analytics: true })Sets chosen categories
CookieTrue.onChange(fn)Calls fn whenever the choice changes
CookieTrue.consentThe current choice
CookieTrue.regionThe visitor's region
CookieTrue.versionThe script version
CookieTrue.readytrue when the script has started

Any element with data-ct-open reopens the settings when clicked, and so does a link to #cookietrue-settings:

<a href="#cookietrue-settings">Change cookie settings</a>
<button data-ct-open>Cookie settings</button>

#Events

document.addEventListener('cookietrue:ready', () => {
  console.log(CookieTrue.consent);
});

document.addEventListener('cookietrue:consent', (event) => {
  // runs every time the visitor decides
  console.log(event.detail);
});
CookieTrue.onChange((consent) => {
  if (consent.analytics) startMyAnalytics();
});
Still stuck? Write to [email protected]. A person answers, usually the same day.