Summary: Step-by-step instructions for how to switch your website over to Google Tag Manager without losing any of your existing Google Analytics data.

Using Google Tag Manager to manage your Google Analytics and other tags is great – once you start using it you’ll be so glad you made the switch! This post is available in text and video format below

I always install Google Tag Manager on a website and use that to handle Google Analytics rather than adding Google Analytics directly.

The reason I use Google Tag Manager instead of just using Google Analytics is that Google Tag Manager makes it really easy to also track website events in Google Analytics and to send conversions to your advertising platforms. This lets you track if people are clicking specific links, submitting your contact forms, adding products to their cart etc.

There is so much that can be done with Google Tag Manager but I’ll save that for dedicated posts.

In this post I will cut straight to the “how to” aspect of the specific steps involved in creating a Google Analytics tag in Google Tag Manager. You can follow along and easily install Google Tag Manager on your own website.

In this example I’ll also show you how to set your Google Analytics tracking code as a variable in Google Tag Manager so that you can refer to the tracking code whenever you need without having to look it up each time.

Prefer video? Here is the video version of this post

Instructions

Step 1: If you don’t yet have a Google Tag Manager account, then set one up at https://tagmanager.google.com. To do that you need to go to Admin –> Account –> Create Account. Choose a name for your account and then click Continue.

Adding Google Analytics to Google Tag Manager

Step 2: Next up, create a container for your Google Tag Manager tag. This will be named according to your website name, e.g. www.mysite.com. You will also need to choose a container type. ‘Web’ is the container to choose for a website.

Adding Google Analytics to Google Tag Manager

Step 3: Once you’ve agreed to the terms of service, Google will create two snippets of code that need to be installed on your website. These are installed in the head section of your website and the top of the body section of your website respectively. Most website themes should give you a way to add these snippets of code as part of the theme itself, but if not there are plugins you can use. You are most likely already using your theme or a plugin to deploy the Google Analytics tag, so deploy these using the same way. If you are unable to get the body code installed at this stage (as of 2017 some themes and plugins haven’t caught up to adding tags to body yet), your Google Tag Manager will work fine in the majority of cases with only the head code. The body code is used when your website is viewed on a device in which javascript is unavailable. Here’s what the tag code snippets look like.

Adding Google Analytics to Google Tag Manager

Once you have got the tags on your website it’s time to set up Google Analytics in your Google Tag Manager.

Step 4: Go to the Google Tag Manager container that has been set up for the website.

Adding Google Analytics to Google Tag Manager

 

Step 5: Select ‘Variables’.

Adding Google Analytics to Google Tag Manager 2

 

Step 6: Choose to define a new variable.

Adding Google Analytics to Google Tag Manager 3

 

Step 7: Type a name into the space at the top. It defaults to Untitled. A suitable name is GA Tracking Code or something similar. Then choose a variable type of Constant.

Adding Google Analytics to Google Tag Manager 4

 

Step 8: Add your Google Analytics tracking code as the variable value and save it! You can now use this tracking code variable any time you need it.

Adding Google Analytics to Google Tag Manager 5

 

Step 9: Now we’re going to create the tag itself. Click ‘Tags’.

Adding Google Analytics to Google Tag Manager 6

 

Step 10: Add a new tag.

Adding Google Analytics to Google Tag Manager 7

 

Step 11: Name your tag (I named mine Google Analytics) and choose Universal Analytics as the tag type.

Adding Google Analytics to Google Tag Manager 8

 

Step 12: Google Tag Manager wants to know the Tracking ID for your Google Analytics instance. You are going to use your variable here! Click on the little lego button and it will show you the variable you previously created.

Adding Google Analytics to Google Tag Manager 9

Step 13: Here it is, pick this one:

Adding Google Analytics to Google Tag Manager 11

Step 14: This is what your tag should look like so far.

Adding Google Analytics to Google Tag Manager 13

There is one more setting that you will need before your tag is completed. Click on More Settings –> Fields to Set –> Field Name and add the following field: Field Name – cookieDomain, Value – auto.

This will set your Google Analytics to behave in the same way as an out-of-the-box Google Analytics tag, which is to include tracking over subdomains by default. Without this setting Google Analytics will not work over subdomains.

Step 15: A trigger is an event that causes information to be sent to your Google Analytics account. We want Google Analytics to fire every time a visitor views any webpage on your account. Just click on the circle to choose the default ‘All pages’ trigger.

Adding Google Analytics to Google Tag Manager 14

 

Step 16: Here it is, pick this one:

Adding Google Analytics to Google Tag Manager 15

 

Step 17: Your tag is complete! You are ready to publish Google Analytics to your website via Google Tag Manager. Before you do though, it is very important to test it out. To test your Google Analytics tag, click the ‘Preview’ button. The Preview button moves your Google Analytics tag into a state whereby if you visit your own website from your current browser it will act as though your Google Analytics tag is published. However no other visitors can trigger your tag until it is published.

Adding Google Analytics to Google Tag Manager 16

 

Step 18: This is what it will look like when you move into Preview mode.

Adding Google Analytics to Google Tag Manager 17

 

Step 19: Go to your website from within the same browser and the Google Tag Manager preview app should pop up at the bottom of your screen. If your tag is working then you should see the message ‘Google Analytics Universal Analytics – Fired 1 time(s)’. If you don’t get this message, check that the Google Tag Manager tracking code has been correctly added to your website and that the tracking code value matches the tracking code for your Google Tag Manager web container.

Adding Google Analytics to Google Tag Manager

 

Step 20: Once you are satisfied that the Google Analytics tag is firing, you can disable preview mode and then publish your tag. Hold off a minute on publishing though.

At this point, if you don’t already have Google Analytics on your website then you can just go ahead and click the Publish button. However, since this blog post is about how to switch over from Google Analytics to Google Tag Manager I’m assuming you already have Google Analytics installed. In order to switch over to Google Tag Manager you need to remove the Google Analytics tag when you publish the Google Tag Manager tag. It doesn’t much matter which order you do this, but you’ll want to do them as close together as possible so that you don’t experience much time without any tracking, or much time with both tags tracking. I generally remove Google Analytics first and then immediately publish Google Tag Manager.

Step 21:To remove Google Analytics you need to remove the Google Analytics snippet of javascript code from your website. It will be located within the head section on every page of your website and was most likely installed via a theme or a plugin. You might have found it when you installed the snippets of Google Tag Manager code page at step 3. When you remove your Google Analytics code from the head section of your website you won’t lose any of your existing Google Analytics data. You won’t see any new data however until you publish Google Tag Manager. Go ahead and remove your Google Analytics code from your website and then come back to Google Tag Manager and click Publish.

Adding Google Analytics to Google Tag Manager 19

 

Step 22: Before you can finish publishing, Google Tag Manager asks you to name this revision and describe what the change is, so that if you want to roll back you can do so easily. Type in a suitable name and description that you will understand. Click the ‘Publish’ button to finalize this step.

Adding Google Analytics to Google Tag Manager 20

 

IMPORTANT NOTE! Now that your tag is published it should all be working fine, but you do need to test it again. To double check that everything is setup correctly, go to http://www.gachecker.com and check that there is a tick under Google Tag Manager. I usually also right click on the website (after refreshing) and select view source. I manually search for the Google Tag Manager tracking code and the Google Analytics tracking code. The Tag Manager code should be present and the Google Analytics code not present.

Step 23: Now your Google Analytics tag is live on your website. You can test this by navigating to your website again and then going to your Google Analytics ‘All Website Data’ view (or any view that doesn’t filter out your own IP address). If you click on the Real-Time overview in the reports you will see that data is now coming through. You are done!

Adding Google Analytics to Google Tag Manager 21

What’s next?

If you are responsible for digital marketing you will need to know how to collect and read numbers. This will improve your results and help you to generate more revenue from your online presence.

If you would like even better digital marketing results then I guarantee that I can help you with that. Getting started is simple – just subscribe to my free web analytics training by filling out the form below.

get better results from your digital marketing

Share this article!

Success is in the numbers. But which ones?

Are you responsible for digital marketing? Learn more about how to collect and use the numbers for even better results.

SleepWise Clinic

Petra was instrumental in pulling all our clinic's web analytics into one easy to read, dynamic report that's accessible to me at any time, and works with our EXACT booking system.

This has allowed me to see, at a glance, what marketing initiatives are working, need tweaking, or changing altogether, saving me both time and money. I can't recommend her or her analytic services enough.

Ian Gale SleepWise Clinic Strategy Session August 1, 2018

shares