How to move your GTM code into the <head>?

Tabata Vossen -

By default, instead of splitting the Google Tag Manager (GTM) container code, Qualifio places it in the body section. In this article, we will show you how to follow Google's recommendations and place one tag in the head and the other in the body.

The GTM container code is made up of two parts:

Screenshot_2020-08-04_at_15.04.20.png

Here's what the perfect and recommended scenario looks like:

  • In the first part, we see a script tag. It goes in the head.
  • In the second part, we see a no script tag. It goes in the body.

But real-life situations are far from perfect and sometimes we have to deal with very limited circumstances.

While working with Qualifio, you can't access the campaign's source directly and you're only allowed to paste tracking codes into a dedicated field. Then, Qualifio automatically places your GTM code in the body tag rather than following Google's recommendations. Which means that, when adding your GTM code to your Qualifio campaigns, you can only add it in the body tag.

Why? Google once recommended placing the entire container code after the opening of the body tag, but the recommendations of Google Tag Manager are now a little different.

Can I move my GTM code to follow the new instructions?

The previous approach is still working to this day, so there is no immediate need to move your GTM code. But this could potentially mean you're not tracking users who leave your page before the body tag is loaded.

While it is not the default option, it is possible to split the GTM code and put the <script> and <noscript> tags at the recommended places.

Follow the steps below:

  • Find your container ID in Google Tag Manager (in the top navigation, under the Admin option).

Screenshot_2020-08-04_at_15.45.51.png

  • Copy the code below and replace "GTM-ABC123" with your container ID:
<gtm id="GTM-ABC123">

Where does this go?

There are two places where you can put it:

  1. In your campaign > Channels > Tags > Additional HTML code (to track a specific campaign). Like this:
    Screenshot_2020-08-04_at_15.41.10.png
  2. Or by going to Settings > Websites > Tags > Additional HTML code (to track campaigns published on a specific website). Like this:

Screenshot_2020-08-04_at_16.01.48.png

Click Save to apply your changes.

That's it, it's pretty simple. This will ensure that your marketing tags in GTM will be fired as soon as possible without much data loss.

Related articles