Default consent set too late

Created on 1 August 2024, 5 months ago
Updated 19 September 2024, 3 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.

Production build 0.71.5 2024