Streaming live at 10am (PST)

How to insert code GTM (Google Tag Manager) after the tag < body >?

How to insert code GTM (Google Tag Manager) after the tag < body >?

This solution does not work

2 Likes

have you tried adding the HTML as a embed widget as the first element on your project?

2 Likes

Thank you!

It works!

SYMBOLS very helpful.

I’m following this advice but it still gets placed within a div, so I end up with the code below. Tag Manager still seems to work, but I wonder if I’m going to run into problems further down the line?

<body>
  <div class="w-embed w-iframe w-script">
    <!-- Google Tag Manager -->
    <noscript>
      <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-MJZ2RZ" height="0" width="0" style="display:none;visibility:hidden"></iframe>
    </noscript>
    <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=
      '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
      })(window,document,'script','dataLayer','GTM-MJZ2RZ');
    </script>
    <!-- End Google Tag Manager -->
  </div>
1 Like

Really helpful! Thank you.

To make this even easier I create a Global Object of the HTML embed with the script tag in it, then added it to each page, and used the Navigator to make sure that on each page it was right below the body tag.

Thanks again!

1 Like