3

According to the docs, the GTM should be added "immediately after the opening tag." However, any code that is placed there in the master (well, really the htm version of the master) will be put in the form. There is a codeplex solution, but it only handles the actual script, not the noscript and iframe that is part of snippet from Google. I could use JavaScript to move elements to the correct location programmatically, but moving a "noscript" with JavaScript seems a bit silly. So, is this possible?

The code I'm trying to add right after the body tag:

<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXX"
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-XXXX');</script>
<!-- End Google Tag Manager -->
  • Did you come up with a solution to your problem? – James Grizzle Jul 19 '17 at 17:05
  • Unfortunately, no. – Mike2500 Jul 19 '17 at 17:20
0

In case anyone is still trying to figure this out, I was able to solve it for a SharePoint Online site collection. Assuming that the Publishing Features are turned on, I:

  1. Put all the Google Tag Manager stuff into a dedicated HTML file.
  2. Upload the HTML file somewhere like the root Site Assets library.
  3. Go to the Design Manager > Snippet Tool
  4. Configure a Content Editor Web Part to render the HTML file.
  5. Embed the Content Editor Web Part into your master page with no chrome/make invisible with your preferred method of choice or use the native ms-hide class
  6. Check-in, publish.

Done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.