How to Set Up Event Tracking in Classic Google Analytics

Google Analytics Event Tracking is a valuable addition to measure website performance. It enables you to to track users’ interactions with different elements on your website, that Google Analytics would not normally be able to track; for example: button clicks, banner clicks, PDF downloads etc.

To enable event tracking in Google Analytics, you’ll need to create a snippet of custom code and add this code snippet to the website elements you want to track.

Last week, we analyzed in details the different components of the Event Tracking Code and learned what information they provide to GA. In this week’s article we’ll see how exactly to put the Event Tracking code into action and implement it to your website.

Structure of the Event Tracking code (ga.js)

First, let’s revise the structure of the Event Tracking code used in Classic Google Analytics (ga.js).
Ga.js library uses the _trackEvent() method and the code looks like that:

_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)

The code uses 5 parameters (or components):

  • category (required) – The name you supply for the group of objects you want to track.
  • action (required) – Used to define the type of user interaction for the web object.
  • opt_label (optional) – An optional string to provide additional dimensions to the event data.
  • opt_value (optional) – An integer that you can use to provide numerical data about the user event.
  • opt_noninteraction (optional) – A boolean that when set to true, indicates that the event hit will not be used in bounce-rate calculation. Is it’s set to false the event hit will be considered as an interaction and will be used in bounce-rate calculation

Additionally this article assumes that you’re already more or less familiar with the Event tracking code used in Classic Google Analytics. If you find that this short explanation is not enough and you want to know how exactly the EventTrack method works, feel free to check my previous article on the anatomy of the Event tracking code.

How to Set Up Event Tracking in Google Analytics in 5 easy steps

After analyzing the structure of the Event Tracking code, let’s see how to implement it.

1. Replace each element of the  _trackEvent() method with the data that you want reported

As an example, let’s say I want to track downloads of one of a free resource I offer on my website: a whitepaper called “Free SEO guide for Beginners”.

I use:

  • ‘Resources’ as category
  • ‘download’ as action – the same action will be used for all downloads across the site
  • ‘Free SEO guide for Beginners’ as label – to help me distinguish the downloads for this particular resource
  • 3 as value – we assume that I gain $3 per each download
  • true as opt_noninteraction – because I don’t want this event (the download) to impact the bounce rate of the page

So the _trackEvent code in my case will look like that:

_trackEvent(‘resources’, ‘download’, ‘Free SEO guide for Beginners’, 3, true)

2. Put the _trackEvent code inside an onClick function (if you track on-click events)

If you want to track on-click events (such as clicks on links and buttons) you’ll have to place the_trackEvent code after an onClick HTML Event Attribute :

onClick=”_gaq.push([‘_trackEvent’, ‘resources’, ‘download’, ‘Free SEO guide for Beginners’, 3, true]);”

NOTE: onClick is used whenever you want to track an event that resulted of a click.  

You can also track Events triggered by an action different from a click, but you’ll have to use the _trackEvent method in combination with the relevant HTML event attribute.

For more information I recommend you to read this article with examples about the use of the different HTML Event Attributes for Google Analytics Event Tracking.

3. Add the onClick code to the hyperlink code of the elements you want to track

When you’re tracking clicks on buttons or download, you have to place the custom _trackEvent code inside the code of the link you want to track.

In our example we want to track downloads of a whitepaper.

The link to the whitepaper is /downloads/ressources/free-seo-guide-for-beginners.pdf.

So I put the Event tracking code just after this link. It will look like that:

<a href=”/downloads/ressources/free-seo-guide-for-beginners.pdf” onClick=”_gaq.push([‘_trackEvent’, ‘resources’, ‘download’, ‘Free SEO guide for Beginners’, 3, true]);” target=”_blank”>Download a Free SEO Guide for Beginners</a>

4. Check the Google Analytics Report

If you’ve followed these instructions, you already set up Event tracking for this particular event (downloads of the whitepaper “Free SEO guide for Beginners”).

As long as you have properly installed Classic Google Analytics tracking code on the pages with the events, the data will magically start appearing in GA.

You’ll find the Events Reports in Content > Events.

The main metrics in the report are:

  • Total Events: How many Events were recorded
  • Unique Events: How many unique actions happened
  • Event Value: The total value recorded (only you know whether it’s £, $, time or another metric!)
  • Avg. Value: The average value across all Events
  • Visits with Event: How many visits contained an Event
  • Events / Visit: The average number of Events recorded per Visit

The main metrics can be broken down by Category, Action, Label (or a combination of these)

The Events can also be reviewed by the pages on which they happened.

5. Set up Events Goals

You should consider to set up goals for your most important Events. In this ways, you can see data relating to these in the standard GA reports and see how the sessions with Events compare to all other sessions.

I’ll explain how to set up Events Goals in one of my next articles.

What other “Events” you can track using Google Analytics

As I said, Event tracking is extremely useful and there are many reasons why you should implement it.

The most common use for Event Tracking is to see how many times people click on a certain element, such as a button or a banner. But if you’re more familiar with Javascript, you could track much more. For example:

  • Clicks on videos
  • Clicks on adverts
  • Clicks on social profiles
  • Clicks on AdSense and affiliate links
  • Clicks on Live Chat buttons or other gadgets (usually an external service)

In this article, I took as example one of the most common Event tracking codes: the one for tracking clicks on buttons. But codes may vary depending on the type of events you want to track.

In my next article, you’ll find examples of Event Tracking codes for other events, such as submission forms, clicks on videos,  social profiles and others.
So keep reading!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: