Google Analytics Google Tag Manager (GTM)

How to Add Google Analytics to Google Tag Manager

Looking to add Google Analytics to your website through Google Tag Manager? Maybe you have GTM installed but don’t have direct access to the code to place GA directly. Maybe you want to keep all of your tracking scripts in one place, within a GTM container. Either way, here’s how you add the GA tracking code to via GTM.

It’s a given, but first you need to make sure you have a Google account with both Analytics and Tag Manager setup. Assuming you’ve done that, let’s get started.

Create a GA Tracking ID Variable in GTM

Firstly, load up your GTM workspace and we’ll start by creating a variable to house your Google Analytics Tracking ID.

Click Variables on the left-hand menu and then click the New button under User-Defined Variables.

Give this new variable a name – something like ‘GA Tracking ID’ – and click the Variable Configuration area to select a variable. From the menu that slides in from the right, scroll down to the Utilities section and select Google Analytics Settings. This is a special type of variable designed specifically for GA and we need to get the actual GA Tracking ID to put in it.

Open a new browser tab and load up Google Analytics. Go into the property you want to track, select Admin from the menu on the left to be taken to the admin menu. From there, under Property (middle column) click Tracking Info which should list a few more options underneath and select Tracking Code.

On this page you can see your Tracking ID. It should look something like UA-123456789-1.

Copy your Tracking ID, go back to GTM and paste it in the Tracking ID field. Don’t do what I did and literally type the fake UA-123456789-1 ID in there, then wonder why it isn’t working later on – duh!

Leave the rest of the settings as they are for a basic setup. Click Save and that’s it – your variable is now setup and ready to use in the tag that we’ll create next.

Create a Google Analytics Tag

Now it’s time to create the Google Analytics tag itself in GTM. To start, go to the Tags view using the menu on the left and click New.

Give it a name – something as simple as ‘Google Analytics’ will do – and click the Tag Configuration area to select the type of tag we need.

The one that you’re looking for should be right up the top. It’s called ‘Google Analytics: Universal Analytics’. There are a couple of other options there but for a basic setup I would choose this one. So, select that tag and you should be given a couple of fields to configure.

To start with, keep the Track Type field as Page View. At the moment we’re simply looking for the basic Google Analytics implementation which sends through 99% of data to GA.

For Google Analytics Settings, we’ll need to choose the variable we created earlier. Select the dropdown field and choose {{GA Tracking ID}} or whatever you names yours. We could’ve created the variable here at this stage by selecting New Variable but for clarity we split the process clearly.

Leave the Advanced Settings alone as we don’t need them for this basic setup.

The final step is to select the Trigger to cause the Tag we’ve just created to fire. For this, click the Triggering area to bring up a list of potential triggers. More than likely, the only trigger in the list that shows up will be named ‘All Pages’. Luckily for us, this is the one we need! Select it and we’ll return to the tag view. Your tag should look something like the image below:

If so, click the blue Save button at the top right of the screen to return to the workspace view.

We’ve now got our tag setup; on all pages, the Google Analytics tracking code will be loaded and it will send off page view information to GA with the Tracking ID that we set. Brilliant!

Now it’s time to test it.

Check That It’s Working

Use GTM’s Preview Mode

To see if the newly created tag is working, click the Preview button next to the blue Submit button at the top right of the screen. This will refresh the page and put GTM into ‘Preview Mode’. In Preview Mode, GTM displays information in a ‘drawer’ when you load up your website that has this GTM container installed. See for yourself – go to your website (refresh the page if you need to) and you should see an area at the bottom of the screen dedicated to Google Tag Manager.

If you see your ‘Google Analytics’ tag listed there in the Summary window under the ‘Tags Fired On This Page’ section, that’s great news – the tag has successfully been triggered!

Although this all looks good, let’s double-check things. With tracking there’s a million and one things that could mean it doesn’t actually work. The true test is checking if Google Analytics is receiving any data.

Check Google Analytics’ Realtime Report

To see if GA is actually picking anything up, we’ll need to leave Preview Mode in GTM and publish the updated container. Go back to GTM and click ‘Leave Preview Mode’ and then ‘OK’ to confirm. The page should refresh and the orange preview area should disappear.

Next, to publish the updated container click the blue Submit button at the top right of the page, then click the blue Publish button. Give this version of the container a name – it’s good practice to get into – otherwise click Skip to go ahead and publish the container.

Once the container is published, you should see a version summary page. This is our cue to check Google Analytics.

Open up Google Analytics again and navigate to the ‘Realtime’ report by selecting it from the menu on the left. Once there, load up your website – give it a refresh to be on the safe side – and start clicking around to a couple of different pages. If all has gone according to plan, you should see your pageviews start showing up in real-time within Google Analytics. Mission accomplished!

I hope that’s helped you get Google Analytics setup via Google Tag Manager. If you have any issues, please let me know in the comments below and I’ll try and help you.

Leave a Reply

Your email address will not be published.