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:
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.
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']);">
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']);">
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!
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.
We hope with our tool, people can save a lot of time on implementing advanced GA features.
Pingback: BUX Podcast #51: Olympics and Google Analytics | A Better User Experience
Pingback: BUX Review: The Hello Bar | A Better User Experience
Pingback: How To Use Google Analytics to Get Your Crappy Website to Print Money | A Better User Experience
Pingback: Here’s My Full-Proof Process For Designing Great Web Sites That Make Money | A Better User Experience
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!
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.
Great information. Lucky me I came across your blog
by chance (stumbleupon). I have book-marked it for later!
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
Any thoughts as to what I am doing wrong?
Pete… post your code and I’ll take a look
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!
Pingback: Deborah’s Weekly Roundup of Web Development and Design Resources: August 5, 2012