Track Outgoing Links With jQuery And G-Analytics!

September 29th, 2009

analytics

This is an explanation of how you can track single outgoing links with some jQuery and Google Analytics. Why would you do this? Say your selling an iPhone app, and you have a few ads/links on your own site linking to that iPhone app in iTunes, and you want to know how many people are clicking on that ad vs. the people buying the app. Sound like something you need? Lets get started.

If you don’t have a Google Analytics account, go make one and come back once you have installed the tracking code in the footer of your website. Don’t worry, this post will wait for you.

Step #1

Enter this into the <head> of your website if your not already using the jQuery library.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>

Step #2

Now go to the specific link that you want to track the clicks on. Your basic html link will probably look like this:

<a href="http://joshuaschaible.com/myiphoneapp" target="_blank">Buy My App!</a>

All we have to do is add one javascript variable:

onClick=‘javascript: pageTracker._trackPageview("/outgoing/NAME-HERE");’

Add the onClick function and your link will look like this:

<a onClick=‘javascript: pageTracker._trackPageview("/outgoing/NAME-HERE");’ href="http://joshuaschaible.com/myiphoneapp" target="_blank">Buy My App!</a>

Where it says “NAME-HERE” you should put a name or identifier of what your tracking. For example:

<a onClick=‘javascript: pageTracker._trackPageview("/outgoing/myiphoneapp");’ href="http://joshuaschaible.com/myiphoneapp" target="_blank">Buy My App!</a>

Step #3

Log into Google Analytics. In the left hand side go to “Content” and then to “Top Content.”

Picture 2

At the bottom there will be a search box which says “Filter Page.” Type in “outgoing”. It should then show you all records of /outgoing/ clicks. According to our example it should say “/outgoing/myiphoneapp/ and show you the amount of clicks and the amount of unique page views.

Picture 3

Click to enlarge!

Remember…

Google Analytics doesn’t work in real time yet, so you may have to wait up to 24 hours to start seeing the click numbers go up! Hope you enjoyed! Please comment with any questions!

Tags: , ,

Leave a Reply