Google Consent Mode: analytics_storage denied

Hello,

I implemented the Google consent mode through the following process: Google consent mode integration | Piwik PRO help center

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,

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

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:

Thank for your help

kindly reminder :slight_smile: I’m still looking for help

many thanks :smiley:

@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!

1 Like

Hello @Daniel_Twork ,

Have you found something?

Many thanks :slight_smile:

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?

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.

Hello,

any idea?

Many thanks,

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 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, so it might look a bit different.

Hello @anthonybartczak,

I still have the same issue:

Uncaught ReferenceError: gtag is not defined at googleConsentModeMapping

And it makes sense

<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…

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

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

Hello @anthonybartczak , @mbaersch ,

Not sure to follow you :slight_smile:

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


<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.

I followed this process: How To Integrate Google Consent Mode v2 & Piwik Pro [No GTM]

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

:slight_smile:

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.

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.

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.

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.