Search code examples
google-tag-managergoogle-analytics-4

Why GTM server container duplicates intercepted GA4 client events?


I have server-side tracking implemented using Google tag manager.

I noticed duplicate events coming in but not because my GTM web container sends duplicate events (verified in debugger).

The GA4 client in my GTM server container receives two identical event calls, for no obvious reason. The only difference is the param _s:

https://www.google-analytics.com/g/collect?[...]&_s=1
https://www.google-analytics.com/g/collect?[...]&_s=2

I've dealt with this by creating a query parameter variable: query param gtm

And then excluding all calls where the _s param equals 2 from my GA4 event trigger:

enter image description here

This solves the issue but seems like a hacky solution.

I wonder why two identical server events get triggered in my GTM server container, for a single GTM web event, in the first place?


Solution

  • I had a similar problem, and I couldn't solve it by filtering the parameter because it happened later (I think the params of the two events were _s=6 and _s=7).

    I started looking for blog posts until I've found this one: https://www.thyngster.com/google-analytics-4-events-demystified-ga4. The suggestion that helped me was this one:

    You may see events being fired on the browser that you didn't define on Google Tag Manager or GTAG. This is normal, don't go crazy with it. If you see a duplicate event or a new event that you don't know where it's coming from take a look at the Data Stream Settings

    And, in fact, inside Data Streams was the solution to my problem: under Events settings > Create Events, someone had created a custom event based on the same name as the one I was firing through code, in my case it was add_to_cart.

    Disabling the custom event solved the issue.

    EDIT

    I forgot to mention that the first way of debugging this issue was to check the value of the dataLayer variable in the browser console. This variable keeps track of all the events, together with their send_to attribute. Before looking into the analytics dashboard you should check whether you are sending duplicate events from the code and whether you are firing other events with the same name but without the correct send_to attribute, which will result in two events with the same name firing to the stream you are tracking.