Skip to content

EARN UP TO 50% COMMISSION WITH OUR RESELLER ACCOUNTS + REGULAR PASSIVE INCOME SIGN UP TODAY

Reference

JavaScript API

Look up the cookieScan object and the consent update event that let your own code check what a visitor has accepted.

Updated 3 min read

Applies to:
  • Cookie banner

https://cookiescan.com/help/javascript-api/ Β· Updated 12 October 2026

On this page

Overview

The JavaScript API lets your own code check what a visitor has agreed to. Use it to load a script, video or widget only once the visitor accepts its category. It works on every plan.

To turn it on, go to Cookie Banner, then Settings, then Javascript API, tick Javascript API and select Save & Publish.

The cookieScan object

With the API on, the CookieScan script creates window.cookieScan as it loads. It holds the visitor's saved choice.

PropertyTypeValue
cookieScan.consentGiventrue or falsetrue once the visitor has made a choice on your banner.
cookieScan.consent.preferencetrue or falsetrue if the visitor accepted Preference.
cookieScan.consent.statisticstrue or falsetrue if the visitor accepted Statistics.
cookieScan.consent.statisticsExempttrue or falsetrue if the visitor allows Statistics cookies you have marked Exempt.
cookieScan.consent.marketingtrue or falsetrue if the visitor accepted Marketing.
cookieScan.consent.unclassifiedtrue or falsetrue if the visitor accepted Unclassified.

Until the visitor makes a choice, every value is false. Necessary cookies have no property. They are always allowed.

A short example that checks for Marketing consent:

JavaScript
if (window.cookieScan && cookieScan.consent && cookieScan.consent.marketing) {
  // The visitor accepted Marketing: load your marketing script here
}

When a visitor saves a choice, CookieScan fires a cookiescan_consent_update event on document. The event's detail holds the same values as cookieScan.consent, plus consentGiven.

JavaScript
document.addEventListener('cookiescan_consent_update', function (e) {
  if (e.detail.marketing) {
    // The visitor has just accepted Marketing
  }
});

The event fires only when Seamless consent (no page reload) is on. Otherwise the page reloads after the choice, and cookieScan holds the new values on the reloaded page. The event also fires when a visitor turns categories off, with those values set to false.

When the values are ready

When your code can read the values depends on how you install CookieScan.

Install methodWhen cookieScan is ready
Script tagAs soon as the CookieScan script has run. Put your code after the CookieScan script tag.
Google Tag ManagerAfter Tag Manager loads the CookieScan script, which can be after your page's own scripts run. Check that window.cookieScan exists first.

If you install with Google Tag Manager, you can use Tag Manager events instead of reading cookieScan.

Was this article helpful?

Thanks for your feedback.

Please don't include personal details. We can't reply here.

Thanks for your feedback.

Please don't include personal details. We can't reply here.

Thanks, your comment has been sent.

Sorry, we couldn't record your feedback. Please try again later.

Still stuck?

Our support team can help with anything these guides don't cover. Tell us your CookieScan ID and the page address so we can look straight away.

Back to Reference