Default consent set too late

Created on 1 August 2024, 9 months ago

Problem/Motivation

This is to fix the issue here:
https://www.drupal.org/project/google_tag/issues/3180185#comment-15465757 ✨ Support Google Analytics consent mode Fixed

Steps to reproduce

Install with 2.0.6, run the site with Google Tag Assistant.
Notice the Tags are fired before the "Consent Default".

Proposed resolution

Root cause is gtm.js loaded before gtag.js, and consent default was set in gtag.js
Refer to this link for reference:
https://developers.google.com/tag-platform/security/guides/consent-debug...

With the patch, "Consent Default" will be at the very beginning.

Remaining tasks

If you need to set the consent afterwards, just call another consent update.
Possibly, could set other default values rather than 'denied' for all, as requested in here.
https://www.drupal.org/project/google_tag/issues/3440508 ✨ Additional consent mode options Active

For sure, should be handled by that issue task.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada francismak

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @francismak
  • πŸ‡¨πŸ‡­Switzerland zilloww

    Hello, any new on this update? Just tried the patch but unfortunately, it is not working for me. (See Gtag preview mode screenshot linked below)

    I tried it on `2.0.6`. When I try it on `^2.0-dev@dev`, the patch isn't applied.

    While waiting for an answer, I'll try some tweaks to see if I can do something for this issue that is becoming a little critical because of the new Google consent restrictions deadline...

  • πŸ‡ΊπŸ‡ΈUnited States philltran Detroit, MI

    @zilloww Looks like this patch was committed via issue 3180185 ✨ Support Google Analytics consent mode Fixed

  • πŸ‡ΊπŸ‡ΈUnited States philltran Detroit, MI

    @zilloww Opps. My mistake. This patch moves the

      if (config.consentMode === true) {
        gtag('consent', 'default', {
          ad_storage: 'denied',
          analytics_storage: 'denied',
          ad_user_data: 'denied',
          ad_personalization: 'denied',
          wait_for_update: 500,
        });
      }
    

    code block from `/js/gtag.js` to `/js/gtm.js`

  • πŸ‡ΊπŸ‡ΈUnited States philltran Detroit, MI

    I updated the patch to work on 2.0.x dev branch. I added a condition on gtag implementation of default consent to only apply if `gtm` is empty. Otherwise we would have consent.default set twice. I tested this successfully with GTM-xxx and AW-xxx ids. Using a G-xxx id made the consent.default load too late. I will continue to look into that issue and am open to anyone else's insight on the matter.

  • Status changed to Needs review 4 months ago
  • @philltran @zilloww Caution, some of these things don't look right.

    1. I'm certain that Default Consent should not go before the Consent Initialization event in GTM. The Consent Initialization action is designed to be the very first thing that fires on a page, and it typically fires off the cookie consent banner, or establishes Default Consent settings. I know you're not firing anything from that action, but industry practice is to have Consent Initialization as #1. This way, you're safe if Google changes something assuming everyone has Consent Init first.

    Links with useful nuggets and screenshots of how GTM consent mode in Preview Mode should look:
    https://www.simoahava.com/analytics/consent-settings-google-tag-manager/
    https://developers.google.com/tag-platform/tag-manager/templates/api#set...

    2. Caution with the GTAG js command that you're using I: know we got it form Google's documentation, but I can't see the context of your function, but there should be a line above it

    // 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' });

    more later.....

Production build 0.71.5 2024