You are on page 1of 5

Chapter 2

Using Google Tag Manager


in Your Library

G
oogle Tag Manager, abbreviated GTM, launched can create new accounts and containers. An account
in 2012 and revolutionized how Google Ana- is a way to organize the various websites and mobile
lytics tracks website data.1 GTM is a separate applications you track. The container is an individ-
Google platform that uses a tag-based system to tell ual website or app that you are tracking. When you
Google Analytics (and various other data-tracking create a new container, a GTM tracking number and
products) what data gets tracked and how. You do not tracking code (referred to as the container snippet)
have to use GTM to add Google Analytics to a website, are automatically generated. The GTM container snip-
but it does greatly simplify several custom tracking pet must get added to every web page you want to
options such as event tracking. All of the case studies track. If your website already has Google Analytics
in this issue of Library Technology Reports recommend tracking code on it, that code must be removed as you
GTM and will provide advice on creating custom tags add the new GTM container snippet, or you will acci-
in the GTM interface for the different online library dently track your website’s data twice in your Google
tools and platforms. This chapter introduces GTM to Analytics account.
help you decide if it is time to implement it for your Ideally, the GTM container snippet should be
library. placed at the opening of the body tag (<body>) within
a web page for best data collection,2 but this is not
always possible if you do not have direct access to the
Getting Started with website’s code. The container snippet may be added to

Library Technology Reports  alatechsource.org  October 2016


Google Tag Manager another section of a web page, but it may miss some
data if users leave a web page before the script has
Since GTM is an additional Google product, you will the opportunity to fully load.3 Later chapters in this
need both a Google Analytics account and a Google issue of Library Technology Reports will discuss imple-
Tag Manager account. Google Analytics still tracks, menting GTM on different online tools to demonstrate
collects, and reports your website use data while GTM the best option for placing the container snippet for
tells Google Analytics how to function. Libraries with that specific tool. Once you add the container snip-
existing Google Analytics accounts need to create pet, almost all other customizations occur in the GTM
only a GTM account. administrative interface—so no additional code needs
to be added to the online tool itself.  

Google Analytics
https://analytics.google.com Creating Your First Tag in
Google Tag Manager
Google Tag Manager
https://tagmanager.google.com Once you create your first container, you are taken to
that container’s administrative interface to add any
tags, triggers, and variables that tell GTM how to func-
After creating a GTM account, you have access tion. A tag is script that runs on a web page and is usu-
to the GTM web administrative interface, where you ally based on a specific product like Google Analytics,

9
Google Analytics and Google Tag Manager  Tabatha Farney
Next, select Google Analytics as your
product. This will give you an option to
choose either Universal Analytics (analyt-
ics.js) or Classic Google Analytics (ga.js).
By now, you should be using Universal Ana-
lytics because it has more advanced features
and reports than its predecessor. Select Uni-
versal Analytics and click Continue. Add
your Google Analytics Tracking ID num-
ber. It should look like UA-xxxxxxxx-x (fig-
ure 2.1). If you do not have it memorized,
you can easily find this information within
your Google Analytics account. You will be
Figure 2.1
using this Tracking ID number a lot, so I rec-
Universal analytics tag, Google Tag Manager, University of Colorado ommend creating a custom GTM variable to
Colorado Springs store this number for reuse.4
Select Page View for Track Type, and
you can ignore display advertising features,
more settings, and advanced settings for this
tag. Click Continue, and you will reach the
Fire On section, which contains the trigger
options that tells the tag when to run. Since
we are adding the Google Analytics track-
ing code, you will most likely want to track
every web page on which the GTM con-
tainer snippet appears, so select All Pages
for this tag.
And you are done! Click the Create Tag
button and relax . . . but not for too long
because you still need to publish this change
to your GTM container before it takes effect.
GTM is a tag management system, so you
edit, test and debug, and save different ver-
sions of your containers all within the GTM
site.
Click on the Publish button within the
Figure 2.2 GTM interface to publish your container. If
Library Technology Reports  alatechsource.org  October 2016

Google Tag Manager debug window, Google Tag Manager, University you already added the container snippet to
of Colorado Colorado Springs your website, publishing the container auto-
matically pushes those updates to your web-
but you can also create and add your own custom site so that Google Analytics tag is now live. If you are
scripts. The trigger tells the tag it should fire (or run) using a newly created Google Analytics Tracking ID
on a specific web page or action based on if the variable number, it will take Google Analytics roughly twenty-
(some value) is true. This may sound complicated, but four hours to start displaying data in its reports.
the GTM administrative interface is fairly easy, with Additionally, you can click the down arrow next
a point-and-click functionality that walks you through to the Publish button to select the Preview and Debug
the entire process. All you have to know is what you option to determine if your tags work as expected.
want to track and when you want to track it. Simply select this option and open your website in the
No matter what type of online tool you are track- same web browser. As your browser loads your web-
ing, the first tag you should always create is a Google site’s web page, the GTM debug window (shown in fig-
Analytics tag to sync your Google Analytics account ure 2.2) will open at the bottom of the screen and list
to your GTM container. This connects GTM to your the tags that fired and the ones that did not. Again,
Google Analytics account. To do this, go the Tags area the GTM container snippet must already be added
within your GTM container and click on the New but- to your website in order for this to work. Your newly
ton. Once on the new tag screen, name your tag to created tag should be firing, so can you publish your
help organize your tags. Use whatever naming con- changes knowing it is working.
vention makes sense for your library.

10
Google Analytics and Google Tag Manager  Tabatha Farney
Creating Events in Google you can capture any data point on your site you can
Tag Manager uniquely identify.

You successfully created your first GTM tag to sync Creating an Outbound Link Event Tag
your Google Analytics to your website! Next, you
should focus on tags for those useful Google Analyt- Creating an event tag takes only a few minutes if you
ics events.5 Recall that an event is any user action know what event you want to track and how you want
that cannot be automatically tracked by Google Ana- to track it. In the Tag section of your GTM container,
lytics. Common events are clicks on outbound links follow these steps to create an outbound link event tag:
(links that navigate users away from the website),
document downloads, and other script-based features. 1. C
lick on the New button in the Tag section of your
Previously, if you wanted to collect data associated GTM container.
with these events, you needed to add Google Analyt- 2. Name the new tag. For this example, I am creating
ics’ event-tracking script to each event you wanted an outbound link event, so I name this tag Out-
to track. GTM replaces this tedious process with a bound Link Event.
simple event tag—no direct editing of your website’s 3. Under the Choose a Product section, select Google
code required. Before you create an event tag, you Analytics. As with your first tag, select Universal
should have a good understanding of how GTM trig- Analytics. Click the Continue button.
gers and variables function so you can leverage their 4. Add your website’s Tracking ID number. This might
full capability. seem redundant since you already created the tag
to sync your Google Analytics account to the GTM
Triggers container, but you will repeat this process with
each new event tag because it connects the event
Triggers tell the GTM tag when to fire and collect data back to your Google Analytics account.
data. Currently, GTM allows for seven types of trig- 5. Since this is an event tag, change the Track Type
gers: Page View, Click, Form Submission, History from Page View to Event. This will display the event
Change, Custom Event, JavaScript Error, and Timer.6 tracking parameters where you can add informa-
For example, a Page View trigger is useful when a tag tion for the event’s category, action, and label.
needs to be fired as a user loads a specific web page. 6. You can ignore most of the other event options, but
To create a trigger, select the trigger type and add the you should fill in the event’s Category, Action, and
conditions to make the trigger fire. In the case of the Label boxes as shown in figure 2.3 on the follow-
Page View trigger, you can select all web pages, or ing page. Both the category and action are names
you can define the web page or web pages based on I chose to describe those options, while the label
the unique identifier within the page’s URL. If you are uses the GTM system variable {{Click URL}}.
not familiar with regular expressions (RegEx), this is Each time this event tag is fired, it will report these
a good time to learn because it is an excellent method data points in Google Analytics Event reports.
for defining unique strings for the different trigger 7. Under the Fire On section, select the Click option

Library Technology Reports  alatechsource.org  October 2016


types. I recommend LunaMetrics’ Regular Expressions because this tag requires a Click-based trigger to
for Google Analytics as a great starting place.7 fire only on clicks to outbound links.
8. Select the New button on the Click Triggers pop-
System and User-Defined Variables up window.
9. Name your new Click trigger. I called mine Out-
Recall that variables are just pieces of data that are bound Link.
stored or collected by GTM. GTM variables are easy to 10. Under Configure Trigger, select Just Links as the
identify because they always use double curly brack- Targets. This will look only at clicks on web links
ets to indicate a variable (e.g., {{variable name}}). rather than any element on the web page.
GTM comes with a series of built-in system variables 11. Deselect Wait for Tags and Check Validation
you can enable in the container’s Variables section. options—these are useful for testing but increase
For example, {{Click URL}} is a system variable that web page load time as it waits for the tags to load.
has GTM collect the URL of the web link a user clicked 12. Under the Fire On options, select Some Clicks
and this URL will be displayed in your Google Analyt- because this tag should fire only on clicks to out-
ics reports. Another useful system variable is {{Click bound links.
Text}}, which collects the web link’s text when a user 13. Finally, you get to define an outbound link for this
clicks on it. Google provides excellent documentation trigger. I define an outbound link as any link not
for all its system variables,8 but GTM can send Google within the website I am tracking. In this exam-
Analytics even more data with User-Defined (custom) ple, my library website is http://www.uccs.edu
variables. With a little bit of scripting knowledge, /library. Any site that does not contain the string

11
Google Analytics and Google Tag Manager  Tabatha Farney
uccs.edu/library in its URL is con-
sidered a separate website. In GTM,
this translates to the system variable
{{Click URL}} Does Not Contain
uccs.edu/library as shown in fig-
ure 2.4. I also removed mailto (e-mail)
links as those are tracked in a separate
event tag.
14. Click the Create Trigger button to cre-
ate and save the new trigger in the GTM
container.
15. This takes you back to your Outbound
Link Event tag with the Outbound Link
trigger added to it. Click the Save Tag
button to finish this process.

You will repeat this process with differ- Figure 2.3


ent event parameters and triggers for each Outbound link tag, Google Tag Manager, University of Colorado Colo-
event you want to track on a website.
rado Springs

Testing Your Tags


I have witnessed individuals using great
GTM tags but bypassing the testing phase
only to find out later that some tags were
not working as planned. One setting could
be off in a variable or trigger that causes
the tag to track the wrong data, which
leads to bad data in your Google Analyt-
ics reports. This is unfortunate because it is
not possible to delete specific data within
your Google Analytics account. Rather than
suffer needlessly, take the time to test your
tags! I recommend a two-step process: first Figure 2.4
to determine if the tag is firing properly, Outbound link trigger, Google Tag Manager, University of Colorado
and another test to ensure it is collecting Colorado Springs
Library Technology Reports  alatechsource.org  October 2016

the correct data.


The first test was already mentioned—use GTM’s website. New event tags can be added at any time in
preview mode before publishing the new container the GTM container, but planning will help you stan-
version. This will tell you if the tag is firing as planned. dardize the naming convention for your event catego-
After you ensure your tags are firing properly, open ries, actions, and labels, which will keep your data
up the Real-Time reports in your Google Analytics reports cleaner. It will also help you think strategi-
account. For event tag testing, you can use the Real- cally about what insights you want to gain from the
Time Event report to see what data your event is col- data.
lecting while still in the Preview and Debug mode.
This minimizes the potential of collecting wrong data.
Notes
If you are happy with your event data, you can con-
fidently publish the changes to your GTM container. 1. Laura Holmes, “Digital Marketing Made (Much)
Within twelve to twenty-four hours, that new data Easier: Introducing Google Tag Manager,” Google
will be available in your Google Analytics reports. Analytics Solutions blog, October 1, 2012, http://
analytics.blogspot.com/2012/10/google-tag
-manager.html.
2. “Quick Start Guide,” Google Tag Manager, accessed
Conclusion February 29, 2016, https://developers.google.com
/tag-manager/quickstart.
Before you start tracking events in GTM, you should 3. Justin Boyle, “Where Should the Google Tag Man-
create a list of events you want to track for each ager Snippet be Placed?” LunaMetrics, December 12,

12
Google Analytics and Google Tag Manager  Tabatha Farney
2014, www.lunametrics.com/blog/2014/12/12 8. “Variables,” Google Tag Manager Help, accessed
/google-tag-manager-snippet-placement. February 29, 2016, https://support.google.com
4. “Unit 2, Lesson 2: Set Up a GA Property Variable,” /tagmanager/answer/6106899?hl=en.
Google Analytics Academy, accessed February 29,
2016, https://analyticsacademy.withgoogle.com
/course05/unit?unit=2&lesson=2. Other Resources
5. “About Events,” Google Analytics Help, accessed
February 29, 2016, https://support.google.com
/analytics/answer/1033068?hl=en. “Google Tag Manager Fundamentals,” Google
6. “Triggers,” Google Tag Manager Help, accessed Analytics Academy, accessed February 29, 2016,
February 29, 2016, https://support.google.com https://analyticsacademy.withgoogle.com
/tagmanager/answer/6106961?hl=en. /course05.
7. Robin Steif, Regular Expressions for Google “Welcome to the Google Tag Manager Help Center,”
Analytics (Pittsburgh, PA: LunaMetrics, 2010),
Google Tag Manager Help, accessed February 29,
www.lunametrics.com/regex-book/Regular
-Expressions-Google-Analytics.pdf. 2016, https://support.google.com/tagmanager.

Library Technology Reports  alatechsource.org  October 2016

13
Google Analytics and Google Tag Manager  Tabatha Farney

You might also like