Event Tracking Pt. 2: Implementations

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

Now that we have an object, how do we track an action associated with that object? We add JavaScript to our page code when the action takes place. So, with our Maps example, we would add some code when the visitor clicks on the button to change the Map view type. Here’s how that code might look:

onClick="mapEventTracker._trackEvent('Change Map View',

<label> and <value> should be replaced with one of the labels we identified in our data mode:

Map 5
Satellite 10
Hybrid 15
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.

Be Sociable, Share!

    Like this post? Sign up to get posts delivered to your inbox.


    1. Jahangir says

      A doubt, in the tracking of the event object with the code that you gave “onClick=” mapEventTracker._trackEvent(’Change Map View’, <ACTION> ,<VALUE> );””

      What/why should be assigned here?? isn’t “value” automatically incremented for that particular Label when the event is executed??


    2. says

      Hi Jahangir,

      The action and the value are not automatically incremented. In most cases, you will define those values. In some cases the value could be auto incremented, but it will be a value derived from something happening in the browser. For example, value could the the number of seconds it took for the page to render.

      User defined values would be specific for each action. Like clicking on the play button might be worth 100. It’s up to you.

      Once the reporting part of this feature is activated I’ll have more information for everyone.

      Thanks for reading and thanks for the question.



    3. Gerard says

      Hi Justin,

      Event tracking seems much more powerfull than goals. Is there any possibilties it will replace goals in the near future ?
      Is there any limitation on event tracking (goals are limitied to maximum 4 in GA)?

    4. says

      Hi Justin,

      wonderful series, really helpful. But I share with Jahangir a doubt on how to implement/define <ACTION> <VALUE> . Please let us know whenever you have more information about that…

      Thank you very much for sharing all that!

    5. says


      Great observation. Based on what I’ve seen, events will be an effective way to circumvent the 4 goal limit in GA.

      Thanks for reading and thanks for the observation.


    6. says


      Event tracking is just a framework to track data. It’s so flexible that you can literally capture anything. However, the flexibility also makes the implementation difficult becuase you need to create the hierarchy of data before the implementation.

      When event tracking is rolled out to masses I’ll start writing more about it and provide some examples.

      Thanks for reading and thanks for the comment.


    7. Daniel Waisberg says


      please do a favor to the world: RELEASE A NEW VERSION OF YOUR PDF!

      You will make so many families happier: WA will arrive home earlier and play with their kids, enjoy their times with their husbands/wifes, have more time to spend on their hobbies, and so on. Christmas is coming…


    8. says


      No news on when event tracking will launch, sorry!


      I’m working as fast as I can to get the next version done! I’ll try to get you home for dinner as soon as I can. :)


    9. Avlok says

      Any word on the updated PDF? I loved your work on the first PDF but an updated one would make implementing the ga.js a lot easier :-)

    10. Christina says

      I do agree about the insights for event tracking. My question is that. Does this event tracking code imply for tracking a click in a static image?.

    11. says

      Hi Christina,

      You can use the event tracking code to track anything, including a click on a static image. The code for tracking a static image will be different than the code above because your data model for your events will be different than the data model I created for the example above.

      If you’re just getting started with event tracking check out the first post in the event tracking series. It talks about setting up a data model before adding any code.

      Thanks for the question,


    Leave a Reply

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

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>