Website speed: google analytics slowing down my website

I installed google analytics on http://pokersociale.netlify.app. My website on mobile went from 99 speed score on lighthouse to 82. This isn’t acceptable: anyone having the same issue with GA?

1 Like

This question is more suitable for Google Analytics community/support. However, to answer your question, I’d say don’t bother yourself much with those numbers. In real world usage, I have seen those numbers not meaning much. You do everything that’s possible on your part to optimise your website but if you need Analytics, you’d have to accept the tradeoff.

@NicolasK You should try Netlify Analytics. My understanding is that they do not cause any slow-down.

I had the same problem. My site went down from 99 to 78 when activating Lighthouse.
For the time being, I decided to remove Google Analytics.

Greetings :wave:t2:

In regards to speed, this often comes as a result of loading the Google Analytics script (and initializing it) as a part of the initial page load. That’s what happens when you follow their install instructions too… although I think it’s wasted speed loss. I don’t run GA on my site anymore — Netlify Analytics is great for me and avoids any need for GDPR banners (which you legally should implement if you’re running GA and have EU visitors, even one… I’d recommend reading this), but when I did run GA, there’s a Gatsby plugin that handles loading the GA script in an asynchronous format after the page is done loading (technically once the React PWA hydrates) - it’s worth noting that this is different than simply adding the async or defer attributes to the load script; those still run during the initial page load, just at a different point in the lifecycle.

You can do some research and searches for how to load the GA script after page load but I like to recommend this approach since it already sets you up for the correct tracking consent workflow:

Jon

P.S. I am going to move this over to #opentalk as this concern is with GA script loading and not actually a concern with Netlify as a hosting platform :slight_smile:

I put the script before the closing body tag. now I’m back in the green at 90. but I want to score near 100 on mobile. plus it’s strange because since the script is async, it shouldn’t do a difference putting the script at the end.