Added Events overwrite Delayed Events

Created on 10 July 2023, 12 months ago
Updated 14 July 2023, 12 months ago

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.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom AlanHDev

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

Comments & Activities

Production build 0.69.0 2024