Info
Content

JavaScript-API

The consentmanager.net CMP supports various JavaScript APIs in order to allow websites to retrieve consent information.

Using the API

For all requests to the API, please always only use the public functions mentioned below. Please do not access the internal window.cmpmngr object directly!

In order to send or receive information from/to the API you can use the general public function __cmp(...). This function can handle most generic requests. In addition to this, the CMP also offers public functions __tcfapi(...) for IAB TCF v2 compliance and __uspapi(...) for IAB US Privacy compliance.

Example:

var x = __cmp('consentStatus');
if(x.consentExists){/* do something */}

API functions

The three API functions use different parameters due to the different specifications these functions are following. The API functions are:

__cmp( Command, Parameter, Callback, Async )
__uspapi( Command, Version, Callback, Parameter )
__tcfapi( Command, Version, Callback, Parameter )

Please note, that for __cmp() all parameters except of Command are optional.

Commands

The API supports the following commands:

Please note that our API may return objects to TCF v1+v2 commands, that are different from the standard. See here for more details.

Command Function Description
getVendorConsents __cmp() Get vendor consent data object according to IAB TCF v1.
noncompliant_getVendorConsents __cmp() Get vendor consent data object according to IAB TCF v1 in case of a noncompliant setup of the CMP.
getConsentData __cmp() Get consent data object according to IAB TCF v1.
noncompliant_getConsentData __cmp() Get consent data object according to IAB TCF v1 in case of a noncompliant setup of the CMP.
getTCData __tcfapi() Get consent data object according to IAB TCF v2.
noncompliant_getTCData __tcfapi() Get consent data object according to IAB TCF v2 in case of a noncompliant setup of the CMP.
getUSPData __uspapi() Get consent data string according to IAB US Privacy spec.
ping

__cmp()

__tcfapi()

Depending on used function:

__cmp('ping') will return the IAB TCF v1 ping object.

__tcfapi('ping') will return the IAB TCF v2 ping object.

addEventListener

__cmp()

__tcfapi()

Adds a new event listener. See details here.

Please note that the parameters depend on the used function.

removeEventListener

__cmp()

__tcfapi()

Removes an event listener. See above.
getCMPData __cmp()

Get an object that contains all relevant consent data.

{
 consentstring: "IAB TCF consent string", 
 uspstring: "IAB US Privacy String", 
 gdprApplies: true/false,
 hasGlobalScope: true/false, 
 tcfversion: 0/1/2, 
 tcfcompliant: true/false, 
 regulation: 0/1/2 (none / GDPR / CCPA), 
 purposeConsents: {},
 vendorConsents: {}, 
 purposeLI: {}, 
 vendorLI: {}
 googleVendorConsents: {}
}
consentStatus __cmp()

Get consent string and info if user choice is given. The returned status object will look like this: {'consentExists': true/false, 'consentData': '…'}

Please note that this does not signal consent, but only if the user made a choice.

setConsent __cmp() Simulate a user click on accept all (Parameter = 1) or reject all (Parameter = 0).
setVendorConsent __cmp() Sets consent status for a certain vendor. Vendor-ID and status need to be passed as array via parameter 2, e.g. __cmp('setVendorConsent',['s30', 1 ]) sets consent (accept) for vendor s30.
setPurposeConsent __cmp() Sets consent status for a certain purpose. Purpose-ID and status need to be passed as array via parameter 2, e.g. __cmp('setPurposeConsent',[52, 1 ]) sets consent (accept) for purpose 52.
exportConsent __cmp() Exports consent info for cross device consent sharing.
importConsent __cmp() Imports consent info for this visitor.
showScreen __cmp() Show welcome screen (depending on visitors location/account setup).
showGDPRScreen __cmp() Show welcome screen for GDPR
showCCPAScreen __cmp() Show welcome screen for CCPA
showScreenAdvanced __cmp() Show preference manager (depending on visitors location/account setup).
showGDPRScreenAdvanced __cmp() Show preference manager for GDPR
showCCPAScreenAdvanced __cmp() Show preference manager for CCPA
setAgeCallback __cmp() Set callback function for age verification.
setUserID __cmp()

Set external user ID 1.

setUserID sets the external ID (ID 2, ID 3) for which the user is known. getUserID and setUserID both return a user-ID object: {'external': ..., 'external2': ..., 'external3': ..., 'internal': ...}
Note: The internal user ID is only available if enabled in CMP settings and after “settings” event is fired (see CMP events).

setUserID2 __cmp() Set external user ID 2
setUserID3 __cmp() Set external user ID 3
getUserID __cmp() Get all user IDs

 

Back to top