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 )
__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.

Command Function Description
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()

__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).
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). 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).
showGDPRScreenAdvanced __cmp() Show preference manager for GDPR
showGDPRScreenVendors __cmp() Show preference manager for GDPR > Page All vendors
showCCPAScreenAdvanced __cmp() Show preference manager for CCPA
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.

 

Back to top