How To Trigger a GTM Tag Allowing Vine Cookies By Sending a GTM Event
One easy way to fire a GTM tag is to send a GTM event to signal that the visitor accepted cookies. For example, with Osano you can do this as follows using the Osano Cookie Consent JavaScript API :
Sending GTM event to integrate Vine Cookies with Osano consent dialog
<script>
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#000"
},
"button": {
"background": "#f1d600"
}
},
"position": "top",
//Using Osano callback hooks onStatusChange & onInitialise to send GTM event
onStatusChange: function(status) {
console.log(this.hasConsented() ?
'enable cookies' : 'disable cookies');
if (this.hasConsented())
{ window.dataLayer = window.dataLayer || [];
window.dataLayer.push({'event': 'cookie_consent'}); }
},
onInitialise: function(status) {
if (status == 'allow' || status == 'dismiss')
{ window.dataLayer = window.dataLayer || [];
window.dataLayer.push({'event': 'cookie_consent'}); }
}
});
</script>
Now we need to tell GTM to listen to the 'cookie_consent' event and allow cookies when receiving event.
In GTM, create a new trigger as follows:
- Call it “Vine cookie_consent"
- Select Custom Event as the trigger type
- Select the trigger to fire on All Custom Events
- Enter ‘cookie_consent’ as the event name
Your trigger should look as follows:
- Click Save to create the trigger.
Please note that there are other possible types of triggers to be used in GTM. For example, you can use a trigger based on the Accept button click classes (which you can find inspecting the Accept button in the browser)
In Google Tag Manager, create a new Custom HTML tag:
- Give it a name: “call allowCookies on GTM event”
- Select Custom HTML as the tag type
- Copy the following script into the HTML box :
GTM Script to allow Vine cookies
<script type="text/plain" src="https://cdn.vine.eu/vscript/allowCookies.js" data-cookieconsent="marketing" async></script>
- Select the Vine cookie_consent trigger as a firing trigger so this tag fires on receiving the "cookie_consent" event.
Your tag should look as follows:
- Save and publish in GTM.
Comments
0 comments
Please sign in to leave a comment.