Problem/Motivation

I have a situation where there is a mixture of delayed events set in the session from a previous page and I am also adding events in the current page. If I have 2 delayed events and one event, when the events are added to drupalSettings, the event occurs first followed by the second of the 2 delayed events, the first of the delayed events being lost.

Steps to reproduce

In a test page, add 2 delayed events and one event using the google_tag.event_collector service.

Observe that the drupalSettings.gtag.events array in the page shows only two events rather than three, and that the single event has overwritten the first of the 2 delayed events.

Proposed resolution

The behaviour is due to the eventCollector->getEvents() method. This is set to return $delayed_events + $events. As both of these are indexed arrays, elements where the keys are the same in $delayed_events are replace with elements in $events.

Instead, the return should be array_merge($delayed_events, $events)

Remaining tasks

Create the fix branch and patch.

Issue fork google_tag-3373657

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

AlanHDev created an issue. See original summary.

alanhdev’s picture

rowanadev’s picture

Status: Active » Reviewed & tested by the community

I have been able to reproduce this issue on Drupal 9.5.9 using google tag version 2.0.2 and PHP 8.1.16.

Once I was able to reproduce the issue I applied the patch and it has resolved the issue.

japerry made their first commit to this issue’s fork.

japerry’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.