How to automatically track events with Google Tag Manager

  • 0
  • May 25, 2017
Emma Barnes

Emma Barnes

Senior Insights and Analytics Analyst

Event Tracking with Google Analytics is essential for measuring actions on your website that aren’t just page loads. This can include tracking PDF Downloads, usage of dynamic filters, and clicks on external links. Events can be tracked as goals if they are valuable to the business.

Tracking Events in Universal Analytics (analytics.js)

This post will cover the Google Tag Manager element of Event Tracking, rather than the developer side, as some of these methods may not require a developer. However, if you need a web development team, I know a really good agency that offers web development

It should be noted that this post will cover Event Tracking in Universal Analytics (analytics.js), not the older version of Google Analytics (ga.js). If you have not yet migrated to Universal Analytics, I have written a migration guide you might find helpful.

How to track Google Analytics Events in Google Tag Manager

Before I start talking about specific events, let’s talk about how to set up an event in general.

        1. Log into Google Tag Manager
        2. Select “Tags” from the left-hand side
        3. Create a new tag
        4. Select Universal Analytics from Tag Type
        5. Set your Google Analytics Tracking ID
        6. Choose “Event” for the track type
        7. Set your Event Category, Action, Label and Value as desired*
        8. Set your triggers as required

*Note: This is how your events will be named within Google Analytics

Setting the tag for Event Tracking is the same process every time. The difference comes with creating the triggers that fire.

PRO TIP: Sort your event tracking tags into folders for easy management.

Branded3 GTM Folders

1) How to track file views and downloads

File Download Events Google Analytics

If you have links on your websites to pages or files that can’t track Javascript such as PDFs and MP3s, you can see how many people clicked on these links if you set up event tracking. We’ll use PDFs as an example.

The first thing you need is a trigger that states “fire if someone clicks on a PDF link”. Go to the “Triggers” section of Google Tag Manager and create a new trigger named PDF Click.

          • Trigger Type: Click – Just Links
          • Some Link Clicks
          • Click URL contains .pdf

This can be replicated for other file types such as .jpg, .xls, .mp3, and so on.

PRO TIP: A similar approach can be taken to tracking people who click on e-mail addresses and telephone numbers from a mailto: or tel: link. Change the Click URL contains to mailto: or tel:. This tracks clicks on links not actual e-mail sent or calls made.

PDF Download Event

Create an event tracking tag with the following:

          • Category: PDF
          • Action: Download
          • Label: {{Click URL}}
          • Value: (decide your own value)
          • Firing Trigger: PDF Click

You may want to reverse Category and Action depending on how you generally configure events. I like to have “Action” as the action taken (e.g. they downloaded a file), but some people prefer to have “Category” as the larger encapsulating feature. As long as you are consistent with what you consider a “category” and what you consider an “action”, that’s all that matters.

2) How to track clicks on external links

External Link Clicks Branded3

If you want to see how often you’re sending traffic to other websites, you can track external link clicks.

Before we set the trigger, we need a variable that finds the domain name (hostname) contained within the URL that can be clicked on. To do this, go to the “Variables” section of Google Tag Manager.

Create a new user defined variable called “Click URL Hostname” with the following criteria.

          • Variable Type: Auto Event Variable
          • Component Type: Hostname
          • Strip www.

Click Hostname Variable Google Tag MAnager

Once this variable is created, the trigger will execute on and click that links to an external website. Go to the “triggers” section and create a new trigger called “outbound clicks” with the following parameters:

          • Trigger Type: Clicks – Just Links
          • Wait for Tags: 2000ms
          • Check Validation
          • Page URL: matches RegEx .8
          • Trigger Fires on: Some Clicks
          • Click URL Hostname: does not contain YOURSITE.COM

Replace “yoursite.com” with your domain name.

Outbound Link Clicks Trigger Google Tag Maanger

3) How to track clicks on… whatever you want

Note: This method depends on how your website has been coded. You may have to get a developer involved, but it is possible without!

The example I’m going to use is tracking clicks on all of the components of Wren Kitchens’ kitchen planner. We wanted to measure which selections were made the most from door styles, worktops, and so on.

Wren Kitchens Kitchen Planner

Each link has a title that relates to the names of the product type.

Wren Kitchens Title

Using Google Tag Manager we are able to extract the title attribute when clicked and it is assigned to the event.

Wren Kitchens Event Names

Before we set the trigger, we need a variable that finds the title within the element that can be clicked on. To do this, go to the “Variables” section of Google Tag Manager.

Create a new user defined variable called “Element Title” with the following criteria:

          • Variable Type (Main): Auto Event Variable
          • Variable Type (Secondary): Element Attribute
          • Attribute Name: title

Event Variable Google Tag Manager

You can do this for any sort of element attribute – such as alt tags – and you only need to change the attribute name.

 

Once this variable is created, we need a trigger that only launches a tag when the relevant section is clicked. This will vary by website; on the kitchen planner, we only want to track clicks on kitchen planner pages when the click is on an element with the class “layer-toggle” or “selection”:

          • Trigger Type: Clicks – Just Links
          • Trigger Fires on: Some Link Clicks
          • Click Classes: matches RegEx layer-toggle|selection
          • Page URL: containers www.wrenkitchens.com/online-planner

Amend this as relevant to your website.

Wren Kitchens Event Trigger

The Event Tag uses the Title Variable to pull in the event action.

Event Tracking Tag

Optional:: Wren Kitchens used a Lookup Table Variable to generate the kitchen range chosen based on the URL. This then became the Event Category

Wren Kitchens Lookup Table

Tips

 

Free of charge. Unsubscribe anytime.