Duplicate events pushed to datalayer for anonymous users

Created on 2 December 2022, about 2 years ago
Updated 5 February 2024, 11 months ago

Problem/Motivation

Duplicate events are pushed to the datalayer.

Steps to reproduce

We saw this when going offsite (to a payment gateway) and returning.
However, may happen under other circumstances.
The cause is that events are not deleted from the PrivateTempStoreCookie when headers have been sent. This is the case when triggered by bigpipe.

Proposed resolution

Delete the cookie client side after pushing events.

 // Push events.
            for (var index in eventsOrder) {
                var name = eventsOrder[index].name,
                    event = drupalSettings.google_tag_events.gtmEvents[name];
                window.dataLayer.push(event);
                delete drupalSettings.google_tag_events.gtmEvents[name]
            }
            // When running in bigpipe the event is flushed after headers
            // have been sent so the cookie cannot be removed. This can cause
            // the event to be pushed multiple times. For this case
            // we remove the cookie here.
            $.removeCookie('gte_ptsc_google_tag_events', {path: "/", domain: window.location.host})

Remaining tasks

MR to follow shortly.

User interface changes

None.

API changes

None.

Data model changes

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇨🇭Switzerland tcrawford

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024