Analytics

Google Analytics Event tracking is a useful feature that allows you to record interactions with elements of your website which aren't tracked as standard within Google Analytics.

In this post I explain how to track events manually or by using Google Tag Manager.

What Can Google Analytics Event Tracking Be Used For?

Event tracking can be used to measure visitor engagement on your site in many different ways. The typical uses include:

  • Tracking outbound links to other websites.
  • Tracking clicks on email addresses or click-to-call phone numbers. This can help you to better understand the number of enquiries you are getting from your site.
  • Tracking PDF and other media downloads.
  • Measuring interactions with video content, such as time spent watching a video.
  • Monitoring the clicks on unique elements of a page, such as the contact us call to action on your about page.
  • To setup up events to record conversions relating to phone number clicks and calls.

Event tracking allows you to count interactions that don’t necessarily involve loading another page on your website. Google Analytics goals can be setup based on your events.

Google Analytics Event Tracking in Google Analytics - Tracking of clicks on ShareThis buttons

Example of Event Tracking in Google Analytics – Tracking the clicks on ShareThis buttons

So How do I use Event Tracking?

To use event tracking you need to have Google Analytics installed on your website. Before setting up event tracking, you need to give some consideration to the following:

  • Decide on which elements of your site you want to track, whether it is PDF downloads, or clicks on outbound links.
  • Adopt a consistent and clear naming convention for the different action, label and category options available to you when you are setting up event tracking. Every name you give to each category, actions, and labels appears in the event tracking reports. If your naming isn’t sensible then your report won’t make a lot of sense either.
  • Decide whether you want to set up automatic auto-event tagging or manually tag links on your site. If you have a lot of documents and page elements to track it may be worth setting up Auto Event Tagging and using Google Tag Manager Events.
  • There used to be two different ways to setup event tracking on a website for standard Asynchronous Google Analytics (ga.js) and Universal Google Analytics but this has now been simplified as the standard Asynchronous Google Analytics (ga.js) code has depreciated. Users of the old ga.js code have now been automatically transferred over to Universal Analytics. It is advisable to ignore any guides that talk about using ga.js and event tracking.

How Does Google Analytics Event Tracking Work?

A snippet of custom code is added to the link code on the items you want to track on your website and when the item is clicked, the element is tracked and displayed as an event in Google Analytics.

The event tracking code consists of four elements that you can define to describe a user’s interaction on your website:

  • Category (Required) is the name you give to a group of objects you want to track.
  • Action (Required) is the type of interaction, such as downloading a document.
  • Label (Optional)is useful for summarising what the event is about, such as clicks on navigation menu options.
  • Value (Optional) can be used if you’d like to assign a numeric value to your file download.

When the event fires on your site, the ‘Category’, ‘Action’, ‘Label’ and ‘Value’ attributes can be used to help you understand exactly what the user engaged with on your page. It is important to to give some thought to the naming conventions used for these attributes as these values are what will show within Google Analytics.

The Event tracking code for an event tracked link in Universal Analytics looks like this:

onclick=”ga(‘send’, ‘event’, ‘Category’, ‘Action’, ‘Label’, ‘Value’);”

The code is placed after the href link text as illustrated in the example below:

<a href=”www.examplewebsite.co.uk/company_brochure.pdf” onclick=”ga(‘send’, ‘event’, ‘Category’, ‘Action’, ‘Label’, ‘Value’);”>

The category, action, label and value labels are replaced by the values that you decide to enter. An example of an event tracked link with entered values is further down the page.

How to Setup Google Analytics Event Tracking

Depending on the number of events you would like to track, or the level of control you would like to have on the tracking parameters for your events, you can setup up auto event tracking, or manually tag links on your website.

If you have lots of documents and page elements to track it is worth using auto event tagging. This can be done using Google Tag Manager. Auto event tagging will fire on the following:

  • When users click on links.
  • Clicks on any type of page element.
  • After a certain visit duration or at timed intervals.
  • On submission of a form.

If there are other actions that you would like to track you can use Google Tag manager to set this up.

Manually Tagging Links to Track Events

You can manually customise links on your site to add the ‘Category’, ‘Action’, ‘Label’, ‘Value’ attributes to a link as already discussed earlier. To give you a practical example of this, the example below shows a link that includes event code for tracking a PDF download.

The italicised text below shows an example of event tracking parameters configured to record the download of a company brochure PDF document.

<a href=”www.examplewebsite.co.uk/pdf/company_brochure.pdf” onclick=”ga(‘send’, ‘event’, ‘PDF’, ‘Download’, ‘Company Brochure – PDF Download’);“>ANCHOR Text</a>

Auto-Event Tracking Options

Event Tracking Using Google Tag Manager

Google Tag Manager logo
You can measure interactions on your site by setting up Google Tag Manager’s Auto-Event Tracking. This might sound more complicated that it is but it does require time to understand how to setup and use Google Tag Manager.

Event tracking using Google Tag Manager is initiated via clicks on event triggers that can be setup on specific variables on your webpage. Google Tag Manager Events are user actions with web page elements (“DOM elements”) that are triggered by your browser and sent into the Tag Manager data layer so that they can be used to set up triggers.

A summary of the steps required to setup an event within Google Tag Manager are listed below:

  1. Log into Google Tag Manager
  2. Select “Tags” from the left-hand side
  3. Create a new tag and select Universal Analytics as the Tag Type
  4. Set your Google Analytics Tracking ID
  5. Choose “Event” for the track type
  6. Set your Event Category, Action, Label and Values. You can use Google Tag Manager variable names such as {{click url}}
  7. Set your triggers as required

An example of how to setup an event within Google Tag Manager is outlined below:

Step 1 – Check You Have the Right Enabled Variables Selected for Your Event

Head over to the Variables section in Google Tag Manager and make sure that you have ticked the variables that you would like to track on your site.

Setting variables in Google Tag Manager

Step 2 – Create a New Tag in Google Tag Manager

Create a new tag in Google Tag Manager and change the Track Type to ‘Event’. This will then automatically add the tracking parameter fields for Category, Action, Label and Value as shown in the screenshot below. As we discussed earlier in this post, the Category, Action, Label and Value attributes form the basis of the event variables within Google Analytics. There are Google Tag Manager specific code variables that you can use to automatically populate fields with values. For example the {{Click}} code will automatically pull in the web URL into the field it is entered into.

Google Tag Manager Contact Form Submission event

Step 3 – Configure the Tag

Enter values for Category, Action, Label and Value.

The label should really be named to give you as much information as possible on what was clicked. If you were planning to track clicks on the navigation buttons in your site header, you may want to record the click URL of the item that was clicked on.

The Value box for your event can be populated if you want to attribute a nominal value to types of enquiries on your site. You may want to give a contact form submission a higher value than an email newsletter signup for example.

The True/False field is used for a non-interaction event. If you want your event action not to create a new pageview and not to impact on the bounce-rate, then set this value to True.

Setting the tag for a tracked event is the same every time. The main difference in setting up different types of tags is will be in configuring what the tag fires on.

Step 4 – Select What the Event Tag Will Fire On

The next step is to select or create a trigger for the tag to fire on. You will need to set the fire on conditions for your tag. I have included a few examples of the different types of triggers for different events on your site.

Trigger for Measuring Clicks on an Email Address Link

An example of a completed trigger for an email address clicked link is below.

Google Tag Manager Event trigger to record an email click event action

  1. On the choose Trigger Type screen under the Click heading choose Just Links
  2. Select the Some Link Clicks under this trigger fires on
  3. Set the variable to Click URL within the first drop down box
  4. Specify that the URL ‘Contains’ in the second drop down option
  5. Enter mailto: within the third field

Trigger for Measuring Clicks on a Phone Number

Setting a trigger to track clicks on a phone number in Google Tag Manager

  1. On the choose Trigger Type screen under the Click heading choose Just Links
  2. Select the Some Link Clicks under this trigger fires on
  3. Set the variable to Click URL within the first drop down box
  4. Specify that the URL ‘Contains’ in the second drop down option
  5. Enter tel: within the third field

Trigger for Measuring PDF Downloads

Using GTM to setup a PDF download event

  1. On the choose Trigger Type screen under the Click heading choose Just Links
  2. Select the Some Link Clicks under this trigger fires on
  3. Set the variable to Click URL within the first drop down box
  4. Specify that the URL ‘Contains’ in the second drop down option
  5. Enter .pdf within the third field

Conclusion

Google Analytics Event Tracking is a valuable addition to measuring user interactions on your website. It can be used in combination with traditional Google Analytics goals to measure micro or macro conversions on your site. Using Google Tag Manager and Tag Manager events means it is now easier for you to setup and control the events you want to track.

Useful links

6 responses to “Using Google Analytics Event Tracking”

  1. Jamie Knop says:

    Good guide Pete. Why they didn’t keep the old format of code working for Universal is rather daft..

    I actually have a code generator for event tracking that supports both universal and async tracking. Feel free to include in your useful links of this post if you wish. You can check it out here http://www.seoweather.com/google-analytics-event-tracking-code-generator/

  2. Marin says:

    Hello Jamie! Should i put this code, i generated on your website inside analytics code or beneath?
    Thanks!!

  3. Nate says:

    Hi! Just a query – if I were to use this via a function in WordPress, could I just use the onclick attribute for the tags and pass through variables to achieve the same effect, or would I still have to manually add these in GA? For example, if my function said the link would be:

    `ga(‘send’, ‘event’, $ga_category, $ga_action, $ga_label, $ga_value)`

    with the strings in their correct places, would these events appear (with the corresponding strings) in GA without any additional intervention on my part?

  4. Mangesh says:

    Thank You! I was stuck in clearing concepts from almost four months but your blog explained it very well.

Leave a Reply