Event Tracking: The Killer UX Feature in Google Analytics You Suck at Using

event-tracking

There’s no polite way to say this. But chances are very good that you suck at using event tracking in Google Analytics.

And the truth is, it’s not your fault. I’m not trying to be accusatory. I’m just saying… it’s time to man up and admit your failings. Let’s come together in one cathartic Kumbaya moment of personal responsibility and admit we can do better.

Because you can. Hell, *I* can do better and this is my article!

Event tracking is a way of keeping track of things, components, and happenings as Michael Fienen likes to say.

What does this mean? It means you can track stuff in Google Analytics more granularly than at the page view level.  Now we can track specific items within pages.

Examples of How to Use Event Tracking to Your Benefit

1. Multiple Calls-to-Action

Many sites have multiple calls-to-action on the same page. By tracking clicks from each one, you can compare the CTAs and find out which one is doing the heavy lifting.

2. Track Ad Clicks

We have an advertising block on the website. Look over to the right towards the top of the page and you’ll see the six ads. We can easily track clicks from those ads using event tracking.

3. Track downloads

We also have a podcast on our website. The files themselves download from a different domain making it hard for us to know how many downloads are occurring. By tracking the individual download link on the site, we can see at a glance how many times a particular podcast has been downloaded.

4. Realtors – Track the outbound links to your MLS provider

In my experience, Realtors have the toughest time of anybody developing a solid sales funnel on their website. The problem stems from the laws that govern how the MLS can be used on websites. It depends from county to county in the US, but oftentimes, Realtors find themselves having essentially a vanity website with their own personal listings and then a link or an iframe that leads to the MLS, which is hosted on the parent company’s websites.

When this happens, the Realtors are assured that the parent company – the local Century 21 branch, or ReMax branch – will, if they get the lead, give it back to the Realtor whose website they used to access the MLS. This is all fine and good as long as the leads are coming in, but more than one Realtor in my day has been skeptical. With event tracking, a Realtor can track the outbound link to the MLS. If they care to run numbers against their parent company, they can. But in any case, they should get some idea of how many people managed to get that far in their funnel.

The Code Behind Event Tracking

In order to get event tracking to work, you have to add some code to the event on your website that you wish to track. This can be a little daunting if you’re not used to looking at code but it’s necessary to understand because how the code is written will effect how your events are tracked.

If you’re comfortable with code, feel free to dig directly into the Google Developer’s Event Tracking Guide. It’s pretty sweet.

For everybody else, here are the basics of what you need to know:

The HTML

You’re almost always going to try to use event tracking with the onclick attribute. Hopefully you’re familiar with a regular anchor linking tag.

<a href="#">some text</a>

Adding the onclick attribute is simple.

<a href="#" onclick="#">some text</a>

See? EFFEN DEEP.

Now all that’s left is the code to use inside the onclick attribute.

The Google Code

The first part is just a bit of Google code stuff. We have to use the following code inside of the onlick to push the data to Google.

_gaq.push()

All that’s left is the part you need to edit. Take a deep breath. It won’t be that bad. Here it is.

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

Now, see? Not so bad. Right? All you need to know is what those values inside the parentheses mean so you can modify them to suit your needs and you’re practically good to go!

What those values mean

  • category (required) – The name you supply for the group of objects you want to track. (e.g. ‘downloads’, ‘CTA’, ‘outbound links’, etc.)
  • action (required) – A label that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object. (e.g. ‘click’, ‘download’, ‘play’, etc.)
  • label (optional) – An optional string to provide additional dimensions to the event data. Use this to label your event with a specific name.
  • value (optional) – An integer that you can use to provide numerical data about the user event.
  • non-interaction (optional) – A boolean that when set to true, indicates that the event hit will not be used in bounce-rate calculation.

Note that label, value, and non-interaction are all optional. If you opt not to use them, just leave them out completely.

Bringing It All Together

If we take all of the code above and combine it, it looks like the following:

<a href="#" onclick="_gaq.push(['_trackEvent', 'category', 'action', 'label']);">

You’ll notice two things. The first is that the code for _trackevent isn’t quite what I wrote above. The second is that everything seems to be in single quotes. I don’t pretend to be a syntax expert in javascript, but I can explain why the code difference. When we added in the _gaq.push function, the rest of the code had to be modified to fit that format.

The second thing is, I left off the final two attributes – value and non-interaction. You can use them if you wish, but I don’t. So I’m leaving them off.

Examples of Event Tracking Code

Let’s go one step beyond the general syntax above to show a few examples of how event tracking code works.

Track Calls to Action

You can give the labels any name. You can make them awesome, descriptive, or if you’re like me, boring an numerical.

<a href="#" onclick="_gaq.push(['_trackEvent', 'Call to Action', 'Click', 'Button 1']);">
<a href="#" onclick="_gaq.push(['_trackEvent', 'Call to Action', 'Click', 'Button 2']);">
<a href="#" onclick="_gaq.push(['_trackEvent', 'Call to Action', 'Click', 'Button 3']);">

Track Ad Clicks

In this example, I use ‘Ads’ as my category. I use the ‘action’ space to delineate which ads I’m serving for free, getting paid for, and are using as an affiliate. Then I used the label for the company name on the ad.

<a href="#" onclick="_gaq.push(['_trackEvent', 'Ads', 'Paid Ad', 'Company 1 Ad']);">
<a href="#" onclick="_gaq.push(['_trackEvent', 'Ads', 'Free Ad', 'Company 2 Ad']);">
<a href="#" onclick="_gaq.push(['_trackEvent', 'Ads', 'Affiliate Ad', 'Company 3 Ad']);">

Track Downloads

Are you getting the idea that tracking stuff isn’t hard? It’s basically copying the same code into place and modifying a few parameters so it will log itself correctly in Google Analytics. This is no different.

We can track our individual podcast downloads with the following code.

<a href="#" onclick="_gaq.push(['_trackEvent', 'Podcasts', 'Download', 'BUX 48']);">
<a href="#" onclick="_gaq.push(['_trackEvent', 'Podcasts', 'Download', 'BUX 49']);">
<a href="#" onclick="_gaq.push(['_trackEvent', 'Podcasts', 'Download', 'BUX 50']);">

In this case, ‘Podcasts’ is the category, ‘Download’ is the action, and each podcast is labeled in the ‘label’ attribute. Easy.

Wrapping It Up

What you should take away from this article is that event tracking is easy. There’s no reason to suck at it.

We sucked because we didn’t know better. And now we don’t have that excuse.

So go forth, track your events. Get better data and make smarter decisions.

You can do it!

Other Resources

About the Author

A longtime web professional with over 18 years of experience working with clients in the music business, actions sports industry, and local businesses. Owner of Little Wing Marketing. Google Plus

12 comments on “Event Tracking: The Killer UX Feature in Google Analytics You Suck at Using

  1. Great write-up! Thanks Ben for putting this together.

    I especially like your examples explaining the benefit of event tracking. Those are very effective examples and scenarios.

    Event tracking is a gift from Google and I wish every GA user can take advantage of it.

    That’s what we are trying to do at skyglue.com. Our tool automates Google Analytics event tracking and tracks individuals and their detailed on-page activities (links, buttons, images, forms etc.) with just one snippet of JavaScript.

    We hope with our tool, people can save a lot of time on implementing advanced GA features.

    Cindy

  2. Pingback: BUX Podcast #51: Olympics and Google Analytics | A Better User Experience

  3. Pingback: BUX Review: The Hello Bar | A Better User Experience

  4. Pingback: How To Use Google Analytics to Get Your Crappy Website to Print Money | A Better User Experience

  5. Pingback: Here’s My Full-Proof Process For Designing Great Web Sites That Make Money | A Better User Experience

  6. Another great post that makes it easier for people to use the features in Google Analytics. Ben; We would be more than happy to re-blog some of your articles at Lighthouse8.com. Thanks for sharing!

  7. Awesome. I enjoy your humor in presenting this but more importantly you made it so easy to understand. Will be looking out for anything else you do.

    Shot

  8. OK – excellent guide for beginners like me. I have used this code, and events are being tracked in GA, but…

    235 of your visits sent events
    Total Events: 0
    Unique Events: 0
    etc. etc.

    Any thoughts as to what I am doing wrong?

  9. Hi Ben!
    This is a great article! My question is how does the code attach to a specific button on a page? Should the lable be the buttons ID tag??
    Thanks for the helpful post!

  10. Pingback: Deborah’s Weekly Roundup of Web Development and Design Resources: August 5, 2012

Leave a Reply

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