1

In a recent Q&A on Youtube, the GTM product manager said two things which made me consider the current recommendation of putting the GTM script at the beginning of the body tag.

https://youtu.be/XBCNJo9qGH8?t=6m23s

The video highlights the positives of having it early, and that the drawbacks are HTML validation. Synchronous tags will be supported by the end of the year, and I hope to future-proof with that in mind (for synchronous A/B scripts)

It seems desirable to be able to deploy A/B snippets from Google Analytics and optimizely through GTM.(it´s very desirable because I don´t want a synchronous script being there for several months).

What are other negative consequences of putting the script in the head section?

tovare
  • 4,027
  • 5
  • 29
  • 30

3 Answers3

2

The GTM code can be placed within the head section (although it's not recommended), but the <noscript> part should be left in the body. Quoting from this article, "Where Should The Google Tag Manager Snippet Be Placed?":

By [placing the container in the Head section], we are allowing browsers with JavaScript enabled process the GTM script as normal without having to parse the noscript tag while loading the page.

nyuen
  • 8,829
  • 2
  • 21
  • 28
1

A/B tests

Rather do not use async GTM for A/B testing, insert A/B test tools script directly to section and let GTM do only analytics stuffs.

NOSCRIPT

Remove nosctip part and then you can put it into . Else do what is written in docs.

Jakub Kriz
  • 1,501
  • 2
  • 21
  • 29
  • Part of my concern is futureproofing for a GTM upgrade which will do syncronous tags later this year. A/B tools prefer to be in the head to ensure that no rendering happens. I´m not that concerned about agents without javascript, since the site won´t work at all for those users. – tovare Sep 29 '15 at 15:53
  • 1
    Yes, It is true, that GTM will offer features for Synchronous scripts, hope later this year. But for now, it is not publicly available. I am not sure, If I can tell more. – Jakub Kriz Sep 29 '15 at 16:53
0

A likely conclusion is:

There´s mounting evidence so far that the GTM-tag should be put in the head, and that there are mostly positive effects in doing so.

Simo Ahava said in the GTM product forum that:

I've always preferred to put it in the head. That's where asynchronously loading libraries should be placed. The only thing you might want to do is leave the block in , as some browsers fail to validate noscripts in . Webmaster Tools verification via GTM will not work if GTM is installed in ( He also has a blog with some good tips: http://www.simoahava.com/#gref) Ref: https://productforums.google.com/d/msg/tag-manager/DMFVIIRFs6o/kuZzVgixDwAJ

Phil Pearce who ran a GTM video series on youtube commented on the YouTube Q&A video:

"Re: 7mins:25 ... I wish the Google Support docs would be updated to say place the GTM code in the (with iframe in the body)."

The product manager said in the video that earlier is important and putting the tag in the head, would make it load even faster.

tovare
  • 4,027
  • 5
  • 29
  • 30