In this post I’m going to discuss how to implement event tracking in Google Analytics. If you have not read part 1, I strongly recommend you do so because I reference Part one extensively. When we implement event tracking we add code that creates the data model we defined in Part 1. We’re going to continue our example of tracking an event in Google Maps. We want to find out how which map view people use most.
The Data Model
If you remember part 1, I created a data model for our event data. This will help us answer our business question and it will help use create the code.
Tag Your Pages
I know this seems simple, but the first step is to make sure your pages are tagged with the GA tracking code. Remember, this only works with the new ga.js tracking code.
Creating The Object
The first thing we need to do is create the object that we want to analyze. To create a new object we use a method name
_createEventTracker(). We pass this method a value and that value is the name of the object we defined in the data model. Our object is called ‘Map’ so let’s use ‘Map’ in the name:
var mapEventTracker = pageTracker._createEventTracker('Map');
When we look at the reporting interface we will see ‘Map’ in the Objects report. Pretty straight forward, huh?
This code must appear after your GA page tag. The reason is that the
_createEvent Tracker() method is attached to the
pageTracker object. In this example, I’m going to place it in the same block as the regular tracking code:
Tracking the Action
onClick="mapEventTracker._trackEvent('Change Map View',
<label> and <value> should be replaced with one of the labels we identified in our data mode:
Street Level 20
What happens when a visitor clicks on a map button is that the code sends the action, label and value to GA and associates it with the map action we defined above. Now you can see how our data model really drives the implementation.
Tracking Multiple Objects
Ok, so here is something that’s pretty cool. Let’s say the map team wants to add two different maps to a single page. We can track both of them using the same map object. We would then differentiate what the visitor does using different labels. The actions would remain the same for both objects, but we’d have different labels.
A Final Note
I’d like to say that every implementation for event tracking can be different. It really depends on the business questions you need to answer and the structure of your pages. I think this post does a very good job of covering the basics, but your specific implementation will probably be a bit different… Unless you’re Google Maps. :)
As we’ll see in the next post, the new Event reports provide a logical structure for analyzing event data.