[C] Consentify

JavaScript API

Control the Consentify widget programmatically with the window.Consentify API.

The widget exposes a global window.Consentify object with the following methods.

init(siteId?, options?)

Manually initialize the widget. Useful when you need programmatic control instead of auto-initialization via data attributes.

Token mode (recommended) passes the token in options and no site ID:

await window.Consentify.init(undefined, {
  token: 'ct_YOUR_PUBLIC_TOKEN',
  position: 'bottom-left',
  theme: 'dark',
  accent: '#10b981',
  lang: 'en'
});

Legacy site ID mode passes the site UUID as the first argument:

await window.Consentify.init('your-site-id', { theme: 'dark' });

All options are optional and override the server-side configuration.

Known limitation: init() swallows errors. If the config fetch fails (bad token, network error, origin rejected), the promise resolves normally and nothing is logged - the banner simply never appears.

show()

Show the consent banner. Only works after the widget has initialized and loaded its config; before that (including on the returning-visitor fast path, where no config is fetched) it is a no-op.

window.Consentify.show();

hide()

Hide the consent banner without recording a choice.

window.Consentify.hide();

getConsent()

Get the current consent preferences. Returns null if no consent has been given. Required categories (like Necessary) are always granted and are stripped from the returned map - only optional categories appear.

const consent = window.Consentify.getConsent();
// { analytics: true, marketing: false, functional: true } or null

hasConsent()

Check if the user has already given consent.

if (window.Consentify.hasConsent()) {
  const consent = window.Consentify.getConsent();
}

reset()

Clear stored consent and show the banner again. Useful for "manage cookie preferences" links.

window.Consentify.reset();

onConsentChange(callback)

Register a callback to be notified when consent changes. The callback receives the visitor's raw choices - the same optional-categories-only map as getConsent(), without required categories injected.

For loading scripts based on consent, prefer script blocking (<script type="text/plain" data-consentify="...">) - the widget then handles injection for you.

window.Consentify.onConsentChange((consent) => {
  if (consent.analytics) {
    // Initialize analytics
  }

  if (consent.marketing) {
    // Initialize marketing pixels
  }
});

On this page