gtag.js/gtm.js order in D10.4 vs default consent

Created on 12 March 2025, 23 days ago

In Drupal 10.3, gtm.js was loaded before gtag.js. Together with the patch of 🐛 Default consent set too late Active , this ensured the default consent is set before anything tracking is triggered in GTM. Beware: GTM is already triggered by the gtag('js', new Date()); line in gtag.js.

In Drupal 10.4, gtag.js is loaded before gtm.js, causing tracking before the default consent is set. Probably because of https://www.drupal.org/node/3473558 .

Possible solutions
1. Play with the weight of the google_tag/gtm and google_tag/gtag library. This is discouraged, it is better to use dependencies between libraries.

2. The google_tag/gtm library is only loaded when there is a GTM id. However google_tag/gtag and google_tag/gtag are always loaded, even if there is no getDefaultTagId(). This doesn't make sense, so I would wrap that in an empty check.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇧🇪Belgium matthiasm11

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

Comments & Activities

Production build 0.71.5 2024