views:

351

answers:

2

Hi everyone, 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

A: 

The google analytics snippet sends google the page URL (among other things, probably) every time it's executed. I don't think you will be able to use it to count button clicks. If you execute the same snippet, it will keep sending the page's URL which is hardly valuable. If you manage to change the URL it sends, you might be able to get something...

Update:

You were right and I was wrong: google analytics does in fact support tracking events other than page loads.

Tomislav Nakic-Alfirevic
I think you are wrong. Everytime the button clicks I don't go back to the same page. I simply execute some javascript to write on a div.innerHTML (for what it matters).In other words, I can't record via google analytics the fact that the user has clicked on my button. Surely there must be a way: I can think of a solution myself which hidden IFrame but I would think there must be better ways
vfix
That's exactly what I ment by "if you manage to change the URL it sends". The google snippet sends the URL of the page it's in, so you would have to have an IFrame with the snippet to be able to send a unique button identifier (URL) to google. I agree that that is a clunky way to do it, but google analytics was designed to count page loads, not events on the page.
Tomislav Nakic-Alfirevic
Thanks but I think and hope you are wrong. since it's a very cluncky way of doing it.
vfix
It seems you haven't noticed that I updated my answer: I provided a link to what is exactly what you are looking for.
Tomislav Nakic-Alfirevic
+4  A: 

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>
Brian