Execute JavaScript code and determining the consent signal

UniConsent CMP v2 API

  • openunic

Display UniConsent CMP to users.

__unicapi('openunic')
  • agreeAll

The user agreed to all the consent options. You can implement your programmatic first layer of the CMP and trigger the agreeAll event once the user clicked "Agree All" button at your programmatic first layer UI.

__unicapi('agreeAll')
  • openOptions

Open the second layer UI. This can be used if you like to customise the first layer and programmatic open the consent manager.

__unicapi('openOptions')
  • openVendorList

Open the vendor list UI. This can be used if you like to customise the first layer and programmatic open the consent manager.

__unicapi('openVendorList')
  • getUConsent

Get the consent signal of your custom vendors.

__unicapi(
  'getUConsent',
  2,
  (uConsent, success) => {
    if (success) {
      // do something with tcData
    } else {
      // do something else
    }
  },
  [1, 2, 3]
) // vendors Ids
  • getUCData

Get the consent signal data of your custom vendors.

__unicapi(
  'getUCData',
  2,
  (ucData, success) => {
    if (success) {
      // do something with tcData
    } else {
      // do something else
    }
  },
  [1, 2, 3]
) // vendors Ids
  • getTCData
__tcfapi(
  'getTCData',
  2,
  (tcData, success) => {
    if (success) {
      // do something with tcData
    } else {
      // do something else
    }
  },
  [1, 2, 3]
) // vendors Ids
  • ping
__tcfapi('ping', 2, (pingReturn) => {
  // do something with pingReturn
})
  • addEventListener
const callback = (tcData, success) => {
  if (success && tcData.eventStatus === 'tcloaded') {
    // do something with tcData.tcString

    // remove the ourself to not get called more than once
    __tcfapi(
      'removeEventListener',
      2,
      (success) => {
        if (success) {
          // oh good...
        }
      },
      tcData.listenerId
    )
  } else {
    // do something else
  }
}

__tcfapi('addEventListener', 2, callback)
  • getVendorList
__tcfapi(
  'getVendorList',
  2,
  (gvl, success) => {
    if (success) {
      // do something with gvl
    } else {
      // do something else
    }
  },
  'LATEST'
)

You can find all the API at: IAB TCF Document.

U.S. Privacy User Signal Mechanism "USP API" (CCPA Compliance Mechanism)

Example:

__uspapi('getUSPData', 1, (uspData, success) => {
  if (success) {
    // do something with uspData
  } else {
    // do something else
  }
})

Response uspData:

{
 "version": 1, /* number indicating the U.S. Privacy spec version */
 "uspString": "1YN" /* string; not applicable: "1--" */ /* number; 1 applies, 0 doesn't apply, -1 not set */
}

Make sure your ad stack get the consent from users before kicking off.

Example:

__tcfapi('addEventListener', 2, function (tcData, success) {
  if (success && tcData.unicLoad === true) {
    if (!window._initAds) {
      window._initAds = true
      // your code to kick off the ads
      console.log('_initAds started.')
    }
  }
})

Example:

;(function waitCMP() {
  var readyCMP
  if (!readyCMP && window['dataLayer']) {
    window['dataLayer'].forEach(function (event) {
      if (event['event'] === 'unic_data') {
        readyCMP = 1
        console.log(event)
        // your other codes;
      }
    })
  }
  if (!readyCMP) {
    setTimeout(waitCMP, 100)
  }
})()

Still have questions?

Contact us: support@uniconsent.com