Optimizing Gtag Performance in Astro Projects
Google Tag Manager (Gtag) is a staple for tracking and analytics, but implementing it incorrectly can lead to significant main-thread blocking, negatively impacting your site's Lighthouse scores and user experience. In our project 'rifasvelez-web', we recently revisited our Gtag implementation to ensure that analytics gathering doesn't come at the cost of page responsiveness.
The Performance Bottleneck
When loading external scripts like Gtag, browsers often prioritize these network