CMP API usage

Introduction

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

Non-EU visitors and CMP API

By default, non-EU version of the Consent Tool code (automaticaly served by our geo-aware CDN) does not include CMP API functionality (to minimize load traffic/time), but that is server-side configurable - feel free to contact support if you need it.

General information

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

When implementing the CMP API integration, you should bear in mind that it loads aynchronously, so you can not directly call __cmp 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.

(function (window) {
    window.__cmp = (function () {
        var listen = window.attachEvent || window.addEventListener;
        listen('message', function (event) {
            window.__cmp.receiveMessage(event);
        });

        var commandQueue   = [];
        var cmp            = function (command, parameter, callback) {
            if (command === 'ping') {
                callback({"cmpLoaded": false}, true);
            } else {
                commandQueue.push({
                    command:   command,
                    parameter: parameter,
                    callback:  callback
                });
            }
        };
        cmp.commandQueue   = commandQueue;

        cmp.receiveMessage = function (event) {
            var data = event && event.data && event.data.__cmpCall;
            if (data) {
                commandQueue.push({
                    callId:    data.callId,
                    command:   data.command,
                    parameter: data.parameter,
                    event:     event
                });
            }
        };

        return cmp;
    }());
})(window);

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

window.__cmp('getConsentData', null, function (consentData, consentDataSuccess) {
    console.groupCollapsed('getConsentData 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.

Back to top