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
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.
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.
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.
Step 5: Select ‘Variables’.
Step 6: Choose to define a new variable.
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.
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.
Step 9: Now we’re going to create the tag itself. Click ‘Tags’.
Step 10: Add a new tag.
Step 11: Name your tag (I named mine Google Analytics) and choose Universal Analytics as the tag type.
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.
Step 13: Here it is, pick this one:
Step 14: This is what your tag should look like so far.
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.
Step 16: Here it is, pick this one:
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.
Step 18: This is what it will look like when you move into Preview mode.
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.
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 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.
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!
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.