zesty.io

Product

Use Cases

Integrations

Learn

Setting up Google Analytics for GDPR

How to be GDPR compliant with Google Analytics and Tag Manager using cookies and Javascript

We are going to check for a cookie named trackMe, if that cookie is null, we will show a popup asking the user if its ok to run GA, if the cookie value is true, we will run the GA script. If it is false, we do not run the GA script.

Step 1: Prepare Javascript to Check and Set Cookies

Javascript can access cookies, use these handy functions to set and check a cookie value. You'll want to load this function up first. This is vanilla Javascript, no framework needed.

Step 2a: Remove the GA (analytics) and GTM (tag manager) auto loading

Remove all the GA and GTM script tags stuff from the loader view file in the editor and save it. If you are using Zesty.io GA auto loader, you need to delete the setting. You can delete the GA settings in config > settings > analytics.

Step 2b: Create an Analytics Loading Function

We will want to setup a function to run Google Analytics, that way we can run it as a user accepts, and run it when we check the trackMe cookie.

Step 3: Create CSS/HTML popup for unrecognized visits.

In your theme, create a page or panel with language about the cookies and some toggle buttons. You will check a cookie using the getCookie function to load or not load this.

HTML/CSS popup, connect the buttons to your javascript functions.

Setup on clicks to the buttons that setup a cookie trackMe to store the user's preference.

Step 5: Check the

If the trackMe cookie is true, we will want to run the load

Testing Cookies

Use Google Chrome and download the EditThisCookie plugin. Once installed, a cookie icon will appear on your toolbar. Use that to check if the trackMe cookie is there, you can also delete the cookie there.

Connect with Content Experts

Book a free 15-minute consultation with a content expert. Discuss your application, pain points and requirements. Understand how Zesty's lower total cost of ownership, features, functionality can elevate your business by creating extraordinary digital experiences.

Trusted By

zesty customer logo Sonyzesty customer logo Rocket Leaguezesty customer logo Singlifezesty customer logo Acornszesty customer logo Phoenix Sunszesty customer logo Wattpadzesty customer logo Corner Shopzesty customer logo Bjs

G2 MOMENTUM LEADER

zesty customer logo zesty customer logo zesty customer logo zesty customer logo

Enter your details to connect with a Content Expert

First Name

Last Name

Email

Phone (optional)

Company

Please tell us about your project (optional)