From the course: Advanced Google Tag Manager

Complying with GDPR and CCPA cookie consent - Google Tag Manager Tutorial

From the course: Advanced Google Tag Manager

Start my 1-month free trial

Complying with GDPR and CCPA cookie consent

- [Narrator] Any website with users in California or Europe which is most of us, need to be able to collect consent for tracking. This is due to the CCPA and GDPR privacy legislation which gives users a right to opt out of being tracked. You can see on this website we have a cookie banner on the bottom right which let's users decline or accept tracking or they could click to learn more. If we click accept, the banner goes away. And if we right click and inspect element, we can see in storage sets a cookie called tracking consent accepted or tracking accepted, okay. If I delete this cookie and then refresh the page, you'll see that the banner comes back. So how do we make our banners more interactive like this? If we go to Google tag manager, then create a new tag, tag in configuration, custom HTML, then it'll give you this script here. Paste in the script. Now the first part of the script is really just to load a library that lets us work with cookies. Then we set the cookie name to tracking accepted. Then it's checking if the cookie exists. If the cookie is not undefined, meaning it does exist. Then we're going to take the tracking consent banner and remove it. We're also going to add a click listener, onto the accept dash tracking class. Meaning when someone clicks the button, this will happen, the cookie will be set with the cookie name and the value of okay expiring in 180 days. So that's the script for how to make this more dynamic. But what do we do once we have this cookie value? First one, you get two variables and then we want to scroll down to new variable configuration, first party cookie, and then we want to put the cookie name in here. So it's checking, accepted, just let me call this X, tracking, accepted and then hit save. Now, if we go to triggers, let me say new, just let me say, trigger configuration, page view only on some page use. And it's going to be just on the page use where tracking accepted equals, okay. So now we have a trigger that will only fire if the value of tracking accepted is okay. If that cookie is not there, it's not going to fire. So this is going to be page use with tracking, accepted. Now that we have that whenever we file our tags, so for example, if we set up Google analytics we could choose that as the trigger now instead of old pages. So we're going to say page user tracking, accepted. And that way, we won't be far in Google analytics unless the user accepts tracking, we could also use this for Facebook or any other tag that we need in order to respect the user privacy. Setting the cookies, this can save you from a lot of legal issues and trouble, and really help you respect the user's privacy, especially in locations where legislation demands It.

Contents