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 __gpp(...) for IAB GPP 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 )
__tcfapi( Command, Version, Callback, Parameter )
__gpp( Command, Version, Callback, Parameter )

Removed: Please be aware that the __uspapi() does not exist anymore and was replaced by the __gpp().

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.

CommandFunctionDescription
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.
ping

__cmp()

__tcfapi()

__gpp()

Depending on used function:

__cmp('ping') will return false.

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

__gpp('ping',callback) will return the GPP 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. Possible status values:

0 = reject

1 = accept

2 = reject, don’t count

3 = accept, don’t count

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.

If you want to set consent for a purpose and all vendors that are assigned to this purpose, you can set the third field to true, e.g.

__cmp('setPurposeConsent',[52, 1, true ])

exportConsent__cmp()Exports consent info for cross device consent sharing.
importConsent__cmp()Imports consent info for this visitor.
cancelwait__cmp()Stop the CMP from waiting for incoming consent import calls.
   
showScreen__cmp()Show welcome screen (depending on visitors location/account setup).
showScreenAdvanced__cmp()Show preference manager (depending on visitors location/account setup). Note: You can use the second parameter to indicate which page should be opened (e.g. use “c52” in order to open the page for purpose c52).
showCookies__cmp()Show cookie table.
close__cmp()Close consent layer.
   
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
checkBlocking__cmp()Checks whether blocked elements can be unblocked and unblock them.
checkShowScreen__cmp()Checks whether to show the consent layer (again).
   
privacyLink__cmp()Redirects the visitor to the privacy policy page.
tacLink__cmp()Redirects the visitor to the Terms&Conditions page.
imprintLink__cmp()Redirects the visitor to the legal notice/imprint page.

 

We do our best to keep this purely informative documentation up to date. However, if you notice that any of these guides need a little touch-up, let us know!