TypeError in gtag.js when tagId is null (Drupal GTM 2.0.8)

Created on 21 March 2025, 16 days ago

Problem/Motivation

We're on Google Tag Manager module 2.0.8 and we're having a TypeError in gtag.js when no tagId is set. (we do have a tagId set in the module's settings)

Console logs show:

Uncaught TypeError: Cannot read properties of null (reading 'length')
    at js_MlrjlXCPxejByktEDAzCAq3JGP0F3Hn8o9SjN7Uzpes.js:5:17

After debugging, console.log(drupalSettings.gtag) returns:

{tagId: null, consentMode: true, otherIds: [], events: []}

Basically the issue is that config.tagId is null, and the script tries to read .length, and it's causing a fatal error.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

2.0

Component

Code

Created by

🇮🇹Italy plagiato

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

Comments & Activities

Production build 0.71.5 2024