Multiple Container Loaded events can occur

Created on 25 April 2024, 5 months ago

Problem/Motivation

While contemplating a switch to the google_tag module, it seems that multiple Container Loaded triggers may be occurring. Upon further investigation, it seems that there is some overlap happening between the gtm.js and gtag.js libraries. Both libraries run code that initiates a Container Loaded trigger.

From gtm.js:

window[dl].push({'gtm.start': new Date().getTime(), event:'gtm.js'});

From gtag.js:

gtag('js', new Date());

Debug output from the GTM inspector:

While the impact of this is relatively benign in nature, it could very well be a source of confusion. Typically one wouldn't expect the same container to have multiple loaded triggers firing for the same page view.

Steps to reproduce

  1. Enable and configure the Google Tag module
  2. Follow the instructions in Preview and debug containers Google documentation
  3. Inspect the container in the tool, note there are two Container Loaded triggers.

At this point, comment out either https://git.drupalcode.org/project/google_tag/-/blob/2.0.x/js/gtm.js?ref... or https://git.drupalcode.org/project/google_tag/-/blob/2.0.x/js/gtag.js?re... and repeat the steps.
Note that only one Container Loaded trigger occurs, as expected.

Proposed resolution

Only push one such event into the datalayer when both gtm.js and gtag.js are loaded together.

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Luke.Leber Pennsylvania

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

Comments & Activities

Production build 0.71.5 2024