In this post, Ignite Visibility Project Manager Josh Livecchi teaches you how to track your SEO goals with Google Tag Manager.
One of the best tools in the arsenal of a digital marketer is a tag. That’s a custom snippet of code, running on a website or app, that sends information to a third party system.
That third party system can aggregate the information it receives to provide analytics. Those analytics can be invaluable in determining marketing strategies going forward.
The problem with tags is that there are a lot of them. If you want your website to send different types of data to various third-party systems, you’ll need to deploy separate tags to specific pages on your website.
That gets pretty ugly.
Enter Google Tag Manager (GTM), your one-stop shop for managing all your tags without the aid of a developer.
How Google Tag Manager Works
Google Tag Manager offers you a container tag that you place on all your website pages. If you want to use it in a mobile app, you’ll deploy it with Firebase SDK.
The container tag replaces all the other tags on your site, including tags from Google such as Google AdWords and Google Analytics.
GTM doesn’t just support Google tags, though. It also supports several other third-party tags.
Once you’ve added the Google Tag Manager code to your site, you can add, update, and administer tags on your site from a user-friendly Google console. No developers are needed.
Tags “fire” at your discretion. For example, you can set up tags to fire whenever any page on a website is visited by somebody. Alternatively, you can also set up tags in response to events, such as when a customer removes an item from a shopping cart.
You can also use variables (some custom and some pre-defined) to help define triggers and the data that they send. For example, you might set up variables for cookie values or page URLs.
Although you can set up several GTM accounts, you’ll typically only need one account for all of your websites. You can, however, set up multiple containers with just one account.
Once you’ve set up your account, here are some tips for getting the most out of GTM.
Setting up Analytics With User-Defined Variables
Before you get too deep in the weeds with GTM, Google recommends that you set up a few user-defined variables that will save you time later on.
What’s the point of variables? They simplify your life so you don’t have to enter difficult-to-remember and/or lengthy values over and over again.
For example, do you know your GA tracking ID off the top of your head? Probably not. With Google Task Manager variables, you can associate your tracking ID with an easy-to-remember variable name and simply reference that variable name when using GTM.
Here are some variables you should set up:
- gaProperty – Your Google Analytics (GA) Tracking ID. Set this variable to the value of your Tracking ID just once, and you never have to remember it again.
- gaDomain – Used to establish Automatic Cookie Configuration for a particular domain. It’s considered a best practice for GA. Set this variable to “auto.”
- gaCrossDomains – Used to set up cross-domain tracking if you have traffic moving between multiple domains. Set this variable to a comma-separated list of all your domains once and you won’t have to update all your GA tags.
Good news: you don’t have to define all your own variables in GTM. Google has already defined many widely used variables for you.
The pre-defined variables fall into several categories: page variables, utility variables, error variables, click variables, form variables, and history variables.
Here are the pre-defined page variables:
- Page URL – The full URL of the current page.
- Page Hostname – The domain name of the current page.
- Page Path – The relative path of the current page (for example, “/myArticle”).
- Referrer – The full URL of the page which brought the visitor to the current page.
Here are the pre-defined utility variables:
- Event – The value stored in the “event” data layer key.
- Environment Name – The name of the environment being previewed. An environment can be a testing or staging environment that QA people use before sending a website into production.
- Container ID – The ID of the GTM container.
- Container Version – The version of the GTM container.
- Random Number – A random number between 0 and 2,147,483,647.
- HTML ID – The ID of the custom HTML tag (use with Tag Sequencing).
Here are the pre-defined click variables:
- Click Element – The HTML element that was the target of an auto-event. An auto-event is an action on a tag that causes GTM to collect and identify what just happened. Clicks and form-submissions are examples of an auto-event.
- Click Classes – The value contained in the class attribute of the auto-event element.
- Click ID – The value of the id attribute in the auto-event element.
- Click Target – The value of the target attribute in the auto-event element.
- Click URL – The value of the href or action value of the auto-event element.
- Click Text – The value of the textContent or innerText attribute in the auto-event element.
Here are the pre-defined form variables:
- Form Element – The HTML element that was the submitted form.
- Form Classes – The value contained in the class attribute of the form element.
- Form ID – The value of the id attribute in the form element.
- Form Target – The value of the target attribute in the form element.
- Form URL – The value of the action value of the form element.
- Form Text – The value of the text in the form element.
Here are the pre-defined history variables:
- New History Fragment – The new URL fragment following a page history change auto-event action.
- Old History Fragment – The previous URL fragment.
- New History State – An object containing the new history state.
- Old History State – An object containing the old history state.
- History Sources – The event that initiated the history change.
Tracking Form Submits with GTM Codes
One of the best features of GTM is its ability to track form submits. That’s useful to webmasters who are tracking conversion analytics.
To track form submits, you set up a Form trigger within GTM. The settings for the trigger are as follows:
- Wait for Tags – GTM will halt the form submit until all tags that use the trigger have fired or the timeout limit is reached. The default timeout is two seconds.
- Check Validation – GTM won’t fire the trigger event if the form submit fails validation. For example, if a user didn’t enter a mandatory field such as a zip code, then the trigger event won’t be fired.
- Enable When – Determines which pages GTM should listen for submissions.
- Fire On – You can specify that the trigger event gets fired when a variable (for example, form ID) is equal to a specified value.
We’ve already seen the GTM variables associated with form submissions. You can use those to simplify form tracking.
You can, however, track all types of input variables from a form, including text fields, radio buttons, check boxes, and drop-down lists.
Perhaps best of all, though, is you can track form abandonment. That will give you some insight as to whether your form has too many fields to fill out.
GTM also allows you to track custom Google Analytics events
GTM also allows you to track custom GA events (such as a click on a specific page) for tracking purposes.
Note that there’s a difference between GA events and GTM events. GA events are hits sent in response to GA tags fired from GTM. GTM events are user interactions with web page elements (called DOM elements).
Of course, to track customer GA events, you must first have added a Google Analytics page tracking tag. Make sure the tag fires on all pages.
To enable GTM to track URLs that visitors click on, we’ll use a pre-defined variable that we’ve already seen: the Click URL variable.
Just fire up GTM and click on “Variables” on the left-hand navigation. Then, check the box next to “Click URL.”
Then, click on “Triggers” on the left-hand navigation and create a new Click trigger. Use the following settings:
- Type: Click
- Target: Just Links
- Check “Wait for tags”
- Leave the default of Max wait time (2000ms) alone
- Uncheck “Check validation”
- Enable When: Click “URL contains” and then select a unique part of the URL you’d like to track
- Fire On: All Clicks
- Save the trigger with a descriptive name
Now, for that same trigger, you need to add a GA event tracking tag. Click on “Tags” on the left-hand navigation and create a new tag with these settings:
- Tag: Universal Analytics
- Click on “Triggers”
- Name: Anything descriptive
- Tag Name: Again, anything descriptive but it should include “UA” in it for “Universal Analytics”
- Track Type: Event
- Category: Nav
- Select “Action”
- Label: Another descriptive name
- Save the tag with a name that identifies it
Finally, publish the tag.
That’s it. Now you’re tracking custom GA events.
You can also use GTM to set up similar events, such as form submissions, clicks on specified elements, and even timed intervals.
As with anything else in IT, be sure to test in an isolated environment before rolling out your changes to production. Make sure that you’re tracking the right data otherwise you could end up making bad decisions based on inaccurate information.