Implementing Google Analytics with Google Tag Manager

Tag management, and Google Tag Manager, exist to make web analytics implementations easier. If you’ve got a fairly simple site then you should consider using Google Tag Manager to implement Google Analytics. It greatly simplifies the process.

The Standard Google Analytics Tag Implementation

Let’s Walk through a very basic Google Analytics setup using Google Tag Manager. Here’s a video if you don’t want to read :)

I’ve got a small site that used to sell my old e-book. I want to implement the standard Google Analytics tracking code on this site using GTM.

The first thing I need to do is create a container. The container will hold my Google Analytics tag along with any other tags that I may wish to put on the site.

There’s not too much involved in creating a container. You need to name the container and choose a timezone.

Creating a Container with Google Tag Manager

I should mention that Adding a domain to the container is not necessary. It just triggers various help in the user interface. While not necessary I recommend adding a domain.

Once the container has been created it’s time to add the container JavaScript to the site. Copy the code and place it after the opening tag on your site.

Add the GTM Code to your site

Great, now we’ve got a container and it’s time to populate the container with our Google Analytics tag. The GTM team made it easy to install Google Analytics by creating a form for most of the GA tag options, as shown below:

Adding Google Analytics to a site using GTM

For a simple implementation all you need to enter is the web property ID. This is the UA number. You can find it in your Google Analytics account.

Note: Google Tag Manager currently supports only the basic Google Analytics tag. Future releases of Google Tag Manager will allow you to customize your Google Analytics tag.

Next you need to specify the rules associated with your Google Analytics tag. The rules control which pages the Google Analytics tag will appear on. To learn more about rules see this post about understanding Google Tag Manager.

For this implementation we want to add the Google Analytics tag to appear, or fire, on every single page. We can use a default rule that meet this condition.

Add GA tag to all pages using GTM

Once you click Save GTM will save the tag in the container BUT the tag will not be pushed live to your site. You still need to publish the tag. And you should also Preview the tag before publishing, just to make sure it works right.

If you’re interested in learning more about the tag preview and publishing process check out my post on understanding how to preview and publish with Google Tag Manager.

A lot of you are probably thinking about more complex implementations, like those that require cross domain tracking. Right now a lot of those choices are not supported with the standard Google Tag Manager – Google Analytics integration.

But there is another way to implement Google Analytics with Google Tag Manager.

The Generic HTML Tag Method

If you have a more complex implementation, you can use the Generic HTML Tag for the implementation. This type of GTM tag is basically arbitrary HTML. You can put anything you want in this tag. This includes the Google Analytics tracking code and any customizations that you want to include.

Using GTM to Add A Custom Google Analytics Tag

As you can see, you can put the GA tag in the basic HTML tag, with any customizations that you want.

Is it more work than using the standard GTM GA tag? Maybe a little. But if you want to switch to Google Tag Manager ASAP, and you have a complex implementation, then this is the method for you.

Be Sociable, Share!

    Like this post? Sign up to get posts delivered to your inbox.


    1. says


      Are you sure about Google Tag Manager not supporting cross domain tracking? – I think that if you add your different domains within the same container, the cross domain tracking might be automated.

      Best regards,

      Søren Larsen Pedersen
      Web developer at Marketing Lion

      • says

        @ Tomáš: Yup, I have a couple of ideas. It requires a little bit of JS, but you can do it. First, you need to put your transactional data some place where GTM can access it, like the data layer. Then you need to pull it out of the data layer and put it into the ecommerce tag. For this, try using a custom HTML tag that references the ecommerce parts of the data layer. I don’t think a macro would help here. Macros are for holding data that is in the data layer, then referencing them in Rules.

        I like your thinking :)

    2. says

      Just wanted to ask something. Google Tag Manager does not seem to support codes that interacts with the content on the website. Services that convert keywords into ad links and so on. Is that right?

      • says

        @Sushubh: If I remember correctly, those service usually rely on some JavaScript. You have to place their JS library on your site and then their JS converts keywords to links. You can certainly host that third party JS using Google Tag Manager. Just use a Custom HTML tag.

        • says

          I saw this because it did not work for me. Even the New Tag page has this message:

          Custom HTML can be used to include any tag that doesn’t need to make visible changes to the page (visible changes include tags with ‘document.write’ functionality built into the snippet, or any A/B testing tag, so please don’t use them).

    3. Christopher says

      great posts – tag manager is my new favourite !

      I just wonder, does Google Analytics code implemented by Google Tag Manager cooperate with Content Experiments tag?

      or in second option is it possible to implement both Content Experiments code and then Google Analytics code in one custom tag?

      • says

        @Christopher: Great question. As of right now, you can not implement Content Experiments with Google Tag Manager because the Content Experiments tag needs to be at the top of the page. The container tag is placed after the opening < BODY > tag.

    4. Robert says

      Thanks for the informative posts. One thing I haven’t been able to find yet is if there is a usage limit for GMT. Is there something similar to GA Standard’s 10 million monthly pageviews?

    5. says

      Just saw the tag manager mentioned in today’s video from Distilled, so I searched it and landed here. Great description of how exactly to use this new tool. I will use it as a reference when starting out with the tool.

    6. says

      It took me a while to figure out how to use dataLayer with onclick events with GTM and GA but once it is in place it’s a breeze to use.

      About Content Experiments tags: I would like to do A/B testing with landing pages. Can I use GTM to deploy the tags required for this?


    Leave a Reply to Christopher Cancel reply

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

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>