Leading Consent Management Platform

Compliant with GDPR, CCPA, COPPA, LGPD, PECR, PDPA, PIPEDA, and more.

Consent Ready API

Add the UniConsent tag once, with your license key. The tag defines two functions immediately and then loads the full CMP in the background.

<script src="https://cmp.uniconsent.com/v2/cmp.js" data-license="YOUR_LICENSE"></script>

You can find your license key at the Install & Setup section. See Install UniConsent Tags for Web for the full installation guide, including the classic two-part tag for existing installations.

unicReady(callback)

Fires once, when the consent state is final.

  • GDPR and IAB TCF Canada: after the user makes a choice, or a stored choice is restored.
  • CCPA / US state laws / other opt-out regions: as soon as the CMP loads.
  • Consent category banners: after the choice in your GDPR region, or everywhere when GDPR is set to worldwide, except in California when CCPA is on and in Canada when IAB TCF Canada is on. Elsewhere as soon as the CMP loads, so check UNIC_EP_1 … UNIC_EP_4 before loading opt-in category tags.

Subscribing after it has already fired calls back immediately.

unicReady(function (status) {
  if (status.UNIC_P_1) {
    loadAnalytics();
  }
});

unicUpdate(callback)

Fires at the same time as unicReady, and again after every consent change (for example when the user reopens the settings and changes a purpose). Subscribing late calls back immediately with the current state, then on every later change. Saves that do not change anything are ignored.

unicUpdate(function (status) {
  applyConsent(status);
});

DOM events

The same data is dispatched on window as unic:ready and unic:update. Register listeners before the tag so they exist when the events fire.

window.addEventListener('unic:update', function (e) {
  applyConsent(e.detail);
});

Loading synchronously

Place your code anywhere after the tag. Nothing else is required.

<script src="https://cmp.uniconsent.com/v2/cmp.js" data-license="YOUR_LICENSE"></script>
<script>
  unicReady(function (status) { /* consent is final */ });
  unicUpdate(function (status) { /* every change */ });
</script>

Loading asynchronously

With async, your inline code may run before the tag. Add the two-line queue guard so calls made early are replayed once the tag loads.

<script async src="https://cmp.uniconsent.com/v2/cmp.js" data-license="YOUR_LICENSE"></script>
<script>
  window.unicReady  = window.unicReady  || function (cb) { (window.unicReady.q  = window.unicReady.q  || []).push(cb); };
  window.unicUpdate = window.unicUpdate || function (cb) { (window.unicUpdate.q = window.unicUpdate.q || []).push(cb); };

  unicReady(function (status) { /* consent is final */ });
  unicUpdate(function (status) { /* every change */ });
</script>

Status object

FieldTypeMeaning
IS_LOADbooleanWhere IAB TCF applies, true only when the visitor allows storage or any custom vendor: false before a choice and after a reject. Always true where IAB TCF does not apply. Consent category and US opt-out choices do not change it, use UNIC_EP_1 … UNIC_EP_4 and the purpose flags to decide which tags load
LOCstringDetected user location
GEOstringRegion whose rules apply: EU, CA, USCA, a US state such as USTX, US, BR, CN, ZA, VN, or N when none
EU, US, CA, BR, CN, NbooleanThe flag named by GEO is true, for example USTX. Consent category banners also set each of their region flags
NPA0 or 11 when only non-personalized ads should be served
customVendorsobjectCustom vendor id to boolean consent
UNIC_CP_{id}booleanYour custom purposes, by purpose ID
UNIC_P_1 … UNIC_P_10booleanIAB TCF purposes 1 to 10. Outside IAB TCF they follow the policy that applies: advertising purposes turn off after a US opt-out
UNIC_SF_1, UNIC_SF_2booleanTCF special features (GDPR only)
UNIC_EP_1 … UNIC_EP_4booleanConsent categories 1 to 4, set in every region. Where IAB TCF applies they follow its purposes, and category 4 (marketing) turns off after a US opt-out

Notes

  • unicReady and unicUpdate are reserved names on window. Do not define functions with these names for other purposes.
  • Callbacks are wrapped in try/catch. An error in one does not stop the others.
  • Both functions accept any number of subscribers.
  • The tag ignores itself if the CMP script is already on the page.
  • The tag sets a Google Consent Mode default of all storage denied with a 3 second wait_for_update. If you already set your own Consent Mode defaults, place them after the tag or they will be overridden.

Still have questions?

Contact us: support@uniconsent.com

Stay ahead on privacy and consent

Privacy laws, consent and compliance updates, a few emails a month.

No spam, unsubscribe any time. Privacy