In this publish, I advised you what it’s and what have to be finished to comply with the 'regulation of cookies' and how to do it with Google Tag Manager (GTM). Nevertheless, on June 1, 2015, Google revealed a new model of Google Tag Manager, which has skilled essential modifications in its operation that make it unattainable to implement the answer proposed within the unique entry.
To summarize, in case you haven’t learn the original entry, I will say that so as to comply with the regulation of cookies it is needed to warn of using those cookies that aren’t strictly vital for the functioning of the website and block its set up till acquiring the consent by part of the consumer, which we’ll contemplate given when clicking on a link or scroll, actions accepted by the Spanish Agency for Knowledge Safety (AEPD) as obtaining consent.
Then, after consulting several colleagues of career (particular mention for MarujeoSEM Marketineo) and doing several exams, I’m going to inform you concerning the adaptation that I have made for this new model of Google Tag Manager. I can’t touch upon probably the most trivial steps comparable to the place and how to set up the GTM code or the Google Analytics code, since that does not change and you continue to have it in the aforementioned entry. Now sure, let's go there!
- 1 1. Varibals (previous Macros)
- 2 2. Activators (previous Guidelines)
- 3 three. Labels
- 4 4. We save the modifications and publish the container
1. Varibals (previous Macros)
We must create the variable Exception of sort 'cookie of origin':
Acceptcookies might be a technical cookie (subsequently, being technical, it isn’t subject to compliance with article 22 of the LSSI and we will install it with out prior notice to the consumer) that may permit us to know if the consumer has not but accepted using cookies or , on the contrary, it has already accepted it.
In addition, we should activate the following built-in variables:
2. Activators (previous Guidelines)
We’ll create 4 activators:
In the earlier version of GTM, we detected clicks on hyperlinks via the event processor, however in this new version that performance has disappeared. Now, we’ll do it by creating a Click activator:
Segmenting the clicks to “only links”:
And we configure it to be activated on all pages only if the consumer has not accepted using cookies. That’s, when “Page URL” matches the common expression. * And the variable Except is totally different from 'sure':
As we’ll see later, we’ll create a label that detects and launches an event (which I have referred to as acepcookies) when the consumer performs an acceptance action (click on link or scroll). When that happens, this activator can be liable for executing the Google Analytics code and launching one other tag that modifications the value of the cookie acepcookies to 'yes'.
To realize this, we created a customized Occasion sort trigger, with the next configuration:
We create an activator that detects if the consumer has not but accepted using cookies, with the following configuration:
Event: Page view
Activator sort: Web page view
Activate: on any web page when Exception isn’t equal to 'sure'.
Finally, we create an activator that detects if the consumer has accepted using cookies:
Choose Event: Custom Occasion
Occasion identify: acepcookies
Execute when Exception is equal to 'yes'
Now we solely have to create three tags: one that accommodates the Google Analytics code, one that puts the worth 'yes' to the cookie acceptscookies and one which detects when the consumer scrolls and launches the activator 'Event acepcookies':
3.1 Place acceptance
This “custom HTML” sort tag is a JQuery script that may create and install the acepcookie technical cookie with the value “yes”. You’ve the code by clicking right here
I had to make some slight modification of the unique code. Right here you could have the modified model, which is what you need to copy and paste:
* jQuery Cookie Plugin v1.3.1
* Copyright 2013 Klaus Hartl
* Released under the MIT license
if (typeof define === 'function' && define.amd)
// AMD. Register as anonymous module.
// Browser globals.
var pluses = /+/g;
return decodeURIComponent(s.replace(pluses, ' '));
if (s.indexOf('"') === 0)
// This is a quoted cookie as according to RFC2068, unescape...
s = s.slice(1, -1).replace(/"/g, '"').replace(//g, '');
s = decode(s);
return config.json ? JSON.parse(s) : s;
var config = $.cookie = function (key, value, options)
if (value !== undefined)
options = $.extend(, config.defaults, options);
if (typeof options.expires === 'number')
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
value = config.json ? JSON.stringify(value) : String(value);
return (document.cookie = [
config.raw ? key : encodeURIComponent(key),
config.raw ? value : encodeURIComponent(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
var cookies = document.cookie.split('; ');
var result = key ? undefined : ;
for (var i = 0, l = cookies.length; i < l; i++)
var parts = cookies[i].split('=');
var name = decode(parts.shift());
var cookie = parts.join('=');
if (key && key === name)
result = decodeAndParse(cookie);
result[name] = decodeAndParse(cookie);
config.defaults = ;
$.removeCookie = function (key, options)
if ($.cookie(key) !== undefined)
// Must not alter options, thus extending a fresh object...
$.cookie(key, '', $.extend(, options, expires: -1 ));
$.cookie('aceptacookies', 'yes', expires: 365, path: '/' );
Attention to the activation guidelines. If we click on the "More" choice, at this level it is best to have one thing like this:
Choose: Click on on link and Occasion acepcookies
three.2 Detects scroll
This "custom HTML" sort tag detects, as its identify indicates, when the consumer scrolls within our Net:
The code, to which I have additionally made a slight modification, you will have it here:
window.addEventListener('scroll', testScroll, false) :
var scrollCount = 0;
if (scrollCount == 2)
dataLayer.push( 'event': 'aceptacookies');
In this case, the activator might be NOAceptaCookies, so that it is just executed if the consumer has not yet accepted using cookies. Otherwise, its execution isn't vital.
3.three Universal Analytics Code
As in the earlier model of GTM, if we would like the Google Analytics cookie not to be installed without the consumer's consent, we must management it from GTM. Subsequently, we must take away it from the Net (when you have not yet carried out Analytics on the Net, there's nothing to delete) and create a label in GTM for it.
Say that, if what you want is to block other cookies than Google Analytics, that is the place you should make modifications and create a label with the code that installs these cookies (and remove them from the Net) in an analogous method as we do on this label.
Although GTM has pre-defined tags for Google Analytics, we'll select to copy and paste the monitoring code right into a "custom HTML" tag to have absolute control of the code.
Particular attention to the activation options:
We choose "Click on link", "Event acepcookies" and "SIAceptaCookies". On this method, the tag with the Google Analytics code will only be executed when the consumer clicks on a link, when the occasion accepts cookies that's launched when the consumer scrolls or if the consumer has beforehand accepted using cookies. . That is to say…
4. We save the modifications and publish the container
At this level, if we have now created the macro, rules and labels appropriately, we should always have something like this:
If at this level, the whole lot has gone properly, we now have just one thing left: SAVE THE CHANGES. It seems a truism, however GTM is anything however intuitive. For the modifications made to take impact, we must PUBLISH.
You'll be able to see a simple technique to examine when you have executed nicely and it works, at the finish of the original entry, precisely ... HERE!
And here's the ticket in the present day! I hope you could have served to catch up with the completely satisfied regulation of cookies and do not hesitate to share freely with whomever you like.
How to meet #leydecookies with Google # TagManagerV2 #lopd #Analytics Click To Tweet