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 handle 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

These days 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 such as clicking specific links, interacting with video etc. There is so much that can be done with Google Tag Manager but I’ll save that for a dedicated post.

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 so that 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


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 18

 

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




Web Data Analytics specialises in growing your conversion rate online. Current and past clients include e-commerce in B2B and B2C industries, lead generation websites and corporates. Petra Manos is experienced in tracking and interpreting website visitor interactions, improving website conversion rate, and attributing online sales to marketing channels. Please call Petra on 0405 123 696 today, email petra@web-data-analytics.com, or visit http://www.web-data-analytics.com.

Share this article!

Nicholls Web Consulting

Utilising Web Data Analytics findings, we have made significant discoveries in user behaviours, and made recommendations based on the available data ensuring that our clients have a well-informed view on their customer’s actions within the web environment. We have found insights from Web Data Analytics have influenced our recommendations in terms of channel spending, and also ways to increase customer conversion based on optimization efforts. I have found Petra easy to deal with and, importantly to us, this works in with our objectives to ensure our clients success.

Eben Nicholls Director - Nicholls Web Consulting Strategic Analysis Report, Booking Gateway Attribution Report June 21, 2017

Erica Stacey Scout Digital

I recently worked with Petra to improve my understanding of Google Tag Manager.

Petra not only provided a solid overview of GTM set up and event tracking, she also provided many tips on best practice, and answered the questions that I didn't even know to ask!

Petra is patient, fun to work with, and her analytical programming mind is hell bent on finding the BEST solution to any data, analytics or tracking problem.

Erica Stacey Scout Digital Marketing Strategy Session June 21, 2017

keneena fanning

This dashboard is sooo much easier to read than the Google Analytics one. I love that you explain what each table means underneath - super helpful. I definitely love visual rather than written info so the graphs are great - and make it much easier to see trends etc. Especially helpful to see where traffic is coming from and how it's converting so I can see where to focus my efforts.

Keneena Fanning Kablooie Store Basic Dashboard May 25, 2017

Nick Hughes

We now have greater insights into how many people visit our site and when, where they come from and the detail of our traffic sources. Glad I spent the time with Petra to cut straight to the insights in our data. Time well spent!

Nick Hughes Successfully Navigating Redundancy Strategy Session May 25, 2017

default gravatar

Petra helped me set up many aspects of Google Analytics, and I now feel confident in finding the information I need. It's definitely increased my understanding of my website audience and the data that comes out of it massively!

Hannah Noble Nipenda Blog May 25, 2017

shares

Subscribe for educational articles written by Petra Manos, the founder of Web Data Analytics

track more
x