Perhaps this sounds familiar:
Your team has just decided to start transitioning to Google Tag Manager.
However, you’re stuck on where you need to place the container code.
Traditionally, you’ve placed
the Google Analytic immediately before the closing
“head tag”, or
perhaps it’s even still in the footer.
With Google Tag Manager, the
placement is now a little different. Instead of placing it in the head section,
Google recommends putting the container code immediately after the opening body
tag.
Where Can I Find My Snippet?
Google provides you with the
exact code and instructions for where to add it to your website.
For Google Tag Manager
Version 1, you can find the snippet code and their instructions on the left
navigation menu under Admin -> Install GTM.
In Version 2, the
installation code is found along the top navigation, under the Admin option.
Then, under the Container Settings, there’s an option for Install Google Tag
Manager.
You may notice that Version 2
has a very similar layout to Google Analytics.
What Does This Code Do?
Let’s examine the container
code and see what it’s actually doing.
The first thing we see is a
no script tag. The no script tag is tells the browser, if the user does not
have JavaScript enabled, and then render an iframe version of the GTM
Container to the page.
The next thing we see is a
script tag. The script inside of here is a JavaScript function that loads your
specific container on your page. It does by creating a new script tag and
setting the source to the URL to your Tag Manager container.
It also tells your page to
load your GTM container asynchronously, which means that the rest of the
page can continue loading while Google is doing its magic.
Why in the Body?
Google recommends putting it immediately
inside of the body and not inside of any other tag. One of the reasons
may be so that older versions of Internet Explorer do not run into issues with appendChild(). Older versions of Internet Explorer are known to
have issues with JavaScript. Google is recommending this code placement to
avoid any issues.
Along with Google’s recommendation,
here are a few other reasons and tips for your implementation:
Load your important information
first.
Putting the GTM container
code immediately after the opening body tag is important for a few reasons. The
page view tag relies on the title tag of the page, which is found in the head
section of your site. Content experiments are setup in the head of the page as
well. Having the GTM snippet in the body guarantees that these are taken care
of.
Place your data Layer above
the container code.
We need to put the data Layer
somewhere now. You may be tempted to add your data Layer after your container
code. This is problematic and will cause issues when you try to push data into
the data Layer. If you place the data Layer after the container code it will
end up overwriting the data Layer that the Google Tag Manager code creates for
you, and you may miss out on having important information available when you’re
first Tags try to fire.
Do not place the container
code inside of other HTML tags.
The reason we don’t place the
container code inside of other html tags is older browsers and their JavaScript
engines. Older versions of Internet Explorer have an issue appending HTML tags
that are dynamically generated. The script tag that the container code
generates will be appended outside of the head section that is not what we
want.
Worst Case Scenarios
We hear it all the time.
Maybe your website is using a template or you don’t have the appropriate
permissions to modify the body code.
Can I put the GTM snippet in
the head section of my page?
While it is not recommended,
it is possible to have the Google Tag Manager script in the head section.
However, this requires that you do not place the no script tag in the head. The
following screenshot demonstrates this method.
As you can see the container,
loader script is placed at the very bottom of the head section. We then place
the no script tag and its contents immediately after the opening body tag. By
doing this, we are allowing browsers with JavaScript enabled process the GTM
script as normal without having to parse the no script tag while loading the
page.
This method works, however it’s not officially
supported by Google.
Can I put the GTM snippet in
the footer section of my page?
This is highly discouraged.
For the same reason that we recommend putting Google Analytics in the head
section, you want your GTM container to load as soon as possible. This enables
you to begin tracking users right away, and ensures the maximum amount of tags
are fired.
At the end
That’s it, it’s pretty simple. Our recommendation is to
place the GTM container code in right after the opening body tag. That way
there’s no custom work to implement the GTM container. Since GTM was designed
for non-developers, it only makes sense to keep the custom development to a
minimum.
Share the article for good people and put your comment to
we know what are you like?
0 التعليقات:
Post a Comment