🚨 Note: All standard Universal Analytics properties will stop processing new hits on July 1, 2023. 360 Universal Analytics properties will stop processing new hits on October 1, 2023. That’s why it’s recommended to start using Google Analytics 4.
GDPR has raised the question of how we could enable and disable Advertising Features in Google Analytics via Google Tag Manager.
Previously there was no good way of doing this programmatically, but in this Live Stream we want to take a look at the new feature of allowAdFeature flag in the Field to Set options to turn this on/off based a cookie consent.
In this video, I’m going to show you how you can connect your cookie consent form with the AllowAdFeatures from Google Analytics. All and more, coming up.
Welcome back to another video of measureschool.com teaching you the data-driven way of digital marketing. My name is Julian. And on this channel, we do marketing tech review, tutorials and the occasional live stream. So if you want to be here live, then consider subscribing and also click that bell notification so you will be notified once we go live. Now today, I want to talk about with you about the Allow advertising features in Google Analytics and how to connect it to your cookie consent form.
We’ve done a video previously on GDPR compliance with Google Analytics. And that video, I basically showed you how to turn off all the different features of Google Analytics to become GDPR compliant. You only do the base tracking that Google Analytics actually allows you to do by default. And in this video, or I got a lot of questions on how to actually turn on the advertising features of Google Analytics. That’s the demographics reports, but also building remarketing audiences by a Google Analytics programmatically. So you’ll be able when somebody clicks on a cookie consent form and says, Yes, I accept to these terms that you will be sending out that data again to Google Analytics, to double click and to Adwords.
Now, this was a bit tricky previously, because Google Analytics didn’t have a programmatic flag to actually say, Okay, I want to turn this on, I want to turn this off for this user. But now they have built in a new field that we can trigger with Google Tag Manager in order to connect the form to the actual advertising features. So without further ado, let’s dive into this training.
GDPR Features to Enable in Google Analytics
First of all, what are we talking about here? When we have the ability in Google Analytics apart from the website and clickstream tracking that we have set up with the Google Analytics js code to send our data to different other services. One of the services is double click, which gathers information and then feeds it back into Google Analytics through the demographics report. So you can get data like the rough estimates of the age of the users or their interest, agenda, for example, here as well. And this is a feature that you have to turn on.
The other feature that you need to specifically turn on is when you have an audience here, you can always turn that audience into a remarketing audience. So you can build a remarketing audience that then sent this over to AdWords and you can remarket to users directly from Google Analytics. Now, these are not really third services since Google is one company. But it goes out of the scope of Google Analytics. So previously, you had to turn these features on in your tracking information, you have your data collection here.
What is AllowAdFeature?
And here are two features, the remarketing features, and the advertising features that you had to turn on in order for this data to be gathered. That will turn something on in your tracking code, and then send that data over to these other services and remarket the user.
Now in GDPR terms, you might want to turn these features off, because the user has consented to actually being tracked through these other services and especially giving that data over to these other services. But it was all right if you actually informed the user about it, and got his explicit permission. And once you have the permission, you may want to turn these features on again.
Unfortunately, that was not a programmatic way to do this in Google Analytics to say to Google Analytics, okay, now the user has consented, please now collect that data. But they have now introduced a new field in the analytics JS library that will allow us to turn these on programmatically. And this is the AllowAdFeatures. And it’s a line of code that you would need to programmatically put into your tracking code. Or you can deploy this via Google Tag Manager as well. So whenever somebody has consented to being tracked, you could deploy this tracking code and therefore be able to track this data in Google Analytics and build remarketing audiences.
How to Connect Cookie Consent Form to AllowAdFeature
Make a Cookie-Consent Form
There might be other more sophisticated platforms out there. Nonetheless, the techniques that I want to show you right now about how you can actually connect that it to Google Analytics. So if you have a different cookie consent form, just use that and see how the cookie actually gets set. Now, once I click on this Got it button, a cookie be will be set in my browser. So it can open up the developer tools, which will find up here under more tools we have the developer tools. And then I can go to the application settings, up here is the tab applications and on the left side, we’ll find our cookies down here that are set on our website. Now we have some Google Analytics cookies, but also a new cookie called cookie consent dismissed and it has the value of Yes.
So if I reload this page now, we still have that cookie, it is safe on our browser, and we don’t see our cookie consent form anymore. Now, if I delete this cookie and reload the page, obviously, this cookie consent form will reappear. So here we have the cookie consent form. So it just checks whether it was agreed to or not. And then it will show it or not. For us, we can use that in our Google Analytics deployment. Now, again, if I click on Got it here, I can click on the refresh button for the cookies. And we should see here or cookie consent dismissed is now set to Yes.
Turn on Remarketing and Advertising Reporting Features
Now, how can I tell Google Analytics once the user has clicked on God it that he should deploy this advertising features? Well, in Google Analytics itself, you will need to first of all turn on these features. So they need to be toggled on. There’s also another way to do this in Google Tag Manager. But once you decide to turn this on, you can do that on the server side in Google Analytics directly. So you don’t have to mess with Google Tag Manager itself. By default now, all of these people who get tracked by Google Analytics will be also sent over that information. And that’s something we want to avoid. We want to only send it over when somebody has actually agreed to this. So we need to build something into the measurement side extra to this to allow this advertising features only for certain users. And let’s dive into Google Tag Manager.
Create a GA Page View Tag
First of all, I have deployed here a Google Analytics page view tag pretty simple and I haven’t chosen to use the Google Analytics settings variable, you can definitely do that. And it sends us over to my account. And now we have here a field to set option. Now in this filed to set option, we can modify this to enter our AllowAdfeatures. Now, this is the name of the field and we can set it to a value, this value is either true or it’s false. Now, by default, the value is actually set to true.
So the allow advertising features are sending over this data. And if we now wanted to change this programmatically based on the user input, we would obviously need to somehow have access to the cookie and then pull it into our Google Analytics field. For now, let’s save this and try this out on our page. First of all, just as field and see what the console says, we have, well, let’s go back into our Google Tag Manager and actually put Google Analytics or our Google Analytics tag in a certain mode. And that mode is under Advanced configurations we’ll set the use debug version to true. And that will give us some useful information into the console.
We could also do this by the GA debugger extension, which I also have installed. But it’s nicer to do this on where people can actually try it out. And here, we see what data was actually sent over to Google Analytics. And we can see this tracker set AllowAdFeatures to true which is by default, anyway, set to true. So it doesn’t really make a difference. Now, the data would be sent over to Google Analytics to AdWords and to double click so we can get that information into Google Analytics. All right, now, we want to set this off from a perspective of the the user if the user hasn’t yet agreed to our cookie consent form. How would we do that? First of all, we would need to have access to our cookie right here.
Build 1st-Party Cookie Variable
How can we get access with Google Tag Manager to our cookies? Well, there is a variable that’s built into Google Tag Manager, where we’ll just go to variables over here and click on a new variable. And as a type will choose the first party cookie. And that’s how you can get access to your cookies that are installed on your browser. And for us, we can just take our cookie name here. In our case, let’s go back and see this is the cookie name Cookie Consent dismissed. Let’s copy this and put that in here and click save. Well, I’m going to give this a name as well. So we know what it is. And set Refresh. Refresh our page. Let’s close this. And if you go to variables now, click on an event, we see that our cookie was set to Yes. So our Google Tag Manager now picks up the value of the cookie and it is set to Yes, and in this case, I want to send over the AllowAdFeatures. Now, one hurdle.
The next hurdle we need to take is actually that our field our allow advertising features field only accepts values that are true or false. It’s a boolean value.
Create a Look-Up Table Variable
So we can feed into this field the yes or no, we would actually intelligence furthers into a yes or into a true or false. How can we do that in Google Tag Manager? There is another functionality of a variable, which is the lookup table variable. And the lookup table variable basically takes an input and rewrites that into the output that you want. In our case, we can go to the a new variable, build a new lookup table variable, right here, lookup table, it’s what’s called. And here’s where we take our input variable. In our case, that would be our cookie, and whatever is inputted in that cookie. So if the input is yes, we want to actually turn us into true. If the input is oops deleted, true. If the input is no, we want to turn this into false, which is not really a value because we didn’t see that in our cookie, we can’t really set this value to know no.
So let’s go over here, undefined, and set that to false. Let’s rewrite this into a lookup table for our cookie consent. All right, let’s save this. And Refresh. Refresh our page. And now let’s look into our variable, we have our cookie consent dismiss is undefined. And therefore our lookup table variable will be set to false. What happens when we click on Got it? Well, first of all, nothing happens. Because we don’t have a new event in here. If we reload the page, now that the cookie was set, we should a new value in our variables the cookie is set to Yes. So our lookup table is set to true. So now we have rewritten the inputs here into true or false.
Apply Look-Up Table Variable Value in GA Page View Tag
And that’s something we can now use in our Google Analytics tag. So let’s go over to tags and go to GA page view, and then click on the field to set options here.
And we’ll set our value not by default to true, but to a variable that we can access here. And this is our lookup table variable. So let’s save this, record refresh. And I’m gonna first of all, clear the cookie again for our test case. Now that’s cleared I’m going to reload the page and Google Analytics fires. Now, what data is actually sent over? We can see that in our developer console because we are still in this debug mode. And we see that our AllowAdFeatures was turned to false we haven’t yet agreed. In every consecutive pageview, if I go around the page without clicking on the gutter button here, I will not be sending that data over to double click and I won’t be setting a remarketing pixel. So that data for this user at least because it hasn’t agreed yet is not available in analytics will not go into our audience demographics reports and also not in our remarketing list.
Now once the user has clicked on Got it, every consecutive page view, so if I go to the next page, or just reload the page, this will be set to true automatically. And as long as the cookie is sticking around. So if the user doesn’t go to another device, or doesn’t clear his cookies, or goes into a private browsing mode, we’ll see still be able to use that user or the data will still be sent over to our advertising features, such as a double-click, and Adwords. So it works as expected. And this is really how you can install this and connect your cookie consent form to this new AllowAdFeatures.
Bonus GDPR Tips
Now in the end, first of all, let’s get rid of our debug version True. So it doesn’t always log this to the console. And the other thing that I need to tell you if you want to deploy this is obviously to use a Google Analytics settings variable, then you only have to configure this field to set option once in your Google Analytics settings variable. And if you have any other tags, such as event tags, this obviously also needs to be set.
But with the Google Analytics settings variable, you only have to do it once in the variable itself, then reuse that variable inside of your Google Analytics tag. I didn’t do this year because we just have a one-page view tag and obviously, if you’re done with your tracking deployment, everything works as expected. Submit this as a version and give this always a name. And publish this to all your users so it goes live.
All right, so there you have it. This is how you can build in your or connect your cookie consent form with the help of Google Tag Manager to the AllowAdFeatures in Google Analytics. Now, I’d love to hear from you. What precautions Have you taken when it comes to the GDPR? Do you have more complicated cookie consents form? How have you handled that previously? And if you haven’t yet, then why not consider subscribing right over there because we bring you new videos just like this one every week.
Learn how to install a cookie consent banner on your website with the help of Google Tag Manager with our handy guide.