Should I move my GTM code into the <head>?

In case you were not yet aware, Google has officially changed its recommendation on placement of the Google Tag Manager container snippet.

Previously, GTM required a single snippet of code to be placed immediately after the opening <body> tag. This code has now been split into two snippets: One to be placed in the <head> and a second to be placed in the <body> as before.GTM New Code Snippet

If you already have GTM running on your website, you might be wondering:

  • Do I need to move my GTM code to follow the new instructions?
  • Are there risks to maintaining the previous approach?
  • Why did the recommendation change?

Let’s answer these questions and help put your mind at ease.

Do I need to move my GTM code into the <head>?

The short answer is no.

There is no immediate need to move your GTM code just because the instructions have been updated. Your existing implementation will continue to work exactly the same way.

However, moving the container snippet into the <head> means that GTM will start loading earlier on the page. This gives your tags a greater chance of firing in the case that the user leaves the page or closes their browser, which can improve your data quality and accuracy.

In our tests, firing the base Google Analytics tag in the <head> (instead of the <body>) can result in a 3-5% increase in recorded sessions. Most of that traffic (95%) consisted of bounces. And for the traffic that didn’t bounce, we were able to capture a more accurate source of traffic (since the GA code was able to fire and capture the traffic source before the user navigated to the next page).

Are there risks to maintaining the previous recommendation (top of the <body>)?

It’s possible that some newer tag types which GTM now supports (e.g. Google Optimize) will not function properly using the previous placement.

If you are interested in using Google Optimize to conduct A/B testing on your site, you will definitely want to update your GTM code to the recommended placement. Otherwise, the user will likely see the page “blink” as Optimize serves up a different variant of the page.

Why did the recommendation change?

In addition to supporting Optimize and other new tag types, another potential reason for moving the container snippet into the <head> is to enable the future possibility of deploying synchronous tags via GTM. However, this is just speculation, as there is no official word on this from Google.

You should plan for moving the code when it is feasible to do so, but you do not need to do it right away and scramble your financial and technical resources.
Do you have any questions about new GTM snippet instructions? Please let us know in the comments below.

Share this article!

2 thoughts on “Should I move my GTM code into the <head>?

Leave a Reply

Your email address will not be published. Required fields are marked *