Custom Event Tracking with Google Analytics

I have been researching a method for tracking clicks to external sites from my site. Google Analytics’s custom event tracking is a nice solution. Here is a link for the asynchronous event tracking scripts for Google Analytics: http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html#Anatomy. Keep in mind that to work with this code, you need the 3rd generation of Google Analytics scripts on your site. If you are using urchin.js or ga.js then you need to update your scripts.

Here is an example implementation:

<html>
<head>
<script type="text/javascript">
function LogLinkClick( linkId ){

_gaq.push(['_trackEvent', 'Outgoing Links', 'Click', 'Link ' + linkId]);

alert( "Clicked 'Link " + linkId + "'" );
}
</script>

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>
</head>
<body>
Hello World!<br /><br /><br />

<a href='javascript: LogLinkClick(1);'>Link 1 </a><br />
<a href='javascript: LogLinkClick(3);'>Link 3 </a><br />
<a href='javascript: LogLinkClick(5);'>Link 5 </a><br />
<a href='javascript: LogLinkClick(7);'>Link 7 </a><br />
</body>
</html>

You need to dig around the Google Analytics dashboard to find the event tracking reports.

  1. When you access the main page for Google Analytics, click the View Report link for the profilefor which you are tracking the events.
  2. On the left navigation, select Content
  3. Under Content, select Event Tracking and Categories
UPDATE
Google Analytics has released a beta of their new user interface. To view your custom events in this new user interface, expand the Content tab on the left navigation then Events and Overview.

7 thoughts on “Custom Event Tracking with Google Analytics”

  1. Many thanks for the marvelous blog posting! I found your post very interesting, I believe you are a excellent writer. I added your blog to my bookmarks and will return in the futureto your blog. Keep up that exciting job, have a great daytime!

Leave a Reply

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