2

So I'm making a GDPR, CCPA... compliant Next.js App with cookie consent and preferences and need to implement Google Anayltics with Google Tag Manager with Consent.

_app.js:

...
<Script src={`https://www.googletagmanager.com/gtag/js?id=${googleTagId}`} strategy="afterInteractive" />
<Script
    id="gtag"
    strategy="afterInteractive"
    dangerouslySetInnerHTML={{
        __html: `
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            
            gtag('consent', 'default', {
                'ad_storage': 'denied',
                'analytics_storage': 'denied',
            });

            (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','My Id from gtag code...');
        `
    }}
/>

But when I go to my app I can see that Google anayltics collects data without prior consent (denied in consent gtag function). See this image

Only after the user consented with this code it should collect data:

gtag('consent', 'update', {
    'ad_storage': 'granted',
    'analytics_storage': 'granted',
});

Why is it collecting data without prior consent, when everything is set to denied?

1 Answer 1

1

This happens because Google applies modeling, that is, if you deny consent to analytical cookies, the hits are sent anonymously rather than lost.

Behavioral modeling for consent mode aims at filling this data gap by modeling the behavior of users who decline analytics cookies based on the behavior of similar users who accept analytics cookies. The training data used for modeling is based on the consented user data from the property where modeling is activated.

For example, behavioral modeling estimates data based on user and session metrics, such as daily active users and conversion rate, that may be unobservable when identifiers like cookies or user IDs are not fully available. Without modeling, you have a less complete understanding of user behavior on your site based only on the observed data you have available.

https://support.google.com/analytics/answer/11161109?hl=en

2
  • Is this GDPR, CCPA ... compliant? If not how can i disable it Commented Sep 3, 2022 at 13:55
  • 1
    It could be compliant, I'm not a legal. If you want to avoid to send hit just to use a trigger based cookie consent status to fire Google Analytics tag. Commented Sep 3, 2022 at 15:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.