UPDATED: GA4 bug NOW FIXED – Infinite JavaScript loop that will BREAK your website!

Phil Pearce
First published June 30th, 2023
Last updated January 15th, 2024
UPDATE: Google Analytics 4 bug fixed. This article was highlighting the infinite JavaScript loop bug in GA4. Fortunately it's now fixed.
UPDATED: GA4 bug NOW FIXED – Infinite JavaScript loop that will BREAK your website!

UPDATE: This bug has now been fixed!

The MeasureMinds team found yet another GA4 bug, this time as a result of the Google Analytics 4 (GA4) auto-migrations.

The other Google Analytics bug we found was regarding GA4 regex conversions. You should read that too!

 

What is this GA4 infinite JS loop bug?

This bug occurs when GA4 auto-migrations activate the ‘Collect Universal Analytics events’ listener. This is enabled by default if an analytics.js code has been detected on your website.

 

Once enabled; it listens for all GA3 events, and then converts them to GA4 events.

When a GA4 event is executed it also output dataLayer.push({“event”: “ACTION”}); this is done to allow for synergy with GTM.

However, if the GA3 eventAction is the same as a GTM trigger event, it creates an infinite loop!

For example, here’s a real-life example from an AddToCart event:

  1. ga(“send”, {eventAction:”addToCart”, eventCategory:”ecommerce”, hitType:”event”} );
  2. is converted to gtag(“event”, “addToCart”, {event_category: “ecommerce”, send_to: “G-11111111”} );
  3. which then sends dataLayer.push({“event”: “addToCart”}); on hitCallback
  4. which invokes GTM trigger for {{Event}}=addToCart which executes the GA3 tag again!
  5. <infinite loop>

Put simply, when this setting is enabled, it doesn’t check to see if there’s an exact-match conflict between GTM event triggerName and GA3 eventAction, hence there’s no safeguard in place.

Additionally, as this is valid JS it means that is no JS error reported, which makes the issue more difficult to detect.

 

What is an infinite JavaScript loop?

An infinite JavaScript loop occurs when faulty logic means that the iteration (loop) can’t end. This will cause your browser to run out of memory and stop responding, thus breaking your user’s website experience as they will need to restart their browser.

This is especially bad because GA4 auto-migrations can happen on a weekend. For example, this issue was invoked at 6 am on a Saturday, IT departments are less likely to monitor issues in out-of-office hours, such as this.

 

 

How to prevent this GA4 bug from occurring

1. Don’t use GA4 auto-migrations

We highly recommend not using GA4 auto-migrations at all. It’s much better to get a bespoke GA4 implementation that suits your needs. Our Google Analytics team can help you with that.

 

2. Turn ‘Collect Universal Analytics events’ off 

If you are going to use the GA4 auto-migrations, make sure to turn ‘Collect Universal Analytics events’ off.

 

3. Change the name of the trigger 

Changing addToCart to addToCartX would stop the loop, because the {{Event}}=addToCart would not match.

 

4. Change the event tag to once-per-page

Changing the GA3 event tag from once-per-event to once-per-page would also prevent a loop.

 

5. Share our Tweet to Google Analytics to get bugs fixed

This bug was fixed due to people letting Google know about it. You should do this in future when you find anything similar.

 

We have found lots of different bugs in GA4 and have collected them together in a spreadsheet. We’ve tried to reach out to Google several times about this, but it would help if there were more people shouting about this!

We’ve created a pre-made Tweet that you can send to @googleanalytics by clicking on that link and then hitting Tweet. It’s that easy.

Or scan the QR code below.

 

Need help migrating to Google Analytics 4?

You can use our free GA4 migrator tool to get yourself a basic setup. But if you want a more complex setup, then your should contact our Google Analytics team

We’ve done a lot of very complex GA4 migrations and implementations for huge enterprises. It’s not worth risking problems like this where you break your own website and miss valuable sales during your downtime!

Phil Pearce
Follow me
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Articles from our Blog
0
Would love your thoughts, please comment.x
()
x