Gravito Ltd
Search…
Integration
Gravito CMP emits "gravito:cmp:b2b" (up to version 1.0.x) or "gravito:cmp:light" (version 2.0.1 onwards) events. Events indicate the UI actions and points when the user has given or denied the consents and rest of the tags can either trigger or should not.
The event types are:
Action
eventType
CMP loaded
cmploaded:nocookie
CMP is shown with first, initial layer
layer1:visible
Layer 2 closed
layer2:closed
Custom settings confirmed by clicking "Yes"
layer2:opt-in:selected
"Accept all" clicked on layer 1
layer1:opt-in:all
"Accept all" clicked on layer 2
layer2:opt-in:all
"Reject all" clicked on layer 2
layer2:opt-out:all
CMP has collected consents previously
opt-in:previously
Now you could set e.g. TMS to trigger further activities after it receives event with types "layer?:opt-in:all" or "layer2:opt-in:selected". The latter option might require further processing of the settings.

Setting up event listener on GTM

You need to define following:
  1. 1.
    Custom HTML, call it e.g. "CMP events"
  2. 2.
    Variable, call it e.g. "CMP event proxy"
  3. 3.
    Variable, call it e.g. "consentLevel"
  4. 4.
    Trigger, call it e.g. "CMP opt-in event"
1) You can set up simple event listener on GTM with following code as custom tag:
Version 1.0.x:
1
(function() {
2
document.addEventListener('gravito:cmp:b2b', {{CMP event proxy}}, true);
3
})();
Copied!
Version 2.0.x onwards:
1
(function() {
2
document.addEventListener('gravito:cmp:light', {{CMP event proxy}}, true);
3
})();
Copied!
2) Define new variable {{CMP event proxy}}, type being javascript:
Note! There is version inconsistency, version 2 branch was changing variable naming but the data model was not changed, the change occurs in version 2.0.2, all versions prior to that needs to stick to following example.
Versions 1.0.x:
1
function() {
2
return function(event) {
3
4
var consentLevel = "";
5
if(typeof gravitoData.B2B.length!="undefined") {
6
if(JSON.parse(gravitoData.B2B).Model[0].consent == true) { consentLevel=consentLevel+"a"; }
7
if(JSON.parse(gravitoData.B2B).Model[1].consent == true) { consentLevel=consentLevel+"b"; }
8
if(JSON.parse(gravitoData.B2B).Model[2].consent == true) { consentLevel=consentLevel+"c"; }
9
if(JSON.parse(gravitoData.B2B).Model[3].consent == true) { consentLevel=consentLevel+"d"; }
10
}
11
12
window.dataLayer.push({
13
event: 'custom.event.cmp.' + event.detail.eventType,
14
'custom.gtm.originalEvent': event,
15
'consentLevel':consentLevel
16
});
17
};
18
}
Copied!
Version 2.0.0 onwards:
1
function() {
2
return function(event) {
3
4
var consentLevel = "";
5
if(typeof gravitoData.lightCMP.length!="undefined") {
6
if(JSON.parse(gravitoData.lightCMP).Model[0].consent == true) { consentLevel=consentLevel+"a"; }
7
if(JSON.parse(gravitoData.lightCMP).Model[1].consent == true) { consentLevel=consentLevel+"b"; }
8
if(JSON.parse(gravitoData.lightCMP).Model[2].consent == true) { consentLevel=consentLevel+"c"; }
9
if(JSON.parse(gravitoData.lightCMP).Model[3].consent == true) { consentLevel=consentLevel+"d"; }
10
}
11
12
window.dataLayer.push({
13
event: 'custom.event.cmp.' + event.detail.eventType,
14
'custom.gtm.originalEvent': event,
15
'consentLevel':consentLevel
16
});
17
};
18
}
Copied!
Code blocks above are pushing the event data to dataLayer for GA and other tags to consume.
3) Define new variable "consentLevel", type being datalayer variable, leave withot default value.
4) Define a trigger for calling other tags after consent has been given
  • Create new trigger, call it e.g. "marketing consent"
  • Choose "Custom event" as type
  • Define event name as "cmp.*opt-in", enable regex matching
  • Choose "some custom events"
  • Define the rule to look for "consentLevel" variable and and depending on the overall CMP setup you might look for variable values to contain string "d" or some other more complex mixture depending on if you want the trigger to require multiple consents:
    • Analytics consent, consentLevel contains "c"
    • Marketing consent, consentLevel contains "d"
    • etc.
After defining those you can use this newly created trigger to load tags that you want to keep from triggering before consent is given. Add more granularity with consent levels and multiple triggers as you like.
5) Testing and debugging. Easiest way to test that your setup works it should is to set up custom HTML tag with console logging or similar and set the triggere to "Marketing consent" or whatever you have named your triggers.

How to resurface CMP?

Two options, CMP binds automatically to element ID defined in config ("settingBtnId"). Alternatively the CMP can be summoned by calling:
Version 1.0.x:
1
window.gravitoB2BCMP.openPreferences();
Copied!
Version 2.0.x onwards:
1
window.gravitoLightCMP.openPreferences();
Copied!
Last modified 1yr ago