Functionality
This function returns the current status of the GDPR CMP. It is part of the IAB Europe Transparency and Consent Framework (TCF) Specifications.
To query the state and process consent it is recommended to use addEventListener instead of ping
.
Syntax
function __tcfapi()
argument name | type | optional | value | description |
---|---|---|---|---|
command | string |
| ||
version | integer | ✔️ |
| The TCF API version to use. Can be null instead. |
callback | function |
| The callback function that is called with the function call result. |
Description
The ping command invokes the callback immediately without any asynchronous logic and returns a PingReturn
object for determining whether or not the main CMP script has loaded yet and whether GDPR applies.
AdConsent will return:
cmpLoaded: false
andgdprApplies: undefined
as long as it is loadingcmpLoaded: true
andgdprApplies: true|false
accordingly, when finished loading
Scope
The function can be called at any time, but the response will change depending on when it is called.
Examples
Basic usage
__tcfapi('ping', 2, function(pingReturn) { if(!pingReturn.cmpLoaded) { console.log("AdConsent is loading, no further information available", pingReturn); } else { console.log("AdConsent is loaded", pingReturn); } });