Unleash the Power of Google Analytics (3): Event Tracking


Part 3 of 10: Event Tracking

When you’ve got your Analytics account up and running, you can start tracking the more advanced features on your site.

Event tracking is a more recent (June 2009) addition to the Google Analytics toolset, and it allows you to track almost anything.

If your site uses lots of Flash, then event tracking is definitely for you. For example, if you have a Flash music player, you can use event tracking to count the number of times users press ‘play’, ‘pause’, ‘fast forward’ and so on, giving you a great insight into how people interact with your content. Event tracking is also useful if you want to track other user interactions – such as out-clicks or ‘mailto’ links – without affecting or skewing page view numbers.

The code

The code for tracking events is very simple indeed. All you need to do is tag each element you want to track with the following line of code (this example assumes that ‘pageTracker’ is the name you’ve given to the tracking object).

pageTracker._trackEvent(‘category’, ‘action’, ‘label’, value);

This code needs to be called in the page after the pageTracker is initialised. Sometimes the best (and certainly the easiest) thing to do, is to move the standard GA tracking code to the top of code – i.e. straight after the opening <body> tag.

The four fields within the brackets allow you to categorise each action performed on the site. Below is a diagram showing how events are structured when you come to report on them.

Structure of tracking events


Here’s a bit more information on each of the parameters that you can pass into the code.

Category. This field is mandatory and should be passed with every event that you track. The category is the highest level in the event tracking ‘architecture’, so it should be used for grouping your events at the widest level. For example, you might have ‘videos’ as the category. This will group all video-related events. Alternatively, you could have ‘downloads’ as the category and group together all download events

Action. Action is the name you give to the specific way in which the user will be interacting with the site. This field is also mandatory. For example, if you’re tracking video actions, you might name them ‘play’ and ‘stop’. Or, if you’re tracking downloads, then you might use the type of file, ‘pdf’, ‘exe’ or even a specific filename.

Label. Label is an optional field that can be used to give more information on each action. So, to return to the video example, you could use the video name as the label. You would then not only be able to record all video interaction at a category level and how many video plays there have been at action level, but also how many plays there have been on a video-by-video basis at label level.

Value. Value is also optional. The value needs to be an integer (i.e. a whole number, meaning – unfortunately – that you can’t use cost or revenue numbers).

Top Tip – If you are using values pay close attention to the tag – pageTracker._trackEvent(‘category’, ‘action’, ‘label’, value); You won’t need inverted commas around the value as it’s an integer and not a string. Putting inverted commas around your value parameter will prevent the tag from working.

Using our video example once more, Google suggests that download time could be used here. But if you’re really clever, a better use would be to record how many seconds of the video the user watched before they stopped it. If you get low numbers, you’ll know the video isn’t connecting with your audience.

Plan Ahead

It’s really important not to rush into an event tracking implementation. You need to plan exactly what you want to track and then work out how you’re going to structure the events. Getting the structure wrong will mean you won’t be able to get the most out of your stats.

You also need to think about the future. Ask yourself what else you are likely to be tracking as your site develops. You need to be able to allow for new categories/actions/labels to be added without them affecting your current Google Analytics stats.

Subscribe to our blog and follow this Analytics series

More on this subject