• Resolved djeah

    (@djeah)


    Hi,

    I know few users have pointed out that the Javascripts inserted is slowing down the page, but my question is different.
    When Pagespeed says that the below Javascript is unused and asking me to remove it, I am wondering whether it is really not used?

    https://www.googletagmanager.com/gtag/js?id=UA-177XXXXXX-1

    What confuses me more is that if I disable grouping of Javascript files on my site, I do not see the Remove unused JavaScript recommendation at all. But if I enable grouping of Javascript files, the number of requests count drops from some 67 to 43, but I see this script along with the grouped javascript created by the plugin as unused.

    I have search console and analytics activated via Site Kit.

    • This topic was modified 3 years, 8 months ago by djeah.

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support James Osborne

    (@jamesosborne)

    Thanks for reaching out. The Site Kit placed Analytics snippet is required in order for your site to record site visits, although it should have minimal impact on site performance.

    While not being an expert on PageSpeed Insights my guess is that as because your Analytics snippet has slight differences places to the standard snippet placed via Site Kit some of this JavaScript may me marked as unused. When checking your site source code I notice a siteground-async=1 reference within your Analytics snippet.

    Have you submitted the same question to the product experts at the Analytics Help Center? They should have more insights on this than we can provide here. Alternatively you could try and temporarily deactivate any your SG Optimizer or any other optimization plugin that may be altering the snippet before checking once more.

    What confuses me more is that if I disable grouping of Javascript files on my site, I do not see the Remove unused JavaScript recommendation at all.

    This isn’t a feature of Site Kit, so I can’t be sure how another plugin combines may alter existing Site Kit placed snippets. What plugin are you using, or where do you see this configuration, I’m happy to check this for you if you share more details.

    Thread Starter djeah

    (@djeah)

    Hi @jamesosborne ,

    I am using Siteground and breeze plugin. But the javascript minification and grouping was enabled only from breeze, as I disabled it from the SG optimizer now.

    However, having done this, the unused gtag only shows up in the mobile version of my site and not in desktop version in Pagespeed now.

    Plugin Support James Osborne

    (@jamesosborne)

    Thanks for the additional insights. If you temporarily deactivate any Breeze and SG Optimizer configurations that impact your Analytics snippet I suspect you won’t encounter the same unused JavaScript notice. Let me know once you’ve temporarily removed this and I’m happy to check your site once more.

    Note that this shouldn’t have any impact performance, I found some additional insights in the Lighthouse GitHub repository in relation to this (Lighthouse is the technology used for PageSpeed Insights). This notice can occur when not all of a JavaScript snippet is determined as used based on PageSpeed Insights logic.

    However, having done this, the unused gtag only shows up in the mobile version of my site and not in desktop version in Pagespeed now.

    That does sound unusual, although I suspect some of the additional JavaScript may be based on different screen dimensions or devices. It might be interesting to know if this also occurs without any additions to the default snippet as placed via Site Kit – again with the SiteGround or Breeze plugins temporarily deactivated.

    Thread Starter djeah

    (@djeah)

    Hi @jamesosborne ,

    I went through the link and looked like breeze wasn’t functioning properly for the JS and CSS. Over the weekend I optimized my site further to get a decent score using Autoptimize. I will not be using the JS/CSS options of Breeze and SG Optimizer now as I am getting good speed and scores, except on the mobile using Autoptimize.

    In Autoptimize doesn’t matter if I aggregate the files, or not, both :
    https://www.googletagmanager.com/gtag/js and https://www.googletagmanager.com/gtag/js?id=UA-1778xxxxx-1&l=dataLayer&cx=c show up in unused category in mobile and
    https://www.googletagmanager.com/gtag/js as render blocking both in mobile and desktop.

    When I checked the source code of the page I do not see any async or defer property for https://www.googletagmanager.com/gtag/js and if I force it to load with either of that property using a plugin, it breaks the site.

    Plugin Support James Osborne

    (@jamesosborne)

    Apologies for the late response. When Site Kit places your tags it does include an async reference, you’ll find a typical Site Kit placed insert here.

    From inspecting your site once more I see a Tag Manager request although this snippet placement is not placed via Site Kit.

    If there are any modifications to the snippet via any other plugins this may be resulting in the unused JavaScript notice within PageSpeed Insights. You’ll find a guide on this here. Note that also if you’re using Google Tag Manager – connected via Site Kit or manually it’s also possible you may encounter this notice depending on the tags you have inserted.

    As we’re limited to Site Kit plugin support can you confirm all your Site Kit dashboards are working as expected? If not we can do some troubleshooting with your additional optimization plugins to ensure it’s working as expected.

    Thread Starter djeah

    (@djeah)

    It was just yesterday that I setup a new GA4 analytics as I was using UA. I added the new GA4 using Site Kit Tag Manager. So now I have both UA and GA4 on my site.

    One more info is that I recall having specified configurations in the Complianz Cookie plugin following the steps in this URL https://complianz.io/configuring-google-site-kit/ , where I followed the 2nd approach “Google Site Kit will add the Analytics snippet. Complianz handles consent only.”

    • This reply was modified 3 years, 8 months ago by djeah.
    Plugin Support James Osborne

    (@jamesosborne)

    Nice work getting both a UA and GA4 property added to your site, that way you can use the Site Kit dashboards while also making use of the newer GA4 Tag.

    In relation to the Complianz documentation thanks for sharing. I’ve tested the same plugin previously although an older version, so I can’t be sure if any additional may be triggering any unused JavaScript notice. I did check your site once more and see that the unused JavaScript indicates this as a minor opportunity, that doesn’t direct impact your performance score. If you’re looking to improve your performance score you can follow the suggestions on the same report, or use PageSpeed Insights.

    Thread Starter djeah

    (@djeah)

    Thanks @jamesosborne . One last question. If I setup both GA4 and UA with the same Google Tag Manager container ID, will that work? I see that if I connect only google tag manager, it inserts an iframe on every page.

    But the below code is present only on the homepage:

    <script>( function( w, d, s, l, i ) {
    	w[l] = w[l] || [];
    	w[l].push( {'gtm.start': new Date().getTime(), event: 'gtm.js'} );
    	var f = d.getElementsByTagName( s )[0],
    		j = d.createElement( s ), dl = l != 'dataLayer' ? '&l=' + l : '';
    	j.async = true;
    	j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
    	f.parentNode.insertBefore( j, f );
    } )( window, document, 'script', 'dataLayer', 'GTM-XXXXXX );</script>
    Plugin Support James Osborne

    (@jamesosborne)

    No problem at all. You can setup a GA4 and UA property together without Tag Manager if you wish, you’ll find a manual code snippet example displaying both in this guide. Site Kit will recognize your UA snippet during Analytics setup, therefore not inserting the snippet for you (Ensure you have the option toggled off for Site Kit to insert your snippet after revisiting the Analytics module settings screen).

    Let me know if you have any further questions on the above.

    Plugin Support James Osborne

    (@jamesosborne)

    As we didn’t receive a response I’ll mark this as resolved. Feel free to open a new support topic if you continue to encounter issues, or reopen this topic and we’d be happy to assist.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘gtag Javascript unused?’ is closed to new replies.