How to use Google Analytics to track your visitors

02 Aug

First create a Google Analytics Account using your gmail account.

Get the property id something starts with UA-xxxx-x

Include the provided Javascript code with the above property id immediately before

This is a sample generated code.

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

Track your visitors in the way they interact with your web page.
Form submitting, mouse clicks or any other events can be tracked.
Example :

<a href="#" onclick="_gaq.push(['_trackEvent', 'Ads', 'Sidebar', 'Food']);">track me</a>

<input  type="submit" value="Sign Up Now!" onclick="_gaq.push(['_trackEvent', 'Signup', 'click', 's1']);"/>

Change _gaq.push() by providing suitable parameters.

_gaq.push([‘_trackEvent’, category, action, label, value])

Leave a comment

Posted by on August 2, 2012 in JavaScript


Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: