SDK with TCF CMP

Deployment routes

Gravito CMP is TCF 2.1 compliant consent management platform. To roll it out, you will first need configuration for it, that is usually generated by Gravito Admin Portal based on your customizations and settings or you will be handed a configuration made by Gravito devOps or some of Gravito’s partners. You can host the configuration on your page template, load it as separate file or host it inside Google Tag Manager custom HTML tag. Whatever the way is, make sure that the configuration is available before the rest of the CMP summoning occurs.

<script>
var customCSS="";
var gravitoCMPConfig = {...}
window.gravitoCMPConfig = gravitoCMPConfig;
</script>

After you have configuration set, you can request CMP with one of following examples.

Option A : Standalone Gravito CMP (settings stored to local cookie):

<script>
var gravitoSdkTag = document.createElement("script");
gravitoSdkTag.src = "https://cdn.gravito.net/sdk/gravitoSDK-v1.0.8.js";
gravitoSdkTag.onload = function () {
window.gravito.ready(function () {
gravito.initTCFCMP(
"https://cdn.gravito.net/tcf-v2",
"https://cdn.gravito.net/cmp",
"VERSION_NUMBER"
);
});
};
document.body.appendChild(gravitoSdkTag);
</script>

Replace “VERSION_NUMBER” with the version you want to use. If you don’t pass any value it will use the latest version by default.

Option B : Gravito CMP with first-party (1P) cookie (consent is stored to persistent cookie):

function getCmpData() {
var date = new Date(new Date().setFullYear(new Date().getFullYear() + 1));
var domain = window.location.hostname;
var value = null;
var xhr = new XMLHttpRequest();
xhr.open("POST", 'https://gto.gravito.net/api/firstparty', true);
xhr.withCredentials = true;
xhr.onreadystatechange = function (response) {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
console.log("1P response : " + response.target.response);
var result = JSON.parse(response.target.response)
if (result.events) {
var gdata = result.events.gravitoData ? JSON.parse(result.events.gravitoData) : null
value = gdata ? gdata.TCString : null
if (value) {
document.cookie =
"TcString" +
"=" +
value +
"; expires=" +
date.toGMTString() +
"; path=/; domain=" +
domain;
}
if (gdata) {
document.cookie =
"gravitoData" +
"=" +
JSON.stringify(gdata) +
"; expires=" +
date.toGMTString() +
"; path=/; domain=" +
domain;
}
}
var obj = {
senderId: "gravitoCMPSuperWrapper",
status: "ready",
};
window.postMessage(obj, "*");
}
}
xhr.send();
}
function postCmpData(data) {
console.log("data", data)
var gravitoData = JSON.stringify(data)
var xhr = new XMLHttpRequest();
xhr.open("POST", 'https://gto.gravito.net/api/firstparty?gravitoData=' + gravitoData, true);
xhr.withCredentials = true;
xhr.onreadystatechange = function (response) {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
console.log("1P response : " + response.target.response);
}
}
xhr.send();
}
var gravitoSdkTag = document.createElement("script");
gravitoSdkTag.src = "https://cdn.gravito.net/sdk/gravitoSDK_latest.js";
gravitoSdkTag.onload = function () {
window.gravito.ready(function () {
gravito.initTCFCMPWithCustomBackend(getCmpData, function () {
gravito.initTCFCMP(
"https://cdn.gravito.net/tcf-v2",
"https://cdn.gravito.net/cmp",
"bundle_latest_2"
);
}, postCmpData)
});
};
document.body.appendChild(gravitoSdkTag);

NOTE: Make sure you have withBackendIntegration:true in gravitoCMPConfig

Please note that this is example works only on *.gravito.net domains. Each domain utilizing this setup needs to be enrolled to Gravito platform which outputs required DNS settings to be applied on customer DNS. Using above would require to replace gto.gravito.net with gto.<domain>.<tld> as endpoint. Same example can be used for other custom backend integration, modify getCmpData and postCmpData functions to suit the custom scenario.

Option C : Gravito CMP with Gravito API integration (consent is stored to local cookie and to Gravito profile):

<script>
var gravitoSdkTag = document.createElement("script");
gravitoSdkTag.src = "https://cdn.gravito.net/sdk/gravitoSDK-v1.0.8.js";
gravitoSdkTag.onload = function () {
window.gravito.ready(function () {
gravito.initTCFCMPWithBackend(
"https://cdn.gravito.net/tcf-v2",
"https://cdn.gravito.net/cmp",
"YOUR_GRAVITO_REGISTERED_DOMAIN",
"VERSION_NUMBER"
);
});
};
document.body.appendChild(gravitoSdkTag);
</script>

NOTE: Make sure you have withBackendIntegration:true in gravitoCMPConfig