Event tracking is used to measure how many users complete a certain action. This includes things like:
- Playing a video
- Download a file
- Flash based elements
- Clicking specific links
These are things that analytic doesn’t track by default, so you need to specify then as events. In this google analytics event tracking example we’ll cover how to define and trigger events.
How to trigger an event
<a href=”download.pdf” onClick=”event code”>Download our pdf</a>
This triggers an event when the user clicks the ‘Download our pdf’ link.
How to define an event
Events consist out of the following elements:
- Label (optional)
- Values (optional)
- Non-interaction (optional)
These variables are declared in the _gaq.push() function. Within there we call _trackEvent.
The syntax of this is:
_trackEvent(category, action, label, value, noninteraction)
This is implemented like so:
<a href=”download.pdf” onClick=”_gaq.push([‘_trackEvent’, ‘Category’, ‘Action’, Label’]);>Download our pdf</a>
Google Analytics event tracking example for downloads
For example, let’s say we want to measure a download of the free pdf ‘Company Whitepaper.pdf’. We could use:
- Category: Freestuff
- Action: Download
- Label: Whitepaper
This would implement in the following way:
<a href=”whitepaper.pdf” onClick=”_gaq.push([‘_trackEvent’, ‘Freestuff’, ‘Download’, Whitepaper’]);>Download our Whitepaper</a>
Why use categories, actions and labels?
The structure of your event tracking is going to be an important factor in your data analysis. In the previous example you might want to track multiple downloads. You would give all of them Category: Freestuff and Action: Download but label them differently.
Likewise you may want to track multiple action types, like video plays. An example structure for this would be:
- Category: Videos
- Action: Play
- Label: Margetingivideo
It is important to keep these labels easy to read for humans. Try not to fall into the habit of using labels like ‘Category: category1’ which do not describe anything.