How to Enable Google Analytics Event Tracking – Web Tracking (ga.js)

Last updated
App Shah
Crunchify » Technology & Tools » How to Enable Google Analytics Event Tracking – Web Tracking (ga.js)
Google Analytics - Crunchify TrackEvents

If you have Google Analytics setup on your site then it is definitely recording pageviews. If you are not using it then you can add script easily with All in One Webmaster WordPress Plugin.

But what if,

  • You have to track special click events?
  • You need to track an event in google analytics when someone fills out a form and clicks submit?

So, what is event tracking?

Event Tracking is a method available in the ga.js tracking code that you can use to record user interaction with website elements, such as a Flash-driven menu system. This is accomplished by attaching the method call to the particular UI element you want to track. When used this way, all user activity on such elements is calculated and displayed as Events in the Analytics reporting interface. Additionally, pageview calculations are unaffected by user activity tracked using the Event Tracking method. Finally, Event Tracking employs an object-oriented model that you can use to collect and classify different types of interaction with your web page objects.

Other must read:

So why this post now?? To be honest, I wasn’t using this feature until last month. But as traffic increased to ~55k/day, I thought of using it lately and found really interesting metrics in Google Analytics.

Google Analytics Tracking - Crunchify Tips

Let me first share my Social Media code which I’m using in widgets (I’m not using any WordPress Plugins):

<ul id="social">

    <li><a href="" id="tw" onclick="_gaq.push(['_trackEvent', 'Outbound', 'Footer', 'Twitter']);" rel="nofollow" target="_blank">Twitter</a></li>

     <li><a href="" id="fb" onclick="_gaq.push(['_trackEvent', 'Outbound', 'Footer', 'Facebook']);" rel="nofollow" target="_blank">Facebook</a></li>

     <li><a href="" id="plus" rel="me author" onclick="_gaq.push(['_trackEvent', 'Outbound', 'Footer', 'Google-Plus']);" target="_blank">Google+</a></li>

    <li><a href="" id="rss" onclick="_gaq.push(['_trackEvent', 'Outbound', 'Footer', 'Rss']);" rel="nofollow" target="_blank">RSS</a></li>

Yes, we are looking at onclick() event and _trackEvent() method. There’s no need to change your scripts, or set a section up in your Google Analytics dashboard. All you need to do is add code to the link, and it automatically starts tracking within your dashboard.

onclick="_gaq.push(['_trackEvent', 'Outbound', 'Footer', 'Twitter']);"

_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
  • category (required): The name you supply for the group of objects you want to track.
  • action (required): A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.
  • label (optional): An optional string to provide additional dimensions to the event data.
  • 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.

Now what? View the reports. Once event tracking has been set up and working on your site for a day, go to the Content section of the reports and view Event Tracking. Unique events will show you how many visitors triggered a particular event.


So far, we just focused on links, but jQuery opens up the whole DOM to interactions. Here’s an obvious use to automatically apply a download action to any links that are ZIPs:

$(document).ready(function() {
    $('a[href$="zip"]').click(function() {
        _gaq.push(['_trackEvent', 'ZIP Downloads', 'Download', $(this).attr('href')]);

I highly recommend using this Google Analytics feature. What functions are you using in Google Analytics to see how your visitors behave on your site, and what actions are you taking to help them along the path from search to purchase? I’d love to hear your ideas!

14 thoughts on “How to Enable Google Analytics Event Tracking – Web Tracking (ga.js)”

  1. I made great use of event tracking when I had my site on Blogger, but now I’m using WordPress, and WordPress won’t allow me to use any “onclick” commands. (It stripped them all out when I imported my posts, they don’t work if I add them in, and when I looked it up, I read that apparently WordPress disables onclick now.) Do you have any solutions for this?

  2. I just cant doing it bro! I’ve already tried dozens of different codes on my blog but i can’t track any events! I’m trying to track the clicks on my partners’ banners, but it won’t work! I tried everything, even adding some extra code to my /head but still doesnt work. I dont know if my blog doesnt have jquery installed or whatever this might be. Can you please, try to help me?


Leave a Comment