Skip to main content

Visitor Click Tracking in Adsense, Chitika and YPN with Google Analytics

If you carefully analyze the Google Adsense Unit displayed just above, you will notice that the ad offers three exit routes where a website visitor can click.

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">
function trackAdvertiserSignUp(){

function trackGoogleFeedbackClick(){

function trackYPNFeedbackClick(){

function trackYPNClick() {

function trackChitikaClicks() {
urchinTracker ("/ChitikaClick");

function trackGoogleAdsenseClicks() {

function trackGoogleAdlinkClicks() {

var elements;

if(document.getElementsByTagName) {
elements = document.body.getElementsByTagName("IFRAME");
} else if (document.body.all) {
elements = document.body.all.tags("IFRAME");
} else {
elements = array();
for(var i = 0; i < elements.length; i++) {
if(elements[i].src.indexOf("") > -1) {
elements[i].onfocus = trackGoogleAdsenseClicks;
} else if (elements[i].src.indexOf("") > -1) {
elements[i].onfocus = trackGoogleAdlinkClicks;
} else if (elements[i].src.indexOf("") > -1) {
elements[i].onfocus = trackAdvertiserSignUp;
} else if (elements[i].src.indexOf("") > -1) {
elements[i].onfocus = trackGoogleFeedbackClick;
} else if (elements[i].src.indexOf("") > -1) {
elements[i].onfocus = trackChitikaClicks;
} else if (elements[i].src.indexOf("") > -1) {
elements[i].onfocus = trackYPNClick;
} else if (elements[i].src.indexOf("") > -1) {
elements[i].onfocus = trackYPNFeedbackClick;

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