3/30/12

Adding Google Analytics Java Script Event Tracking

To add Google Analytic tracking events for any java script event use this code:


_gaq.push(['_trackPageview', '/pagename/item-to-track']);


This assumes you have included your analytics code:



var _gaq=[["_setAccount","UA-XXXXX-X"],["_trackPageview"]];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";
s.parentNode.insertBefore(g,s)}(document,"script"));


So for example: Click Me

8 comments: