Huge Processing Time for Gtag making the site unresponsive

248 Views Asked by At

Loading the Google tag through Google Tag Manager on our site and it is sending data to two destinations, GA4 and Google Ads.

The issue is that the gtag is taking forever to load (13 seconds). In Pagespeed insights it shows anywhere between 10-30 seconds!

I've implemented GTM and Gtag many times and have never had this happen.

The delay is reported as Processing Time in the main thread, after which it triggers a doubleclick iframe. If I disable the Google Signals collection it still takes forever to load.

enter image description here

We removed the Gtag from firing which instantly resolved the issue.

1

There are 1 best solutions below

21
BNazaruk On

Update: Here Simo goes through the new feature gtag enabled by default. That feature aims to detect user-provided data automatically. It does so by parsing the whole page looking through it all with a regex. This process effectively blocks the main thread depending on what content the regex stumbles upon, as it is usually the case with regular expressions. Disabling the feature should fix the problem.

Old answer:

As Stephen indicated, the snippet has to be async to avoid blocking the main thread regardless of whether it's "standard" or not.

Plus, you don't implement GTM and Gtag. You implement either or. GTM loads gtag whenever it's needed. Many new people make the same mistake due to this poorly designed gtm/gtag page of google's documentation.

In general, however, when you're debugging page load, you don't want to end your investigation on the lighthouse report. You should continue with Chrome's page load profiling via devtools and analyze the results properly. Lighthouse is often wrong in what it highlights as a problem. A lot of what it highlights doesn't actually affect the page load times in a measurable way.