Integrate Google Event Tracking with JavaScript
This post discusses easy ways to integrate Google Analytics Event Tracking in your website. Event Tracking is a tool that broadens your ability to track user interaction with your website. Prior to event tracking, using Google Analytics gave you rich information about your page views. With Event Tracking you now have a wealth of information about usage on your non-page reloading events such as AJAX calls, hover events, mouseovers — anything you would like to define and track. (Just make sure you have an account first).
It’s dead simple and, after setup, takes a one-line call to a JavaScript method supplied by Google:
pageTracker._trackEvent(category, action, opt_label, opt_value);
You just have to get the right arguments to that method, so you know what you’re tracking. In the Google tutorial the example is predicated around sending the arguments to the _trackEvent method inline on an onclick event. Instead of doing that, which will create redundant script tags in our views, let’s label our markup in such a way that we can grab a collection of trackable elements via JavaScript and submit them automatically, on a click (or other) event.
Contents