Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use google analytics to count clicks on a button

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

like image 605
rowly Avatar asked Mar 17 '10 10:03

rowly


1 Answers

Updated Answer

Here is the new method for Google Analytics event tracking:

<button onClick="ga('send', 'event', 'Category', 'Action', 'Label');" >Button text</button>
  • Category: Typically the object that was interacted with (e.g. 'Video')
  • Action: The type of interaction (e.g. 'play')
  • Label (optional param): Useful for categorizing events (e.g. 'Fall Campaign')

More info here: https://developers.google.com/analytics/devguides/collection/analyticsjs/events

like image 187
J Wang Avatar answered Sep 19 '22 17:09

J Wang