Route 1. Visitor can click on any of advertised products
Route 2. Visitor clicks the Ads by Google link to submit feedback to Google
Route 3. Visitor clicks the Advertise on this site link - maybe to sign as an adwords advertiser
Of these three possible exit routes, only the first route converts into dollars. As an Adsense publisher, I am very keen to track what visitors are clicking while exiting your website. If lot of my visitors are exiting my website by clicking the "Advertise on this site" without signing up as an Adwords advertiser, I will probably disable the feature.
So how do we track visitor clicks in Adsense units ? There are couple of commercial adsense tracking scripts but recently, Shawn earlier released a JavaScript snippet that allows you to track visitor clicks on products displayed in Google adsense unit. Shawn's script work great but tracks only Google Adsense Clicks for Route 1.
Here is a slightly modified version of the visitor click tracking script that offers some more advantages:
a. Offers visitor click tracking for Adsense, Yahoo YPN and Chitika eMiniMalls.
b. Find how many visitors clicked on "Ads by Google" link to submit feedback about Google ads on your website.
c. View statistics separately for clicks on Google Adsense Text / image Ads and Google Adlink units.
d. Find how many potential advertisers clicked the "Advertise on this site" link.
e. Track how may left your website by clicking the Yahoo Publisher Network without click the YPN ad.

Here is the full Javascript code. You need to place it after all your chitika, google adsense and chitika javascript code. The most recommended position is just before the closing </body> tag. Google has clarified that it would not violate the AdSense Terms and Conditions to use Google Analytics to track outgoing clicks.
For geeks, here's how the click tracking script works: The script loops through all of the IFRAME on the page, and if the IFRAME source includes a google or chitika or yahoo ad server address, it will attach the corresponding function as an onfocus handler. When the ad unit obtains focus, urchinTracker() is called, with a goal identifier.
You will also have to create individual goals in Google Analytics for your website profile. Google lets you define only 4 goal, so choose wisely. You can always add new goal and delete the older ones.
<script type="text/javascript">for(var i = 0; i < elements.length; i++) {
function trackAdvertiserSignUp(){
urchinTracker("/GoogleAdwordsSignup");
}
function trackGoogleFeedbackClick(){
urchinTracker("/AdsByGoogleFeedback");
}
function trackYPNFeedbackClick(){
urchinTracker("/YahooPublisherFeedback");
}
function trackYPNClick() {
urchinTracker("/YPNClick");
}
function trackChitikaClicks() {
urchinTracker ("/ChitikaClick");
}
function trackGoogleAdsenseClicks() {
urchinTracker("/GoogleAdSenseClick");
}
function trackGoogleAdlinkClicks() {
urchinTracker("/GoogleAdLinkClick");
}
var elements;
if(document.getElementsByTagName) {
elements = document.body.getElementsByTagName("IFRAME");
} else if (document.body.all) {
elements = document.body.all.tags("IFRAME");
} else {
elements = array();
}
if(elements[i].src.indexOf("pagead2.googlesyndication.com/pagead/iclk") > -1) {
elements[i].onfocus = trackGoogleAdsenseClicks;
} else if (elements[i].src.indexOf("pagead2.googlesyndication.com/pagead/ads") > -1) {
elements[i].onfocus = trackGoogleAdlinkClicks;
} else if (elements[i].src.indexOf("adwords.google.com") > -1) {
elements[i].onfocus = trackAdvertiserSignUp;
} else if (elements[i].src.indexOf("services.google.com") > -1) {
elements[i].onfocus = trackGoogleFeedbackClick;
} else if (elements[i].src.indexOf("mm.chitika.net") > -1) {
elements[i].onfocus = trackChitikaClicks;
} else if (elements[i].src.indexOf("overture.com") > -1) {
elements[i].onfocus = trackYPNClick;
} else if (elements[i].src.indexOf("publisher.yahoo.com") > -1) {
elements[i].onfocus = trackYPNFeedbackClick;
}
}
</script>
Shawn's Javascript works only with IE browser. Aaron Wall released a modified version of Adsense Click Pepper script that seems to work with Firefox (Gecko), Safari, Konqueror browsers. The Adsense Click Pepper script uses mouse cursor position prior to page unload to help detect AdSense clicks in Firefox.
Download SEOBook javascript source | Track AdSense Clicks With Google Analytics | Read Shawn's blog post | Read Aaron Wall's post | How to define a Goal in Google Analytics
Find this article at: http://labnol.blogspot.com/2005/12/visitor-click-tracking-in-adsense.html
web: http://www.labnol.org/ email: amit@labnol.org

Reader Comments
There are so many different versions now and I am having a hard time to find out what version is the best for different needs and what are the weaknesses on each script?
Maybe you can make a new post to clarify all this?
Kim
Written on 5/1/06 8:18 AM
hi amit,
first of all - an amzing blog. i can only be inspired, if not envious.
excuse me for being a newbie ( first blog 2 weks old)- i understand the code being added to the template etc but i have no idea about 'urchin tracker'. Infact i did add the java code to my blog but unfortunatley, moron that i am, could not find the way to track the clicks after that.
If you are busy, cud you atleast point out a link where i can learn more.
thank you, and i have added you to my favs.
also did in 2 clicks.
Mazhar
www.hairclinic.blogspot.com/
Written on 16/1/06 8:21 PM
Is the setting in google analytics enough or I have to use the javascript also ?
I dont use chitika, they require high traffic which is a far fetched dream-thing for many.
Thanks in advance.
Written on 6/7/06 7:30 PM
"it will attach the corresponding function as an onfocus handler"
onfocus does not work for iframes under firefox, mozilla and other gecko browsers
Written on 21/8/07 6:47 PM