Free Claim your free tracking audit, I’ll handle your behind all technical setup to run paid ads.

How to Easily Setup Cookie Consent Banner for Google Consent Mode v2

cookie-consent GDPR Google Consent V2 cookie consent bannar setup via google tag manager ga4

What is Cookie Consent?

Collecting user data without permission is not allowed. Cookie consent is the way to ask users for permission to track their data and use cookies on their browser/device, usually shown in a banner or pop-up.

I will show you how to set up cookie consent with Google Tag Manager for both browser and server-side. You can also use a plugin if you prefer.

šŸ“ Step 1: To implement a cookie consent banner effectively, we should choose a Google Partner CMP. These CMPs ensure compliance with data protection regulations, integrate seamlessly with Google’s Consent Mode, and enhance user experience through customizable solutions.

Most Popular Google Partner CMPs

šŸ“ Step 2: The CMP (Cookie Management Platform) we choose will have the option to active Google consent Mode v2 in its GTM Template. This option must be enabled; otherwise, we will have to manually grant cookie consent.

The purpose of this is to automatically update once the user has given cookie consent.

google-consent-mode-v2

šŸ“ Step 3: Set the CMP Trigger to Consent Initialization because this fires first in GTM.

cookie_consent-triggr-in-google-tag-manager

Earlier we had ad _ storage = “Granted.” But in the last update V2, two more things have been added.

Primary Permissions

Marketing: ad_storage =’granted’ /Ā  ‘denied’ => Consent for Ads related data collection and interaction with cookie related Ads like Google Ads, Facebook Ads


In the last update march 2024: ad_user_data, ad_personalization also involved here ad_user_data: It is related toĀ  advertising audiences with user data. ad_personalization: Is related to retargeting ads

Statistics – analytics_storage = ‘granted’ / ‘denied’ => Consent for Analytics related data collection and interaction with cookie related analytics like Google Analytics

– The update is known as GDPR Compliance and Google Consent Mode V2. And the thing to understand is that here (Cookie bot CMP) if we allow only Marekting, then three are allowed.

cookie_consent

With Advanced Method, if the user does not give consent, the tag will fire, but Google Internal will check all the parameters, in this case there are many problems such as: Purchase Event has gone, but the user parameters have not gone.Ā  Again, this will only work for Google products and will not work for 3rd parties such as Facebook, TikTok, etc.

There are two implementations for consent mode in Google Analytics:

Basic: If consent is not given, no tags will fire.

Advanced:

    • All tags will fire, but Google will collect partial data if consent is not given. You can find more information here

Ā 

    • This setup applies only to Google-related tags like GA4 and Google Ads. Does not work for 3rd party tags like Facebook Pixel, etc.

Ā 

    • The _ga tag will not be added.

Ā 

    • Numerous privacy experts have raised concerns about this arrangement. It is called the “gray method.”

Ā 

🟢 In Basic Method, we have a problem that First Event does not count, in this case we have a reporting problem. There are problems in various places like running ads, landing on the product page, but there are many other problems that can be easily understood by looking at the picture above.

  1. To solve this problem, we need to create a custom event (cookie _ consent _ update).
  2. Let’s add this to the main event trigger.
  3. In this case, a custom HTML tag is required when each event is fired twice in order to trigger 2.

Ā 

				
					<script>
/* 
 * Source: https://abdulkayium
 * LinkedIn: https://www.linkedin.com/in/abdulkayium/
 */

  window.isConsentCookie = document.cookie.includes('CookieConsent=');

</script>

				
			

Ā  Ā  Ā 4. and then we isConsentCookie Ā Create a JS Variable called and with a Custom Event during First Visit (cookie_consent_update) Add this.

iscookieconsent

🟢 Then the events are counted only once.

Now another problem is that if it is the first time when Product/Others page visit, then it doesn’t count, only page view count.

  • In this case for the rest of the events (cookie_consent_update) You need to copy the trigger again and create the trigger with that page URL and put it all in the event

Ā 

cookie consent

Server-Side Tracking with Cookie Consent v2āš™

There is a problem with server-side ad_storage After being ā€œgrantedā€ and if analytics_storage If ‘denied’ then (ad_storage) will not receive data because we send data to server side with Google Analytics.

Then we only Analytics/Analytics_storage is set up in advance so that even if you don’t give consent, the tags are fired in the web container.

We can see from the Event Data from the Server Container preview mode which permission the user has given, like:-Ā 

How Advanced Setup Data Collection Happened?Ā 

=> /g/collect?gcs=G1 [ad_storage][analytics_storage]

G100Ā  Ā Consent is denied for both ad_storage and analytics_storage.

G110Ā  Ā  Consent is granted for ad_storage and denied for analytics_storage.

G101Ā  Ā  Consent is denied for ad_storage and granted for analytics_storage.

G111Ā  Ā  Ā Consent for both ad_storage and analytics_storage is granted.

G1–Ā  Ā  The site did not require consent for ad_storage or analytics_storage.

1. Then we create a variable with Event Data.

cookei consent server side configuration variable

2. and those variables are configured with the event trigger and marketing issues and added like thisĀ 

cookei consent server side configuration variable 2

3. In the same way, Add kore of Analytics

cookei consent server side configuration variable 2

4. Now another problem is that the page_view is not counted on the server side in case of first visit.

5. In this case we are another GA4 Event in the Web Container (page_view) I make the name. and earlier GA4 ( Page View/Base Code ) Trigger the Cookie Consent Update Trigger with the new GA4 (page_view) eventĀ 

ga4

According to GDPR Recent Update (CMP) this option should be turned on and this code should be placed above the base code of GTM.

				
					<script>
/* 
 * Source: https://abdulkayium
 * LinkedIn: https://www.linkedin.com/in/abdulkayium/
 */
window['gtag_enable_tcf_support']=true
</script>


				
			

Thanks You šŸ™‚Ā  last update 11.31.2024

Top picks

Read our most popular articles of the month

Never Miss Another Conversion

Book a free growth call