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.
-
-
-
- Log into Google Tag Manager
- Select “Tags” from the left-hand side
- Create a new tag
- Select Universal Analytics from Tag Type
- Set your Google Analytics Tracking ID
- Choose “Event” for the track type
- Set your Event Category, Action, Label and Value as desired*
- 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.
1) How to track file views and downloads
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.
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
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.
-
-
-
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 .*
- Trigger Fires on: Some Clicks
- Click URL Hostname: does not contain YOURSITE.COM
-
-
-
Replace “yoursite.com” with your domain name.
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.
Each link has a title that relates to the names of the product type.
Using Google Tag Manager we are able to extract the title attribute when clicked and it is assigned to the event.
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
-
-
-
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.
The Event Tag uses the Title Variable to pull in the event action.
Optional:: Wren Kitchens used a Lookup Table Variable to generate the kitchen range chosen based on the URL. This then became the Event Category
Tips
-
-
-
- Try to be as consistent as possible. Note which event names have capital letters and which ones don’t. Make sure Event Actions and Categories match where required
- Test before you push to live. I use theGoogle Tag Manager Preview and Debug mode for this
- Test after you’ve pushed to live. I useGoogle Analytics Real-Time to see what is being pushed into GA and the Event Tracking Tracker plugin for Chrome
If you have any queries about Event Tacking or Google Tag Manager, please feel free to get in touch.
-
-