Where to place Google Tag Manager container snippet

UPDATE: Google has finally updated official recommendations for GTM code placement. Now you should place the snippet in the head section. Be sure to check this post for details.

Choosing a place for the Google Tag Manager container snippet can be a problem. Of course, there is a quite clear recommendation from Google saying that the snippet should be placed immediately after the opening body tag. But is it the only proper place for it? Where to place the Google Tag Manager container snippet if your WordPress theme does not have a special hook allowing you to add the code to the beginning of <body>? What if your header.php doesn’t include an opening body tag?

Let’s try to find a simple solution for this problem.

This article is divided into the following chapters:

  1. Official Google’s recommendations
  2. Where to get the GTM container snippet
  3. Putting the GTM container snippet in the head section
  4. Adding the GTM container snippet in the footer section
  5. Summary

Official recommendations for the Google Tag Manager snippet placement

First and foremost, let’s look at the probable reasons why Google recommends you to place an asynchronously loading JS library right in the beginning of body section. Before we do it let me honestly say that there’s no “sensational” or “top-secret” information below. This is just a short compilation of what has already been written about “google tag manager body placement” method on other sites.

So here’s how Google recommends you to add the Tag Manager container snippet to your site…

… And here are the possible reasons for that.

Reason 1: Internet Explorer users (7th version or older)

Yes, there are still quite plenty of them. Old versions of IE have troubles running JavaScript so if you put the GTM container snippet somewhere inside <head></head> this might cause issues with appendChild() method that is used by the GTM libary.

Reason 2: First load, then use

Often times the head section may contain data that is important for accurate web analysis. For instance, A/B tests information. So having the container code placed right after the opening body tag ensures this information is taken care of.

I presume that there are other occasions requiring that Google Tag Manager container snippet be placed after opening <body>. You are very welcome to share your thoughts in the comment section below. So if you’re wondering where to place the Google Tag Manager container snippet just follow Google’s official recommendations.

Now let’s see if there are any other sections to place the snippet. But first we need to get it.

Where to get the GTM container snippet

Login to your Tag Manager account, choose Admin tab and then click Install Google Tag Manager.

where-to-place-google-tag-manager-code: get gtm code

Putting the GTM container snippet in the head section

Here’s a simple method of adding the GTM container snippet to the <head> section offered by Simo Ahava in his blog.

Note that the <iframe> part of the snippet is moved to the body section because the placing of an embedded content in the HEAD is prohibited in HTML5.

IMPORTANT! Although this seems to work fine, this way of placing the Google Tag Manager container snippet is NOT officially supported.

Adding the GTM container snippet in the footer section

This is NOT a solution at all. If you want to keep your data as accurate as possible, NEVER place the GTM or GA container snippet in the footer section. Place it in the <head> like it is shown above if you don’t have an opportunity to reach the opening <body> tag.


As you can see the solution for “google tag manager head or head” dilemma is quite simple. If you have a possibility to edit the <body></body> section of each child template with just a few clicks – follow the official recommendations. If you don’t then place the code in the section the way it’s shown above. Finally, I would personally recommend testing both options so you can find the best solution for your site.

Tag Manager , ,