The Google Tag Manager (GTM) tool gives the website owner a large number of helpful tools that assist with the management of Google Analytics and other tags (eg: statcounter, amazon associates, etc.) that he or she may want to add to the site.
Why Use Google Tag Manager?
The Google Tag Manager allows the site admin the ability to preview, test and debug before the tags go live, minimizing the risk of gathering bad data or missing the collection of valuable data.
GTM also allows the site admin to add new code inside the GTM so they don’t have to touch the website’s code again for this purpose.
This tutorial is going to focus on the basic setup of Google Analytics within the Google Tag Manager.
If you haven’t signed up for Google Tag Manager, that’s the first thing you need to do. The best idea is to use the same account that your Google Analytics (GA) and Google Search Console (GSC) use.
After signing in, you will land on the GTM home dashboard. If you have other sites that use tag manager, they’ll show up here, as in the picture below, but if this is your first site, this space will be empty with the exception of the Create Account button at the top left.
Setup The GTM Account
In the account name field, you can either use the site name, or the company that the account is for.
Then click the continue button.
Setup the GTM Container
Next, we want to put in the domain that this tag is going to go on. This is the www.DOMAIN.com without the http:// or https:// and without the trailing slash.
Next, select the Web since this tag is going on a website.
Accept The Google Tag Manger TOS
Click the YES button on the upper right to accept.
At this point a box will pop up that contains the code you need to place on your website.
Installing the Google Tag Manager Code on your site
After clicking the yes button, you will see the following window pop up. There’s two boxes with codes. The top box goes in between the <head> and </head> tags, and the code in the bottom box goes right after the <body> tag.
In WordPress specifically, you can usually insert the top and bottom box into the header.php file of your theme. 90% of the time, theme developers will have both the head and opening body tag stored here (eg: Elegant Themes Divi or the Studiopress Genesis Framework).
REMEMBER: If there is a Google Analytics code (or any other tracking code that you want to insert into GTM) already on the site, then this is the time to remove those from the code.
Make sure to save the file before returning to the Google Tag Manager setup page.
At this point, Google tag manager has been setup on the site, and returning to the GTM dashboard, you can close the popup box that has the code.
You will now see the main dashboard for the site.
Add Google Analytics To Google Tag Manager
In the GTM Dashboard, you will now add a new tag. Click on the Add A New Tag box
At the top of the box that slides out from the right, you will see a line that says “Untitled Tag“. Give your tag a name. You can name it anything you want, but if all this tag is for is for Google Analytics, you might give it “GAnalytics” as a name.
Now we will choose the type of tag and configure the trigger for when that tag will be fired. What that means is that we’ll configure Google Analytics in the tag configuration, and have it fire when someone comes to the site and lands on any page or post.
Click “Choose a tag type to begin setup…” in the top box. Another box will slide out on the right, titled “Choose Tag Type”.
The tag type selector will move back off to the right, and you’ll be back at the Tag Configuration screen. The box has changed a bit and you’ll see two drop downs now.
We want GTM to work the way that Google Analytics did previously (not changing anything), so we will leave the top “track type” dropdown at Page View.
Next, click on the Select Settings Variable dropdown.
You will now see the variable configuration screen slide in.
Add your Google Analytics ID here. You will find you GA ID back in the Google Analytics Admin dashboard for the site.
To Find it, click the Admin gear in Google analytics found in the lower left. Then select the Account, then Property, and select property settings from the list under Property.
Add this code to your Google Tag Manager. Leave the Cookie Domain alone.
Then Click SAVE.
If you haven’t renamed the variable, then do so now.
At this point, the tag configuration is done, and it’s time to move on to the triggering.
Configure The Tag Triggering
Click on “Choose a trigger to make this tag fire…”
The trigger window slides out from the right, and just click on the All Pages text to set the trigger.
At this point, the Tag Configuration and Triggering are complete, and the screen should look like this:
Click the save button in the upper right.
Your dashboard should now look like this:
Preview and Publishing Your New Tag
This is where it gets exciting folks! On the upper right, you’ll see two buttons: Preview and Publish.
First thing to do is click the Preview button.
Google Tag Manager dashboard will reload and look like this:
Now that preview mode is enabled, open a new tab and go to your website.
After your site loads, a couple seconds later the Tag Manager overlay will pop up and show you the tag status. If the tag manager code was added properly, and you followed the above steps correctly, then you should see the Universal Analytics box under “tags fired on this page” section.
If it didn’t work, either you won’t see this overlay, or there will be nothing under the tags fired section.
Provided that the Universal Analytics box show up under the tags fired, you can publish the tag as it’s confirmed working.
Just go back to the Tag Manager and click the Publish button in the upper right corner.
Now, nothing immediate will seem to happen after you hit publish. If you go back to your Google Analytics dashboard right away, you won’t see anything happen. There’s a bit of a leap of faith that the tag is doing it’s thing, so you’re just going to have to wait.
I’ve seen data come in anywhere between eight hours and some time the next day after a tag goes live.
Best thing to do is check on it in the evening if you published it that morning, or check the next day if you published in the afternoon or evening.