Where to place Google Tag Manager code v.2

Google+Tweet about this on TwitterShare on FacebookShare on LinkedIn

Previously, I’ve already written about where to place Google Tag Manager code on your site. As a matter of fact, that post dedicated to GTM code placement dilemma was the very first publication of my blog and it still contains up-to-date information.

But since Google has updated official recommendations on where to add Google Tag Manager container snippet, an additional inquiry yielding new insights into the subject matter certainly would not go amiss.

What has changed

Henceforth, GTM container snippet loads in a protocol-independent manner. What this means is that regardless of your site’s protocol new snippets will always use HTTPS protocol by default, thus providing more protection to your private data and improving overall performance.

Additionally, now instead of putting the container snippet right after the opening <body> tag Google recommends you to place it in the head section, exactly where a loader of an asynchronous JS library belongs to.

where to place google tag manager code

Please do mind that you still have to place the <noscript> part of the snippet right after the opening <body> tag and here’s why:

    • Google Search Console will work properly if only the <noscript> snippet is placed immediately after the opening <body> tag. Moving it elsewhere will break the verification. See Scott Herman’s comments here
    • HTML 5 standards do not allow iframe be placed in the head section

Thus, an official recommendation on how and where to place Google Tag Manager code looks like this:

Will my current implementation still work?

YES, in case you have Google Tag Manager container snippet placed right after the opening <body> tag, this implementation will work just fine. As a matter of fact, you can inject the code however you like. But still…

Why should you update your GTM implementations right away

I guess reasons for changing the snippet location are quite obvious. But in order to get a full insight into the matter, let’s take a closer look at the benefits of putting Google Tag Manager container snippet in the head section.

  • The sooner the better

As you place your GTM container snippet as high in the head section as possible, you obviously narrow down the possibility of losing data because the earlier you fire your tags the earlier tracking process starts.

  • Preparing for the sync snippet rollout

An option for a synchronous GTM loading has been promised a more then a year ago (see this video). Though at the moment it’s still in beta, the snippet’s transferal helps future-proof enabling the option. Especially amid the upcoming rollout of Google Optimize.

  • Easier to implement/migrate

Oftentimes, it’s much easier to paste a given snippet of code in the head section as it’s more accessible. Plus, in this case ga.js migration gets smoother.

  • Higher level of security

As mentioned above, GTM now uses HTTPS protocol, which protects your data from malicious parties.

What’s next

Obviously, the announcement of these changes in the conjunction with the upcoming Google Optimize presentation presages a release of a long-awaited feature – synchronously loading tags.

Google+Tweet about this on TwitterShare on FacebookShare on LinkedIn