Gravito Ltd
Search…
⌃K
Links

Deploy with wrapper

Legacy way of wrapping CMP with external hooks, we recommend using SDK for new deployments.
Light CMP wrapper deployment is required if you need perform actions before the Light CMP loads. Such cases are e.g.
  • Google Consent Mode (beta)
  • Fetch/sync consent(s) from backend/API service
  • Language selector plugin (coming up)
Example wrapper code enabling Google Consent Mode:
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
window.grvgoogleconsentmode = true;
function gravitoB2bCMP_sendDefaultConsents() {
try{
gtag('consent', 'default', {
// Deny consent for ad_storage
'ad_storage': 'denied',
// Deny consent for analytics_storage
'analytics_storage': 'denied'
});
}
catch(error){
console.log('error while sending default consents to google');
}
}
function gravitoB2bCMP_sendUpdatedConsents(consentObject) {
try{
gtag('consent', 'update', {
'ad_storage': consentObject.googleAds && consentObject.googleAds.isPresent && consentObject.googleAds.isConsented
? 'granted' : 'denied',
'analytics_storage': consentObject.googleAnalytics && consentObject.googleAnalytics.isPresent && consentObject.googleAnalytics.isConsented
? 'granted' : 'denied'
});
}
catch(error){
console.log('error while sending updated consents to google');
}
}
function gravitoB2bCMP_consentReceiver() {
window.addEventListener('message', function (message) {
var data = message.data;
if (data.senderId === "gravitoB2BCMP") {
switch (data.type) {
case "grv-b2b-cmp-status":
if (data.status === "b2bcmp-previousconsents") {
gravitoB2bCMP_sendUpdatedConsents(data.consents)
}else if(data.status === 'b2bcmp-updatedconsents'){
gravitoB2bCMP_sendUpdatedConsents(data.consents)
}else if(data.status === 'b2bcmp-nocookie'){
gravitoB2bCMP_sendDefaultConsents();
}
break;
default:
break;
}
}
})
}
gravitoB2bCMP_consentReceiver();
Normal CMP code can be appended to this wrapper code or alternatively loaded separately (but in sequence after the wrapper code).