TCF API Support

Introduction

As an approved IAB Consent Management Platform, Clickio Consent fully supports the standardized CMP Javascript API for user consent data retrieval.

General information

The current version API documentation can be found here. Clickio CMP API implementation fully supports all the described functionality.

Non-EU visitors and CMP API
API Stub

When implementing the CMP API integration, you should bear in mind that it loads asynchronously, so you can not directly call __tcfapi function to pass commands from your scripts. Avoid implementing any await cycles/timeouts, which create parasitic load or delays. Instead, you can use a simple CMP API stub, which gracefully handles all the calls for you, while the full code loads.

<script type="text/javascript">
!function(){"use strict";var t,e,o=(t=function(t){function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}t.exports=function(){for(var t,o,n=[],r=window,a=r;a;){try{if(a.frames.__tcfapiLocator){t=a;break}}catch(t){}if(a===r.top)break;a=a.parent}t||(function t(){var e=r.document,o=!!r.frames.__tcfapiLocator;if(!o)if(e.body){var n=e.createElement("iframe");n.style.cssText="display:none",n.name="__tcfapiLocator",e.body.appendChild(n)}else setTimeout(t,5);return!o}(),r.__tcfapi=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];if(!e.length)return n;"setGdprApplies"===e[0]?e.length>3&&2===parseInt(e[1],10)&&"boolean"==typeof e[3]&&(o=e[3],"function"==typeof e[2]&&e[2]("set",!0)):"ping"===e[0]?"function"==typeof e[2]&&e[2]({gdprApplies:o,cmpLoaded:!1,cmpStatus:"stub"}):n.push(e)},r.addEventListener("message",(function(t){var o="string"==typeof t.data,n={};if(o)try{n=JSON.parse(t.data)}catch(t){}else n=t.data;var r="object"===e(n)&&null!==n?n.__tcfapiCall:null;r&&window.__tcfapi(r.command,r.version,(function(e,n){var a={__tcfapiReturn:{returnValue:e,success:n,callId:r.callId}};t&&t.source&&t.source.postMessage&&t.source.postMessage(o?JSON.stringify(a):a,"*")}),r.parameter)}),!1))}},t(e={exports:{}}),e.exports);o()}();
</script>

The code must be installed in the top of the site page head section, before any ads codes and libraries.

When installing the stub code without setting Consent Scope to Global, please contact our support to enable the CMP API for out-of-scope visitors, otherwise the __tcfapi calls will malfunction and this may break 3rd party solutions logic.

We recommend installing the stub code on the site if you are using non-Clickio 3rd party monetization solutions. For Google ads tags, please refer to this article.

The code is a subject to change, please be sure to have the latest version installed on the site prior to filing support requests in case of any issues.

After installing this code on the page, you can then call the API as usual (getTCData dump example is shown below).

window.__tcfapi('getTCData', null, function (consentData, consentDataSuccess) {
    console.groupCollapsed('getTCData called ('+consentDataSuccess+')');
    console.log(consentData);
    console.groupEnd();
});

The stub stores the request and replies as soon as the full code loads. PostMessage commands are also supported.