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>
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
<!-- End Google Tag Manager -->
  • Did you come up with a solution to your problem? Jul 19, 2017 at 17:05
  • Unfortunately, no.
    – Mike2500
    Jul 19, 2017 at 17:20

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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