#PageSpeed insight shows significantly worse results after i connect Google Analytics

11 messages · Page 1 of 1 (latest)

modern sedge
#

I am attaching two screens from pagespeed.web.dev The 75 is with the script attached (i replaced the tag ID with XXXX in the code below):

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXJ&l=dataLayer&cx=c"
></script>
<script is:inline>
    window.dataLayer = window.dataLayer || [];
    function gtag() {
        dataLayer.push(arguments);
    }
    gtag('js', new Date());

    gtag('config', 'G-XXXX');
</script>

When i remove this the page speeds up to 96.

It seems that LCP loading time is increased over 100%...

I am not sure what could be the issue, have googled it but google claims that their scripts won`t slow down page.
If anyone could help I would be very grateful.

onyx shadow
#

I would think that the <script> tag would normally have defer on it.

subtle belfry
#

I've the same behavior with our usercentrics consent manager.

<script
    type="text/partytown"
    data-settings-id={settingsId}
    id="usercentrics-cmp"
    src="https://app.usercentrics.eu/browser-ui/latest/loader.js"></script>

It doesn't matter if we defer / async it.
the problem is the Largest Contentful Paint. 200kb of JS is getting fetched from the service worker. But the actuall processing of the files and rendering happens in the mainthread itself.

Maybe someone has an idea to render the consent manager more efficent.

onyx shadow
subtle belfry
onyx shadow
#

You have is:inline on your second script tag, but not on the first. The docs (at the link I included) state: "When to use this: when your JavaScript file lives inside of public/ or on a CDN. To load scripts outside of your project’s src/ folder, include the is:inline directive. This approach skips the JavaScript processing, bundling, and optimizations that are provided by Astro when you import scripts as described above."

subtle belfry
#

Ah, I‘m not the OP. Just a different guy with a similar problem 😄.
But I think @modern sedge will love to see your hint

modern sedge
#

Hey thank you very much for your tips - i have tried both - defer and is:inline in the first script tag - it didn`t change anything.
I start to think that the issue may be with the analytics and its configuration itself.

onyx shadow
modern sedge
#

I have used it before with no result - will try again with better understanding.

modern sedge
#

It worked! Thank you very much - i have tried using partytown in the past but it seems i configured it wrong and overcomplicated the config file, after short dive into documentation everything is clear to me. and it is working. Many thanks to you sir! Here is the result with working analytics.