Chapter 2. Using Google Tag Manager in Your Library

Google Tag Manager, abbreviated GTM, launched in 2012 and revolutionized how Google Analytics tracks website data.1 GTM is a separate Google platform that uses a tag-based system to tell Google Analytics (and various other data-tracking products) what data gets tracked and how. You do not have to use GTM to add Google Analytics to a website, but it does greatly simplify several custom tracking options such as event tracking. All of the case studies in this issue of Library Technology Reports recommend GTM and will provide advice on creating custom tags in the GTM interface for the different online library tools and platforms. This chapter introduces GTM to help you decide if it is time to implement it for your library.

Getting Started with Google Tag Manager

Since GTM is an additional Google product, you will need both a Google Analytics account and a Google Tag Manager account. Google Analytics still tracks, collects, and reports your website use data while GTM tells Google Analytics how to function. Libraries with existing Google Analytics accounts need to create only a GTM account.

Google Analytics

https://analytics.google.com

Google Tag Manager

https://tagmanager.google.com

After creating a GTM account, you have access to the GTM web administrative interface, where you can create new accounts and containers. An account is a way to organize the various websites and mobile applications you track. The container is an individual website or app that you are tracking. When you create a new container, a GTM tracking number and tracking code (referred to as the container snippet) are automatically generated. The GTM container snippet must get added to every web page you want to track. If your website already has Google Analytics tracking code on it, that code must be removed as you add the new GTM container snippet, or you will accidently track your website’s data twice in your Google Analytics account.

Ideally, the GTM container snippet should be 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 website’s code. The container snippet may be added to another section of a web page, but it may miss some data if users leave a web page before the script has the opportunity to fully load.3 Later chapters in this issue of Library Technology Reports will discuss implementing GTM on different online tools to demonstrate the best option for placing the container snippet for that specific tool. Once you add the container snippet, almost all other customizations occur in the GTM administrative interface—so no additional code needs to be added to the online tool itself.  

Creating Your First Tag in Google Tag Manager

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 function. A tag is script that runs on a web page and is usually based on a specific product like Google Analytics, but you can also create and add your own custom scripts. The trigger tells the tag it should fire (or run) on a specific web page or action based on if the variable (some value) is true. This may sound complicated, but the GTM administrative interface is fairly easy, with a point-and-click functionality that walks you through the entire process. All you have to know is what you want to track and when you want to track it.

No matter what type of online tool you are tracking, the first tag you should always create is a Google Analytics tag to sync your Google Analytics account to your GTM container. This connects GTM to your Google Analytics account. To do this, go the Tags area within your GTM container and click on the New button. Once on the new tag screen, name your tag to help organize your tags. Use whatever naming convention makes sense for your library.

Next, select Google Analytics as your product. This will give you an option to choose either Universal Analytics (analytics.js) or Classic Google Analytics (ga.js). By now, you should be using Universal Analytics because it has more advanced features and reports than its predecessor. Select Universal Analytics and click Continue. Add your Google Analytics Tracking ID number. It should look like UA-xxxxxxxx-x (figure 2.1). If you do not have it memorized, you can easily find this information within your Google Analytics account. You will be using this Tracking ID number a lot, so I recommend creating a custom GTM variable to 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 tracking code, you will most likely want to track every web page on which the GTM container 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 versions of your containers all within the GTM site.

Click on the Publish button within the GTM interface to publish your container. If you already added the container snippet to your website, publishing the container automatically pushes those updates to your website so that Google Analytics tag is now live. If you are using a newly created Google Analytics Tracking ID number, it will take Google Analytics roughly twenty-four hours to start displaying data in its reports.

Additionally, you can click the down arrow next to the Publish button to select the Preview and Debug option to determine if your tags work as expected. Simply select this option and open your website in the same web browser. As your browser loads your website’s web page, the GTM debug window (shown in figure 2.2) will open at the bottom of the screen and list the tags that fired and the ones that did not. Again, the GTM container snippet must already be added to your website in order for this to work. Your newly created tag should be firing, so can you publish your changes knowing it is working.

Creating Events in Google Tag Manager

You successfully created your first GTM tag to sync your Google Analytics to your website! Next, you should focus on tags for those useful Google Analytics events.5 Recall that an event is any user action that cannot be automatically tracked by Google Analytics. Common events are clicks on outbound links (links that navigate users away from the website), document downloads, and other script-based features. Previously, if you wanted to collect data associated with these events, you needed to add Google Analytics’ event-tracking script to each event you wanted to track. GTM replaces this tedious process with a simple event tag—no direct editing of your website’s code required. Before you create an event tag, you should have a good understanding of how GTM triggers and variables function so you can leverage their full capability.

Triggers

Triggers tell the GTM tag when to fire and collect data. Currently, GTM allows for seven types of triggers: Page View, Click, Form Submission, History Change, Custom Event, JavaScript Error, and Timer.6 For example, a Page View trigger is useful when a tag needs to be fired as a user loads a specific web page. To create a trigger, select the trigger type and add the conditions to make the trigger fire. In the case of the Page View trigger, you can select all web pages, or you can define the web page or web pages based on the unique identifier within the page’s URL. If you are not familiar with regular expressions (RegEx), this is a good time to learn because it is an excellent method for defining unique strings for the different trigger types. I recommend LunaMetrics’ Regular Expressions for Google Analytics as a great starting place.7

System and User-Defined Variables

Recall that variables are just pieces of data that are stored or collected by GTM. GTM variables are easy to identify because they always use double curly brackets to indicate a variable (e.g., {{variable name}}). GTM comes with a series of built-in system variables you can enable in the container’s Variables section. For example, {{Click URL}} is a system variable that has GTM collect the URL of the web link a user clicked and this URL will be displayed in your Google Analytics reports. Another useful system variable is {{Click Text}}, which collects the web link’s text when a user clicks on it. Google provides excellent documentation for all its system variables,8 but GTM can send Google Analytics even more data with User-Defined (custom) variables. With a little bit of scripting knowledge, you can capture any data point on your site you can uniquely identify.

Creating an Outbound Link Event Tag

Creating an event tag takes only a few minutes if you know what event you want to track and how you want to track it. In the Tag section of your GTM container, follow these steps to create an outbound link event tag:

  1. Click on the New button in the Tag section of your GTM container.
  2. Name the new tag. For this example, I am creating an outbound link event, so I name this tag Outbound Link Event.
  3. Under the Choose a Product section, select Google Analytics. As with your first tag, select Universal Analytics. Click the Continue button.
  4. Add your website’s Tracking ID number. This might seem redundant since you already created the tag to sync your Google Analytics account to the GTM container, but you will repeat this process with each new event tag because it connects the event data back to your Google Analytics account.
  5. Since this is an event tag, change the Track Type from Page View to Event. This will display the event tracking parameters where you can add information for the event’s category, action, and label.
  6. You can ignore most of the other event options, but you should fill in the event’s Category, Action, and Label boxes as shown in figure 2.3 on the following page. Both the category and action are names I chose to describe those options, while the label uses the GTM system variable {{Click URL}}. Each time this event tag is fired, it will report these data points in Google Analytics Event reports.
  7. Under the Fire On section, select the Click option because this tag requires a Click-based trigger to fire only on clicks to outbound links.
  8. Select the New button on the Click Triggers pop-up window.
  9. Name your new Click trigger. I called mine Outbound Link.
  10. Under Configure Trigger, select Just Links as the Targets. This will look only at clicks on web links rather than any element on the web page.
  11. Deselect Wait for Tags and Check Validation options—these are useful for testing but increase web page load time as it waits for the tags to load.
  12. Under the Fire On options, select Some Clicks because this tag should fire only on clicks to outbound links.
  13. Finally, you get to define an outbound link for this trigger. I define an outbound link as any link not within the website I am tracking. In this example, my library website is http://www.uccs.edu/library. Any site that does not contain the string uccs.edu/library in its URL is considered a separate website. In GTM, this translates to the system variable {{Click URL}} Does Not Contain uccs.edu/library as shown in figure 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 create 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 different event parameters and triggers for each event you want to track on a website.

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 Analytics 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 to determine if the tag is firing properly, and another test to ensure it is collecting the correct data.

The first test was already mentioned—use GTM’s preview mode before publishing the new container version. This will tell you if the tag is firing as planned. After you ensure your tags are firing properly, open up the Real-Time reports in your Google Analytics account. For event tag testing, you can use the Real-Time Event report to see what data your event is collecting while still in the Preview and Debug mode. This minimizes the potential of collecting wrong data. If you are happy with your event data, you can confidently publish the changes to your GTM container. Within twelve to twenty-four hours, that new data will be available in your Google Analytics reports.

Conclusion

Before you start tracking events in GTM, you should create a list of events you want to track for each website. New event tags can be added at any time in the GTM container, but planning will help you standardize the naming convention for your event categories, actions, and labels, which will keep your data reports cleaner. It will also help you think strategically about what insights you want to gain from the data.

Notes

  1. Laura Holmes, “Digital Marketing Made (Much) Easier: Introducing Google Tag Manager,” Google Analytics Solutions blog, October 1, 2012, http://analytics.blogspot.com/2012/10/google-tag-manager.html.
  2. “Quick Start Guide,” Google Tag Manager, accessed February 29, 2016, https://developers.google.com/tag-manager/quickstart.
  3. Justin Boyle, “Where Should the Google Tag Manager Snippet be Placed?” LunaMetrics, December 12, 2014, www.lunametrics.com/blog/2014/12/12/google-tag-manager-snippet-placement.
  4. “Unit 2, Lesson 2: Set Up a GA Property Variable,” Google Analytics Academy, accessed February 29, 2016, https://analyticsacademy.withgoogle.com/course05/unit?unit=2&lesson=2.
  5. “About Events,” Google Analytics Help, accessed February 29, 2016, https://support.google.com/analytics/answer/1033068?hl=en.
  6. “Triggers,” Google Tag Manager Help, accessed February 29, 2016, https://support.google.com/tagmanager/answer/6106961?hl=en.
  7. Robin Steif, Regular Expressions for Google Analytics (Pittsburgh, PA: LunaMetrics, 2010), www.lunametrics.com/regex-book/Regular-Expressions-Google-Analytics.pdf.
  8. “Variables,” Google Tag Manager Help, accessed February 29, 2016, https://support.google.com/tagmanager/answer/6106899?hl=en.

Other Resources

“Google Tag Manager Fundamentals,” Google Analytics Academy, accessed February 29, 2016, https://analyticsacademy.withgoogle.com/course05.

“Welcome to the Google Tag Manager Help Center,” Google Tag Manager Help, accessed February 29, 2016, https://support.google.com/tagmanager.

Universal analytics tag, Google Tag Manager, University of Colorado Colorado Springs

Figure 2.1

Universal analytics tag, Google Tag Manager, University of Colorado Colorado Springs

Google Tag Manager debug window, Google Tag Manager, University of Colorado Colorado Springs

Figure 2.2

Google Tag Manager debug window, Google Tag Manager, University of Colorado Colorado Springs

Outbound link tag, Google Tag Manager, University of Colorado Colorado Springs

Figure 2.3

Outbound link tag, Google Tag Manager, University of Colorado Colorado Springs

Outbound link trigger, Google Tag Manager, University of Colorado Colorado Springs

Figure 2.4

Outbound link trigger, Google Tag Manager, University of Colorado Colorado Springs

Refbacks

  • There are currently no refbacks.


Published by ALA TechSource, an imprint of the American Library Association.
Copyright Statement | ALA Privacy Policy