[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.

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

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

show()

Show the consent banner (if previously hidden or after consent was given).

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.

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. Use this to conditionally load scripts based on consent.

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

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

On this page