Friday, November 18th, 2005Friday, November 18th, 2005

Track AdSense Clicks With Google Analytics

It would be cool if Google automatically tracked AdSense clicks into Google Analytics... But until they do, here's a little bit of JavaScript code you can use to do it. You can then setup an AdSense click as a "goal" within the Analytics interface.

<script type="text/javascript">
// by Shawn - http://www.shawnhogan.com/2005/11/track-adsense-clicks-with-google-analytics.html
// Put this at the bottom of the page (after the last AdSense block)
	
function adsense_click() {
	if(window.status.indexOf('go to') == 0) {
		urchinTracker ('/AdSenseClick');
	}
}
	
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('googlesyndication.com') > -1) {
		elements[i].onfocus = adsense_click;
	}
}
</script>

This only works with Internet Explorer because of some limitations/bug with Mozilla. I'm too lazy to code a complicated workaround for other browsers (which would involve running JavaScript code whenever the mouse moves which seems really inefficient to me). Hopefully Mozilla will fix the bug (although it's been pending for 2 1/2 years now).

Basically it will log an AdSense click as a pageview to a non-existent page (http://www.digitalpoint.com/AdSenseClick in my case).

UpdateI made a version of the code that will work with AdSense and/or Yahoo Publisher Network. You can find it over here.

51 Responses to “Track AdSense Clicks With Google Analytics”

  1. Ray Says:

    Could this be modified (easily) to work with YPN?

  2. Shawn Says:

    Yeah… could work with YPN easily as well.

  3. AdMoolah News and Views » Google Analytics Update Says:

    […] Shawn at digitalpoint noticed the same thing and came up with a JavaScript hack to partially fix this. The reason I say “partially” is that it only works for visitors using Internet Explorer. I have included this JavaScript on one of my sites, but I have no idea when I will actually be able to see the results. […]

  4. Damon Hart-Davis Says:

    Hi,

    Kewl: I have added the urchinTracker( ‘ fake rel URL’ ) to my existing IE clickthrough code so I’ll have the stats in my custom DB and in Google Analytics.

    I shall put this up on one mirror almost immediately.

    Thanks,

    Damon

  5. Google Adsense + Analytics - S-O-S SEO Blog Says:

    […] Hier entlang geht es zum Forenbeitrag Track AdSense Clicks With Google Analytics. […]

  6. aaron wall Says:

    a friend of mine modified the code from Adsense Click Pepper to uses mouse cursor position prior to page unload to help decect AdSense clicks in Firefox.

    http://www.seobook.com/analytics/astrack.js

  7. Ray Says:

    Ok, well I tried it with YPN and my stats finally updated and nothing shows.

    Is this wrong?

    if(elements[i].src.indexOf(’overture.com’) > -1) {

  8. Shawn Says:

    The code would need to be a little different because Yahoo ads don’t set the browser status to “go to whatever”, so I would just take out the logic that tests for it.

  9. Ray Says:

    Well, I’m sure Shawn is right… but it’s Greek to me…hehe. I think he’s talking about removing the “if”, but it’s hard to test something with clicking it or waiting for google to update sats.

    If anyone has a working example, I would appreciate seeing it. I would REALLY like to have this to work with YPN.

    Thank you.

  10. Shawn Says:

    You can test it (make clicks yourself) by changing the AdSense ID to ca-test. Oh wait… that wouldn’t work for YPN… hahaha… no idea what YPN’s test ID is.

  11. DerAdBlog » Blog Archive » AdSense Klicks loggen mit Google Analytics Says:

    […] Hier der Code: // by Shawn - http://www.shawnhogan.com/2005/11/track-adsense-clicks-with-google-analytics.html // Put this at the bottom of the page (after the last AdSense block) […]

  12. Track AdSense Clicks With Google Analytics: Blog Tips at ProBlogger Says:

    […] Shawn from Digital Point has developed a piece of javascript that will allow those AdSense publishers who use Google’s Analytics to Track their AdSense Clicks. The stats it gives should shed a bit more light on what pages convert best for Adsense clicks, what sources of traffic click ads more etc. […]

  13. Randy Charles Morin Says:

    You are too cool! Thanks!

  14. Track your adsense clicks » Online Business Tips at Metrobisnis Says:

    […] - Shawn (Digital Point) , read more… - SEO Book, Read More… […]

  15. Max Says:

    Thanks for the script Shawn! I looked at my stats for the past week and looks like its not accurate comparing with Adsense account - do you know why?

  16. Shawn Says:

    Because it doesn’t work with Firefox users (see note about Mozilla bug).

  17. Используем Google Analytics для кликов AdSense » Ну и Ну! ру Says:

    […] 1) Первую версию берем у Shawn Hogan (недостаток не работает в IE) 2) Вторая доработанная версия найдена тут […]

  18. Entreprenerd » Track Google AdSense Clicks with Google Analytics Says:

    […] Digital Point’s Shawn has created a piece of JavaScript code that allows you to track your Google AdSense clicks through Google’s Analytics statistics package. The stats that are given will shed more light on what pages your visitors are clicking links to ads on and what pages they are not. Additionally, SEO Book has followed and developed one as well. The advantage of SEO Book’s is that it works both in Internet Explorer and FireFox whereas Shawn’s only works in Internet Explorer. […]

  19. atul Says:

    from where can I get this blog script? Its so simple and yet very attractive.

  20. Shawn Says:

    This is WordPress with a custom template.

  21. » Seguimiento de Adsense en Analytics Says:

    […] Shawn nos propone un pequeño código para que pongamos en nuestro sitio web (al final de todos los bloques de Adsense) mediante el cual se podrá hacer un seguimiento de Adsense dentro de aquellos afortunados que disponen ya de Google Analytics. […]

  22. enrii.blog » Tracking Adsense Clicks with Analytics Says:

    […] Most of you must have been wondering, which page of my site generates the most income? You can now get it answered with a new Adsense Tracking script by Shawn Hogan. Basically, all you have to do is to create a goal in your Google Analytics, then add the script to the bottom of all your pages. However, the script doesn’t track Firefox clicks. Another implementation by Aaron Wall claimed that his script is able to do that. I still don’t have any of them installed in my blog yet as my blog doesn’t generate any revenue. Let me know if any of the scripts works for you. […]

  23. Ivan FXS Says:

    Strange it is:

    elements[i].onfocus = adsense_click;

    - aren’t onfocus and onclick mixed here?

  24. Juan Says:

    I need help. Don’t Work!

  25. J-Foster.NeT » Newest Adsense Tracking Tool Says:

    […] For the ones who are using Google Analytics to track their site traffic, Shawn Hogan just wrote a handy javascript code to track Adsense clicks as well. Visit Shawn’s site to explore how to implement this new handy tool and some examples related. Posted by J. Foster | […]

  26. klmarlon Says:

    Great.
    But I found that it works well for the first click, but when return back to the history page, the following clicks can not be tracked.
    Can you tell me how to figure it out?

  27. ChitikaNews.com » Blog Archive » Track Chitika Ads with Analytics Says:

    […] <script type="text/javascript"> // by Shawn - // http://www.shawnhogan.com/2005/11/track-adsense-clicks-with-google-analytics.html // Put this at the bottom of the page (after the last AdSense block) // Update: Randy added Chitika […]

  28. Web Analytics Guide » Blog Archive » Track Chitika E-Minimalls! Says:

    […] Here’s the code: // by Shawn - // http://www.shawnhogan.com/2005/11/track-adsense-clicks-with-google-analytics.html // Put this at the bottom of the page (after the last AdSense block) // Update: Randy added Chitika […]

  29. miscblogger Says:

    hey thanks! i will try to use this in both of my blogs!

  30. Stefano Says:

    I wonder if this works..anyone tried it?

  31. Bruk Google Analytics til å tracke Adsense klikk - Søkebloggen Says:

    […] Først lagde lagde Shawn fra DigitalPoint en versjon kalt Click Pepper som bare virket med Internet Explorer (rundt 90% bruker dette fremdeles), men så oppgraderte Aaron Wall fra SEO Book dette scriptet til også å fungere med Mozilla FireFox: http://www.seobook.com/archives/001370.shtml. […]

  32. Brian Says:

    Any chance this could easily be modified for adlinks? I think they use “View ads about” instead of “go to”

  33. The Google Insider » Track AdSense Clicks Through Analytics Says:

    […] your Google Analytics account. Take a look at both and see which one fits your needs the best! +del.icio.us Tags: Analytics, AdSense Posted by JonathanDingman […]

  34. medical info Says:

    I have Analytics and this is very useful. Thanks.

  35. Jafo Says:

    This doesn’t really work all that well. First of all, if someone clicks back, chances are clicks will not register.

    And this is not a Firefox bug, the reason it doesn’t work with firefox is “change status text” is off by default.

    Options -> Content -> Advanced

    Too bad, because this could be used to prevent clickfraud if it worked.

  36. Gregor Says:

    Worked great for me for first month or so, but the other day it stopped recording roughly 90% of my clicks. Anybody else seen this? My .js file is on a seperate domain, but this wasn’t a problem before. And help would be great. thanks.

  37. Google Search blog » Google AdSense Analytics Says:

    […] // by Shawn - http://www.shawnhogan.com/2005/11/track-adsense-clicks-with-google-analytics.html // Put this at the bottom of the page (after the last AdSense block) function adsense_click() { if(window.status.indexOf(‘go to’) == 0) { urchinTracker (‘/AdSenseClick’); } } 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(‘googlesyndication.com’) > -1) { elements[i].onfocus = adsense_click; } } […]

  38. Pandeblog 2.1 » links for 2006-04-14 Says:

    […] Track AdSense Clicks With Google Analytics (tags: adsense google) […]

  39. Small Business SEO Says:

    Very usefull code Shawn. Been looking for something to help me track adsense clicks. Thanks.

  40. Rahul Says:

    Dear All
    plz tell how to set up a goal for Adsense in Google Analytics

  41. Mike Lipkie Says:

    I have a question on what is being tracked as well. We are within 10% of the numbers reported by adsense, but only if we add in the number of hits from the googlebot client. Tracking only the IE hits, it ia much further off. Is that correct? Does the googlebot follow in the adsense links?

  42. Make Money with Adsense - Track AdSense Clicks With Google Analytics | Make Money With Adsense Says:

    […] Track AdSense Clicks With Google AnalyticsDigital Point s Shawn has created a piece of JavaScript code that allows you to track your Google AdSense clicks through Google s Analytics statistics package. […]

  43. Zombie Says:

    your script only works with the IE.
    Firefox doesn´t support “window.status” for security reasons.

  44. 100 Top links for Adsense : Top Links : eConsultant Says:

    […] Track AdSense Clicks With Google Analytics [See also : || webmaster || ] […]

  45. Isaac Paton Says:

    It don’t work with firefox

  46. Meethere.org Says:

    Will it work for referrals and search results?

  47. Markus Merz Says:

    If you just want to know how many AdSense clicks you have received you may want to check out the metrics package at performancing.com.

    Performancing.com Metrics counts AdSense clicks (incl. adlinks) and it also shows the goal of the clicks in the outbound links page.

    Performancing.com Metrics is a pretty complete free statistics package. Not as powerful as Google analytics but it has hourly updates and a faster overview.

  48. Doug Karr Says:

    Just wanted to add my thanks!

  49. Track your AdSense Ad Clicks to further maximise on your returns | Chaos Laboratory Says:

    […] AdSense Tracker script for IE - shows you how to link the clicks to Analytics. Doesn’t work with Firefox. […]

  50. O.Butler Says:

    I am able to track Adsense clicks; however, is there a way to track which page the adsense ad was clicked?

  51. O.Butler Says:

    Never mind…I found a report that tells me which page the adsense ad was clicked.

Leave a Reply