Webmaster

Add Tracking Code on your Links

In order to track how many times someone clicks on a link, you need to add some special code. But before you get started – first things first. If you haven’t done so already, go set up an account on Google Analytics.

Once you have verified your site you many continue. In this example I will explain how to write code to track how many times someone has clicked on a .pdf file to download and view the file.

Step 1: Add this javaScript code in the head section of your HTML code:

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

var pageTracker = _gat._getTracker(“UA-xxxxxx-x”);
pageTracker._trackPageview();

Step 2: Add an onClick event to your hyperlink:


* As you can see from the code above, I’m using ASP.NET – I simply added the additional javaScript onClick event.

Step 3: Log into Google Analytics and click on “Content” on the left menu.
Step 4: In the filter box, type the special name you gave your tracking code. In this example I would type SpecialOffer/FirstPage.

Try it out! Happy Coding!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s