Archived topic
Google Tag Manager Speed Problem
5 replies · Started by Giovanni on October 31, 2021
Hi all,
Tag Manager in speed tests slows the site down by 1.5 seconds.
Is there a way through the hook to make it load as the last element on the page?
IN WP BODY OPEN:
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-MBNLJLC"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
IN WP HEAD:
<!-- Google Tag Manager -->
<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-MBNLJLC');</script>
<!-- End Google Tag Manager -->
Hi there,
Not sure if I understand. Google instructs the code to be added in wp_head and wp_body_open and both of those hooks are at the start of the page:
https://github.com/tomusborne/generatepress/blob/master/header.php#L17
https://github.com/tomusborne/generatepress/blob/master/header.php#L27
There isn't a way to change that.
Hi Leo,
google tag manager loads when I open each of my site pages. This consumes energy and speed making me lose 1.5 seconds in tests.
I would like to understand if there is a way to move the google tag manager loading last
Deferring Tag Manger scripts can be a pain and not recommended by Google as it can result in missing analytics.
The alternative method is to load them locally, and there are plugins that can do this.
Theres the PerfMatters plugin. And the CAOS plugin on wp.org.
thanks David
You're welcome