# Google Consent Mode v2 implementation

**URL:** <https://community.hubspot.com/t/google-consent-mode-v2-implementation/101859>\
**Category:** APIs & Integrations\
**Tags:** starter\
**Created:** [March 6, 2024, 3:07pm UTC](https://community.hubspot.com/t/google-consent-mode-v2-implementation/101859 "2024-03-06T15:07:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RYeliseikin](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@RYeliseikin](https://community.hubspot.com/u/RYeliseikin)\
**Post date:** [March 6, 2024, 3:07pm UTC](https://community.hubspot.com/t/google-consent-mode-v2-implementation/101859/1 "2024-03-06T15:07:36Z")

</div>

Hello  
**Description:**  
I tried to implement the Google Consent Mode v2 solution from the hubspot for our [marketing agency](https://www.w-4.ch/de/) website.  
We use a Hubspot Cookie banner  
I turned on the integration according to

> **[Understand and implement Google Consent Mode](https://knowledge.hubspot.com/privacy-and-consent/support-google-consent-mode-v2#turn-on-google-consent-mode-v2)**
>
> Learn how to support Google Consent Mode v2 natively within HubSpot.

I even tried to insert JS code from [here](https://developers.hubspot.com/docs/api/events/cookie-banner#hs_cos_wrapper_widget_1707409100922) in the \<head\>  
the same  
**Bug:**  
But there is a bug.  
When I try to run and verify via GoogleTagManager how the banner convey variables ‘analytics\_storage’, ‘ad\_storage’,‘ad\_user\_data’, ‘ad\_personalization’  
I see that when the consent on the banner is granted - GTM works. But I do not see these variables in the consent tab  
If the consent on the banner is not granted - GTM does not work at all - but in fact we must see “ **denied** ”  
**Question:**  
Do I have to wait for the Hubspot solution?  
Or maybe I have I edit the hubspot banner code manually :  
-set on click functions for example

function consentGrantedAdStorage() {

```
gtag('consent', 'update', {

  'ad\_storage': 'granted'

});

```

}

\</script\>  
Or probably it is worth to insert the code in the \<head\> manually?:

\<script\>

// Define dataLayer and the gtag function.

window.dataLayer = window.dataLayer || [];

function gtag(){dataLayer.push(arguments);}

// Set default consent to ‘denied’ as a placeholder

// Determine actual values based on your own requirements

gtag(‘consent’, ‘default’, {

```
'ad\_storage': 'denied',

'ad\_user\_data': 'denied',

'ad\_personalization': 'denied',

'analytics\_storage': 'denied'

```

});

\</script\>

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [March 7, 2024, 4:28pm UTC](https://community.hubspot.com/t/google-consent-mode-v2-implementation/101859/2 "2024-03-07T16:28:18Z")

</div>

Hi, @RYeliseikin 👋 Thanks for your question. If you believe you’ve found a bug, you might post about it [here](https://community.hubspot.com/t5/HubSpot-Ideas/Re-Google-consent-Mode-v2-through-Hubspot-Cookie-Banner-2024/idi-p/903088), as the PM for this rollout is active in the thread.

As for troubleshooting steps:

- have you already used [GTM’s Preview and Debug mode](https://support.google.com/tagmanager/answer/6107056?hl=en) to verify that the consent status variables (analytics\_storage, ad\_storage, ad\_user\_data, ad\_personalization) are correctly being updated?
- have you tried adding custom onClick functions that trigger gtag(‘consent’, ‘update’, {…}) with the appropriate consent statuses?
- when adding to the \<head\> section, have you tried placing some scripts below the HubSpot banner script or ensuring they’re executed in response to specific consent events?

Thanks for the additional information! — Jaycee

---

<div class="post-metadata">

**Author:** ![RYeliseikin](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@RYeliseikin](https://community.hubspot.com/u/RYeliseikin)\
**Post date:** [March 11, 2024, 11:14am UTC](https://community.hubspot.com/t/google-consent-mode-v2-implementation/101859/3 "2024-03-11T11:14:20Z")

</div>

Thank you, [Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074)  
**Answers**  
1. Yes, I tried . I used GTM’s Preview Mode  
-In one case ([w-4.ch](https://www.w-4.ch/de/)) - I cannot see the gtm container

 ![RYeliseikin_0-1710138227552.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/5/2/52d93ec72595fb3b371978d44e10ee8d1b3a89a8.png)

-For the second website ([https://www.zurzachcare.ch/](https://www.zurzachcare.ch/)) - after I closed the coockie banner once - I did not see it again .  
And in GTM I see the message **"Consent not configured**

**Default consent state has not been set yet"**

 ![RYeliseikin_1-1710138995765.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/a/2/a2ced7f4a759ecdc5c15448e2d3afc2593a29c83.png)

2. Did not try.  
3. Yes below - the section **Site header HTML** places scripts below the HS banner code  
I tried to insert JS code from [here](https://developers.hubspot.com/docs/api/events/cookie-banner#hs_cos_wrapper_widget_1707409100922) in the \<head\>

**Questions:**  
1. For websites that use a Hubspot banner - should we take some special steps in GTM related to the consent?  
2. the second question: If we deny cookies - GTM does not work at all (in the Preview mode)  
I checked the news about [the final relise](https://community.hubspot.com/t5/HubSpot-Ideas/Re-Google-consent-Mode-v2-through-Hubspot-Cookie-Banner-2024/idi-p/903088)  
But it works with cookies - might it be that it does not work with GTM?  
For example a piece of code on our website

 ![RYeliseikin_2-1710155367176.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/6/d/6d9da48b1866991b0208ed2a8e87a8ae5297b32e.png)

I mean in case of **window.\_hsGtmLoadOnce = true** the code is not executed. I.e. it is being executed 1 time and then returns.

if(window.\_hsGtmLoadOnce) {  
return;  
}

But it means that GTM id not loaded the 2 time and more, Yes?  
Thank you
