# Google Consent Mode: analytics\_storage denied

**URL:** <https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405>\
**Category:** Data collection and tags\
**Created:** [December 22, 2023, 10:00am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405 "2023-12-22T10:00:49Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![ValPiwik](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@ValPiwik](https://community.piwik.pro/u/ValPiwik)\
**Post date:** [December 22, 2023, 10:00am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/1 "2023-12-22T10:00:49Z")

</div>

Hello,

I implemented the Google consent mode through the following process: [Google consent mode integration | Piwik PRO help center](https://help.piwik.pro/support/integrations/google-consent-mode-integration/)

When I test with the Google Tag Assistant, it works well for the ad\_storage.  
For the analytics\_storage, on the first landing page, it works. But, if I change of page, it switch from granted to denied…

Could you help me?

Many thanks,

---

<div class="post-metadata">

**Author:** ![Daniel\_Twork](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/daniel_twork/32/498_2.png) [@Daniel\_Twork](https://community.piwik.pro/u/Daniel_Twork)\
**Post date:** [December 22, 2023, 1:04pm UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/2 "2023-12-22T13:04:16Z")

</div>

Hi @ValPiwik,

I will try to help you however it needs a clarification. What technology are you using to render the page view?

Kind regards

---

<div class="post-metadata">

**Author:** ![ValPiwik](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@ValPiwik](https://community.piwik.pro/u/ValPiwik)\
**Post date:** [January 8, 2024, 9:33am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/3 "2024-01-08T09:33:28Z")

</div>

Hello @Daniel_Twork

Very late answer (holidays), apologize.

I’m on Wordpress, Knockout and React.  
It depends on the part of the website.

In this specific case, I checked on Wordpress.

Moreover, I have the following issue in the console:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/1/1fee7488855854f599f8551d88cc4195b5e453ef.jpeg)

Thank for your help

---

<div class="post-metadata">

**Author:** ![ValPiwik](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@ValPiwik](https://community.piwik.pro/u/ValPiwik)\
**Post date:** [January 12, 2024, 7:43am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/4 "2024-01-12T07:43:14Z")

</div>

kindly reminder 🙂 I’m still looking for help

many thanks 😃

---

<div class="post-metadata">

**Author:** ![Daniel\_Twork](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/daniel_twork/32/498_2.png) [@Daniel\_Twork](https://community.piwik.pro/u/Daniel_Twork)\
**Post date:** [January 12, 2024, 12:11pm UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/5 "2024-01-12T12:11:08Z")

</div>

@ValPiwik Thank you for the information, we still need time to consider the problem, I will try to help you, but at the moment it seems that the problem is by race condition. I will reply next week with what we have found out!

---

<div class="post-metadata">

**Author:** ![ValPiwik](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@ValPiwik](https://community.piwik.pro/u/ValPiwik)\
**Post date:** [January 23, 2024, 10:35am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/6 "2024-01-23T10:35:26Z")

</div>

Hello @Daniel_Twork ,

Have you found something?

Many thanks 🙂

---

<div class="post-metadata">

**Author:** ![Daniel\_Twork](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/daniel_twork/32/498_2.png) [@Daniel\_Twork](https://community.piwik.pro/u/Daniel_Twork)\
**Post date:** [January 23, 2024, 10:49am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/7 "2024-01-23T10:49:11Z")

</div>

Hi, I have successfully implemented this liking following our instructions. The problems you may be experiencing are probably not directly due to Piwik PRO, I would look for the cause in the Google Tag implementation. How do you load this library? Do you ensure that it is available immediately?

---

<div class="post-metadata">

**Author:** ![ValPiwik](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@ValPiwik](https://community.piwik.pro/u/ValPiwik)\
**Post date:** [January 25, 2024, 8:03am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/8 "2024-01-25T08:03:31Z")

</div>

Hello,

Thank you for your feedback.  
I think the issue is linked to the error message “gtag is not defined”.  
It is weird because I’m using GA4 and Google Ads, so my Gtag is implemented.

---

<div class="post-metadata">

**Author:** ![ValPiwik](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@ValPiwik](https://community.piwik.pro/u/ValPiwik)\
**Post date:** [February 5, 2024, 10:06am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/9 "2024-02-05T10:06:07Z")

</div>

Hello,

any idea?

Many thanks,

---

<div class="post-metadata">

**Author:** ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)\
**Post date:** [February 5, 2024, 10:38am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/10 "2024-02-05T10:38:59Z")

</div>

Hi @ValPiwik,

The error we see in the attached screenshot most likely indicates that the default consent settings are not set before Piwik PRO updates them.

Is the default consent state described in [this Google article](https://developers.google.com/tag-platform/security/guides/consent#tracking_consent_state) added on every page? You can send me the page URL or add it here if you want.

By the way, we have [recently updated the GCM article](https://help.piwik.pro/support/integrations/google-consent-mode-v2-integration/), so it might look a bit different.

---

<div class="post-metadata">

**Author:** ![ValPiwik](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@ValPiwik](https://community.piwik.pro/u/ValPiwik)\
**Post date:** [February 13, 2024, 11:16am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/11 "2024-02-13T11:16:06Z")

</div>

Hello @anthonybartczak,

I still have the same issue:

```auto
Uncaught ReferenceError: gtag is not defined at googleConsentModeMapping

```

And it makes sense

```auto
<script>
    function googleConsentModeMapping(consents) {
        if ({{ Consents }}) {
            var consObj = {};
            Object.keys(consents).forEach(function(consent) {
                consObj[consent] = ({{ Consents }}.current_state[consents[consent]] === 1) ? 'granted' : 'denied';
            });
            gtag('consent', 'update', consObj);
        }
    }
 
// Call the function with specific consent mappings; these mappings can be adjusted as needed
    googleConsentModeMapping({
        "ad_storage": "remarketing",
        "ad_user_data": "remarketing",
        "ad_personalization": "remarketing",
        "analytics_storage": "analytics"
    });
</script>

```

nowhere gtag is defined in the code provided in the support.

I can provide you the URL, but you will see nothing, I pause the tag to avoid website issue…

---

<div class="post-metadata">

**Author:** ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)\
**Post date:** [February 13, 2024, 11:28am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/12 "2024-02-13T11:28:36Z")

</div>

> [@ValPiwik](#):
>
> nowhere gtag is defined in the code provided in the support.

That is correct. Both our and Google documentation suggest to embed the default gtag settings on the website.

---

<div class="post-metadata">

**Author:** ![mbaersch](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mbaersch/32/35_2.png) [@mbaersch](https://community.piwik.pro/u/mbaersch)\
**Post date:** [February 13, 2024, 11:40am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/13 "2024-02-13T11:40:44Z")

</div>

Hm… as Consent Default values are only needed when Advanced Consent Mode is used and everything works perfectly when there is only an update as long as it is done before tags fire, it should be no problem to define the gtag function if it is not already defined and / or push to the dataLayer directly(?)

That would avoid this error in case of Basic Content Mode usage and I can see no caveat by adding this fallback to the template. Or am I missing something?

best,  
Markus

---

<div class="post-metadata">

**Author:** ![ValPiwik](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@ValPiwik](https://community.piwik.pro/u/ValPiwik)\
**Post date:** [February 13, 2024, 11:48am UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/14 "2024-02-13T11:48:42Z")

</div>

Hello @anthonybartczak , @mbaersch ,

Not sure to follow you 🙂

I have several Google Tags implementend on all pages of my website:

- GA4
- Google Ads

On top of them, I added the Google Consent tag

```auto

<script>
    function googleConsentModeMapping(consents) {
        if ({{ Consents }}) {
            var consObj = {};
            Object.keys(consents).forEach(function(consent) {
                consObj[consent] = ({{ Consents }}.current_state[consents[consent]] === 1) ? 'granted' : 'denied';
            });
            gtag('consent', 'update', consObj);
        }
    }
 
// Call the function with specific consent mappings; these mappings can be adjusted as needed
    googleConsentModeMapping({
        "ad_storage": "remarketing",
        "ad_user_data": "remarketing",
        "ad_personalization": "remarketing",
        "analytics_storage": "analytics"
    });
</script>

```

I tried to change the priority order, but I still have the issue.

---

<div class="post-metadata">

**Author:** ![ValPiwik](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@ValPiwik](https://community.piwik.pro/u/ValPiwik)\
**Post date:** [February 13, 2024, 12:33pm UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/15 "2024-02-13T12:33:16Z")

</div>

I followed this process: [How To Integrate Google Consent Mode v2 & Piwik Pro [No GTM]](https://dumbdata.co/post/google-consent-mode-v2-integration-for-piwik-pro/)

And I no longer have the issue “gtag is not defined”

🙂

---

<div class="post-metadata">

**Author:** ![mbaersch](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mbaersch/32/35_2.png) [@mbaersch](https://community.piwik.pro/u/mbaersch)\
**Post date:** [February 13, 2024, 1:09pm UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/16 "2024-02-13T13:09:54Z")

</div>

adding this line at the top your tag’s script code should prevent this error without the need for code changes as long as only Basic Mode is used:

window.gtag = window.gtag || function(){dataLayer.push(arguments)}

Values will end up in the dataLayer and should get processed as soon as a Google Tag (GA4 or Ads) loads on the page.

---

<div class="post-metadata">

**Author:** ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)\
**Post date:** [February 13, 2024, 1:44pm UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/17 "2024-02-13T13:44:28Z")

</div>

> [@mbaersch](#):
>
> Hm… as Consent Default values are only needed when Advanced Consent Mode is used and everything works perfectly when there is only an update as long as it is done before tags fire

That was one of the reasons why we didn’t include the defaults in the code.

- We didn’t want to skip the defaults part in case there is a failure with the Piwik PRO container (e.g. outage, blocking)
- We wanted them (the defaults) to be on top of any potential tool that could either make use of them or modify them.

As you’ve mentioned - it’s of course possible to add those in the integration tag but we can’t really advise on doing so because of the mostly asynchronous manner of Piwik PRO Tag Manager and reasons above.

---

<div class="post-metadata">

**Author:** ![mbaersch](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mbaersch/32/35_2.png) [@mbaersch](https://community.piwik.pro/u/mbaersch)\
**Post date:** [February 13, 2024, 1:58pm UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/18 "2024-02-13T13:58:59Z")

</div>

fair point. But I can still see no reason why this line should not be added to the default tag code. The asynchronous manner does have no impact in this case - it is an addition inside the tag code and will do no harm if a consent initialization is present.

---

<div class="post-metadata">

**Author:** ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)\
**Post date:** [February 13, 2024, 2:02pm UTC](https://community.piwik.pro/t/google-consent-mode-analytics-storage-denied/3405/19 "2024-02-13T14:02:43Z")

</div>

> [@mbaersch](#):
>
> But I can still see no reason why this line should not be added to the default tag code.

Yes, you are right - I was mentioning adding defaults to the page and forgot to give an answer to this. We’ll update the docs.
