We pay for user submitted tutorials and articles that we publish. Anyone can send in a contribution
Learn MoreHere is a short tutorial about how to track Any Link Click with Google Analytics.
The first thing you will have to do is add a short snippet of code to the link you want to track. The code snippet you are adding is actually an OnClick JavaScript event handler that will be executed when the link is clicked and make Google Analytics take note of it. What you have to add is this the following:
onClick="javascript: pageTracker._trackPageview(’/Links/Test’);"
You can change "/Links/Test" to whatever you want, I will explain later what is it good for.
your tracked href should look like this:
<a href=http://www.dev102.com/ onClick="javascript: pageTracker._trackPageview(’/Links/Home’);"> Test Link</a>
Now we are ready to check out Google Analytics and for the results.
Log into your Google Analytics account do the following:
Now it is time to remember what we wrote in the OnClick event of the link, I wrote (’/Links/Test’) so if I type "Test" in this textbox and click go I will get all the Content that was viewed by readers With Test in the URL, and it will include all the clicks on that Link that we added the OnClick event handler. So there you go, you now know how many clicks were maid on you link.
Need help? Have a better way to track links? Please comment
Enjoy
Amit.
Tags :
AnalyticsClickclicksContentEventGoogleJavaScriptLinkOnClicktrack Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd
Topil James
Said on August 29, 2009 :
Hi!
I don’t understand one thing,
where do you insert the code Test Link
Thanks for your help
marcosz
Said on December 14, 2009 :
this doesn’t work reliably since you can’t predict whether the href or the onclick wil be executed first.
the href may take you to another page before the onclick executes.
Susan Reed
Said on April 16, 2010 :
I have a question.
Where do you insert the code and what is the code? Am I to assume that this is on Google? or do I need to insert some code in my head tag?
Please clarify. Thanks,
Susan Reed
Jamie
Said on May 2, 2010 :
Isn’t the link address supposed to be in quotation marks? so do I quote the whole thing or break it up?
GoosPoos :: Web & Software Technology Blog
Said on July 9, 2010 :
Can this track dynamic links like social bookmark buttons, where links are generated using dynamic php code like php_title etc.
Mike
Said on September 15, 2010 :
I tried this for 3 links on my site for about 35 mins. I copied the code and placed it in the href tag but it showed up in the text, so I added a space after the actual link, and then the link itself added the onClick, which broke the link. Seemed like good instructions, but not as simple as Amit makes it sound. Looking elsewhere for more adequate instructions.
kenny
Said on November 5, 2010 :
Is it possible to use this approach to track links going away from my site to a different site?
Thanks!
Alan
Said on March 16, 2011 :
This is too much trouble, just use a shortener service that has tracking, for example, use unily.it
Freelance Gigs Marketplace
Said on July 13, 2011 :
It’s probably good for the small sites, but how can you manually code links in large dynamic sites?
kiran
Said on August 17, 2011 :
error on footer
http://www.dev102.com/2008/07/30/how-to-track-link-clicks-with-google-analytics/
akmal
Said on October 15, 2011 :
man it isn’t showing up in analytics/content/view full report. there is a, i guess, a landing page report. can’t see the link tracking?