25 January 2011

Using Google Analytics Event Tracking

Google Analytics is my favourate tool to track my website. Now, you can track all events in your website easily with Google Analytics. Also, it is very easy to setup.

If you don't have analytics account, create one with your Gmail account. If you already has Google analytics in your website just add "<!--- This is event tracking code -->" portion.

The basic thing you need is the Site tracking and event posting JavaScript functions.

This is how it is look like:

<script type="text/javascript">

<!--- This is google page tracking code -->
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20xxxxxx-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);
})();

<!--- This is event tracking code -->
_gaq.push(['_trackEvent', category, action, optional_label, optional_value]);

</script>


If you prefer full documentation for this, you can read here at Google code.



No comments: