Recently, we noticed that GA4 was collecting “add_to_cart” events multiple times on our live website. Interestingly, this issue did not occur on our staging website, even though both versions were identical.
In this blog post, we’ll explore the cause of this problem and share our solution to help you resolve any similar issues you may be experiencing.
GTM Multiple Custom Events
We checked all the triggers and tags in GTM but didn’t find any errors. However, when we clicked the “Add To Cart” button in GA4’s preview mode, the “add_to_cart” tag fired multiple times. Surprisingly, each fired tag had the same gtm.uniqueEventId, which was unusual.
|GA4 Debug View||GTM Preview Mode|
We attempted to reach out to GA4 and GTM support, but they were unreachable. However, we needed to solve the problem as soon as possible.
Analyzing the “add_to_cart” Event
“add_to_cart” is a GA4 Ecommerce event. We push it to the data layer when a user submits an “add to cart” action, along with product name, ID, price, and quantity parameters.
When we changed the “add_to_cart” event name to “add_to_cart_2”, GTM started to fire the tag only once. Based on this testing, we concluded that the issue was a GA4 bug. However, we still needed to find a solution.
Fixing the Duplicated Events
Upon further investigation, we discovered that we had also created a custom “add_to_cart” event in GA4. To fix the issue, we deleted the custom “add_to_cart” event from the GA4 dashboard and only kept the GTM tag (which takes data from the data layer).
When you add a custom event in GA4 and then send it via GTM (data layer), it creates an ‘infinite’ loop of the custom event firing multiple times.
We hope this blog post helps you if you’re facing a similar issue. If your problem persists despite following the steps described here, feel free to leave a comment or join our Reddit community, where we’ll do our best to assist you.