how to use google analytics to count clicks on a button

google-analytics

Solution

You can trackPageview in the link's onclick handler: http://www.google.com/support/googleanalytics/bin/answer.py?answer=55521

<a href="javascript:void(0);"onClick="javascript:pageTracker._trackPageview('/folder/file');" >

This inflates your pageviews though, so it may be better to so use GA event tracking: http://code.google.com/apis/analytics/docs/tracking/eventTrackerOverview.html

<a href="#" onClick="pageTracker._trackEvent('Videos', 'Play', 'Baby\'s First Birthday');">Play</a>

Problem

I have google analytics on my site. One page has a button which when pressed executes some javascript. It would be nice to monitor the number of hits the button receives when people come to this page. Can anybody suggest the easiest way to achieve this with google analytics ? Are there any best practices to do this ? thanks

Original source