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
.
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. |
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
and gdprApplies: undefined
as long as it is loading
cmpLoaded: true
and gdprApplies: true|false
accordingly, when finished loading
The function can be called at any time, but the response will change depending on when it is called.
__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); } }); |