Track Google AdSense Clicks via Google Analytics - Free AdSense Tracker
There have been 3rd party javascripts that track adsense clicks out for a while, but no free ones to my knowledge that track clicks on Firefox. Until now.
This free script integrates with Google Analytics to allow you to track your adsense clicks.
This tracking is done through "Goals". A goal is a way of tracking when a website visitor does something you want - Buy an item, submit a contact form, or in our case click an adsense ad.
Create a goal: To create a goal you assign it a URL. This url doesn't have to exist, as the javascript will trigger it.
In the Goal URL field, enter "/asclick" and "AdClick" for the goal name.
Adding the javscript to your page: Copy the astrack.js to your website server and add the following to the footer of your website. This has to come after all adsense code.
<script src="/astrack.js" type="text/javascript"></script>
Testing it: DON'T! There is no way to test that this works as it tracks adsense clicks, and you can't click your own adsense. You'll just have to trust me that works :)
After some time you should start seeing goal tracking appearing in your stats.
For example, here is source conversion. Note that the percentages are based on Visitors, not Pageviews, so they do not compare to CTR.
So from that graphic we can see that out of 11 visitors that came from MSN, 54% of then clicked on an adsense ad over the course of their visit.
Below many graphs in Google Analytics is a list with round arrows. If you click the arrows on almost any item you see an option for "To-date Lifetime value".
Click this and you see the Goal conversion for that item. For example here is the Coversion rate for DSL users.
Once you have Google Analytics tracking your clicks, you can cross segment that data to almost any other data Google Analytics shows. It becomes a very powerful way of optimising your site, not just for CTR, but for the type of visitors that click adsense.
[Thanks to Shawn Hogan and Jim from Digital Media Minute]
Comments
The "new Blogger" templates are now all xml, and I can't figure out how to make this compatible with their templates. It complains that the "for" loop syntax is incorrect.
Any ideas on how to embed this within a new Blogger template?
There is a tool to check that Google Analytics works on your web page before you see the results in your account. Just check ga.truwex.com. Feel free to post your feedback!
Thanks Aaron. Just installed the script and now I'll have to wait for some clicks to see what I can learn.
I was getting the permission denied warning in a version of IE6 on XP. The problem seems to be something to do with IE implementing some draconian anti cross site scripting code.
My solution was to include the urchin.js file using a server-side include instead of the script tag and wrapping everything in Javascript exception handling blocks.
Full details here in my blog post:
http://matthewrhall.blogspot.com/2007/08/google-analytics-jscript-permis...
Thanks for a great script. I make this script integrate with Google Analytics Plugin from http://boakes.org. I want to share my plugin to another WP users. Perhaps I need your permission. May I know your email so I can send you a copy of my plugin? Thank You and have a great day..
Feel free to contact me at me[at]supriyadisw[dot]net
working?
working?
Hi,
I've installed your script and to my suprise there is a huge difference between the data reported in Google Analytics and in Google AdSense. The ratio is 4x more using your script than in AdSense.
I've asked the AdSense support about it and their answer was very short just saying the Google AdSense reporting is right. Are there any reasons that could make the script overcount ?
Ludovic
I tried to put this script on my page and it didn't seem to work. Has Google somehow blocked this script?
maybe clickfraud or time delay stuff?
also keep in mind that with mozilla based browsers it estimates clicks based on mouse position prior to leaving the page...in some layouts maybe links right near the adsense or weird page rendering code could cause the problem
I can ask the coder if there are any other reasons as well...some have suggested if there are other iframes on the page some of those might wrongfully count.
Do Anyone Have An Idea About Google Analytics Will Freely Used By All The Sites And Blog Etc
I have added it and it seems to be working OK. I have asked my accountmanager at Google Ireland if the solutions goed against the Adsense Rules. I will post his reply here, if and when I get it.
This method doesn't work anymore? Am I right?
Do you think google analytics is good for adsense?
no.Google will kill you!
I have a theory that via analytics the script only accounts for 1 ad click per visitor session, hence the varying discrepancy some report.
Anyone know how this could be some how fixed?
Thanks for the tip; I just set this up on my site. Let's see if it works!
Script is working great. Thanks!
One question: Does anyone know if you could place the Google Conversion Code (from AdSense) in the adtrack.js file -- so you can see AdSense conversions in the AdWords interface? My primary need is to see figures by AdGroup, and an easier way to see by Keyword.
Or maybe there's another way to do this?
thanks.
Actually, there is a way to track whether the .js files is working correctly.
Use an HTTP stream watcher like Live HTTP headers OR Fiddler (I use IEWatch personally), and click on the Ads by Gooogle link (not a violation of the TOS I think). If astrack.js is working correctly you will see a request back to Google Analytics and if you analyze the query string you will see this parameter here "utmp=/asclick".
This could also explain some of the variation users are seeing between their AdSense and the Google Analytics numbers. (with the emphasis on some)
Anyway, it is a nice little script.
This is an awesome tool! I had no idea a tool like this existed.
I need invitation code for google analytics
PLZ
Matthew, so the script actually is working for you now? This sounds very odd because this method shouldn't work after Google's update in the Advertising code (which was in July 2007 something)..
So where do I put this code it if my blog is hosted on blogger?
So where do I put this code it if my blog is hosted on blogger?
OK, I figured out the answer to my own question. You cannot use the "a.b" syntax in the context of a "for" loop inside a blogger widget. So, you have to flatten the reference. This occurs in two places:
Inside function adsense_init ()
Original code:
for(var i = 0; i < el.length; i++) {
New Blogger widget compatible code:
var j = el.length;
for( var i = 0; i < j; i++) {
Then inside function doPageExit(e)
Original code:
for (i=0; i
New Blogger widget compatible code:
var j = ad.length;
for( var i = 0; i < j; i++) {
Is the script still working?
(trying again since the comment apparently interpreted my less-than signs as html tags and swallowed half the code.)
OK, I figured out the answer to my own question. You cannot use the "a.b" syntax in the context of a "for" loop inside a blogger widget. So, you have to flatten the reference. This occurs in two places:
Inside function adsense_init ()
Original code:
for(var i = 0; i < el.length; i++) {
New Blogger widget compatible code:
var j = el.length;
for( var i = 0; i < j; i++) {
Then inside function doPageExit(e)
Original code:
for (i=0; i < ad.length; i++) {
New Blogger widget compatible code:
var j = ad.length;
for( var i = 0; i < j; i++) {
SEO Noob, the script is still working indeed. However, the goal conversion isn't measured any longer.
Weird thing is that the 'AdClick' folder is still added to 'Content Drilldown', but Google Analytics won't recognise it as goal conversion.
I just found an amazing FREE adsense tracker..
http://www.adspytracker.com/?affiliate=306
umm question can this adsense tracker thing work for myspace at all ? to find out who is visiting my page ...... cause apparently i seen a code in someones page and it said urchin tracker in it so im just wondering
hey, can you make some code for chitika?
This is awsome Aaron, you are the best! Thanks for sharing again...
Added to my site. Seem to be working fine.
There is another adsense tracking script with easy integration with Analytics - check Contextual Tracker( http://contextualtracker.wiadomosc.info/ )
someone just sent me this link
(removed, as per below comment)
the script in the first comments is the same as you mention in the article ... only function names are changed and line breaks removed so it looks original
i get javascript error in IE with this ... error on line:
el[i].onfocus = urchinTracker('/asclick');
Permission denied
anyone else?
It works perfectly. The right solution. Very nice scripts. Thanks!
http://aevn.fr/index.php
Do you already have UrchinTracker on your site Bernis?
Great Dude, Its Really Great, BTW U Should Have Not Removed URL Submission Box, Instead Moderated The Comments...
sure i do. i didn't have it HEAD, but in the body, so I moved it into HEAD (i mean urchin tracker js) but the problem still persists.
if works (or at least doesn't pop any errors in javascript console) in FF but gives error in IE. looks like function urchinTracker cannot be called for some reason. but it should be, as urchin.js is linked above
everything is set acording to your instructions:
urchin.js in page head
astrack.js after adsense javacsript
wow!!
great its a very nice web!!
keep iy up !!
Cheerz!!
With this work with Yahoo ads?
Hi
First of all I would like to thank you fir this great advice.
And I have a question:
Would it be ok to translate this great article into German and use your screenshots (of course on my own webspace) when I give a link, saying something like "original article can be found at seobook.com"?
bye
Malte
Hi Malte
Yes you can publish this article in German.
Cheers
Aaron
How about adding more information, like the page where the ad was clicked on and which adblock it was, perhaps even the position of the click? Looking at the code, I assume that should be possible, but I wonder if Analytics will let me retrieve all this information :-). It would be neat to correlate this data with the effective click-earning...
Hi!
Thanks for this nice script. I added it and got first results today. But the numbers don't match... :(
More details would be nice, too! :)
Tobias
Has there been any developments in this field since this was published, Aaron?
I am looking for a script or somthing that can give me a better understanding of the performance of my AdSense ads.
Now how do we change it to track YPN clicks? :-P
I have not tested it, but Shawn gave some YPN tips here
forums.digitalpoint.com/showthread.php?t=39549&page=3
and here is what the current AdSense code would look like with YPN added
www.seobook.com/analytics/astrack2.js
although I am not a Javascript expert and my friend who made the code is not an uber Javascript expert, so I can't be certain if the YPN stuff is going to work on Firefox.
It should be able to track the pages whoes ads was clicked by users; otherwise it is useless.
May work if a insert ADSENSE into a DIV and I try to track DIV onclick with analytics like:
...adsense code...?
Guyz i found a some tips in Digital Inspiration Blog by my Amit Agarwal he got some tips about the yahoo, chitika too.. Check out the below link
Visitor Click Tracking in Adsense, Chitika and YPN with Google Analytics
Hey SEO Noob, yes the script has been working fine for me since applying my dodgy workaround. It seemed to always be the first page request that failed. My work around is imperfect because it just silently fails (thanks to the javascript exception handling block) on that first page request. Subsequent requests work fine.
Still can't get it to work for YPN. The Adsense works GREAT though. The stats were perfect.
I just installed the script and see the clicks coming in into Analytics. BUT... it's counting way more clicks than AdSense itself. I saw a few comments up here someone with the same problem. Is the cause of this already known? Is it clicks on public ads that don't generate an income? or is the script wrong? ..
Seems to work very well &'s easy to implement. - Great!
Does this track the ACTUAL ad that was clicked? I'm trying to find a way to tell if an ad is a low paying one (LCPC). I don't think this script provides this functionality but someone correct me if I'm wrong.
Thanks,
Tony @ http://www.productcritic.com
Matthew, are you also having problems with the conversion measuring? Since the Google Analytics update I can't find new reviews of this script so I want to make sure I'm not the only one having this problem. Otherwise I'm going to start debugging...
Do I get it correctly, that we can host astrack.js on the different website?
For example, blogger user can have his blog on the blogspot.com and load thee astrack.js from his verysmallsite.com or even from http://www.seobook.com/analytics/astrack.js :)
I am not certain if it would work...It may, but
etc
Excellent script, but I would like to know what is a most clickable ads? This is the most important thing you must know, it seems to me.
Is this script is useful with blogs.
Hi,
Everytime I try to create a Goal I get an error message:
Goal Creation failed. Please verify and try again. If you continue to have problems, please contact our support team.
Does this still work? Whats going on?
I have been using the astrack.js script for a while now and It's been great. Thanks for the generosity, and here's to your success.
Is this legal to use the script with adsense?
THanks
John
i get javascript error
anyone can help?
Anas,I think google analytics do not need invitation code, do you have gmail account? gmail need that.
if you need an invitation, please leave your email, i will send it to you.
John
It works and it works perfectly. The right solution. Free as well. Very nice. Thanks!
www.nithanth.com/blog
I'm not getting any trustfull date out of this.. the clicks shown in Analytics are WAY higher than the ones shown in AdSense..
Does the script also tracks a click on a link unit? Cause that one won't show up in AdSense and would explain the difference.
From some reason when doing cross segment on google(cpc) by keywords on than 50% of traffic is from (no data). Any idea why is that?
Hello
Where to put the file exactly? In the root dir? or in the dir where I have the file with the script included???
I need invitation code for google analytics too! Please! Who can help Me?
My stats are pretty far off as well, just in the other direction. Seems to be counting about 1/2 of the clicks that Adsense is reporting for the same time periods.
It's better than nothing, though - thanks for putting this together, Aaron.
I believe you can put the code anywhere as long as it is called properly with the javascript code on the page. Putting it in the root directory of your webiste and calling it with src='/astrack.js is the simplest though.'
I was hoping this one would tell what ads the users were clicking on - I've seen some (not free) trackers that can do that. I wonder if that could be integrated into this one.
You can load the script into local computer with apache, then you get PSA. Are you allow to test clicks on PSA though?
You can load the script into local computer with apache, then you get PSA. Are you allow to test clicks on PSA though?
astrack was working great until this past week. It's only picking up a fraction of the clicks I'm actually getting in Adsense. I'm assuming something changed in Adsense. Does anyone know how to fix?
the script has stopped working for me. only appears to be tracking approximately 10% of the clicks I'm getting. Anyone else having this problem? I'm referencing the .js file on another servier - but that didn't cause any problems for the first month or so.
Any help would be greatly appreciated. Thanks.
ASClick stopped working for me, too.
It bombs for not just one, but all of my sites. I loved it, too. :(
It has stopped working for me and a friend as well. Google must have changed something.
Thanks for this!
frank, That sounds like regular Google Analytics tracking that can very easily be copied and pasted into your space. Visit http://google.com/analytics
Is the tracker still working?
Are earnings displayed with this tracking tool?
It stopped working on my site http://www.golfhomeconnect.com several weeks ago. It basically got worse and worse til it wasn't tracking anything.
Anybody handy enough with javascript to try and fix this? Is it fixable? Sounds like you would be a hero to many : )
Does this script work for subdomains?
Somehow, this doesn't work for my site - which has many, many subdomains. Has anyone successfully tried it with subdomains?
Thanks very much for the script ;)
does anybody know when the service starts over again?
Hi mate ! Just what I was looking for ! Works perfectly and performs all jobs very nicely ! Great addition, keep it up ! :)
Once you have the GOOGLE ANALYTICS code, which section do you paste the code into on MySpace?
Does the usage of asclick.js violate Adsense terms?
Seems like a great script, but how can i use it for my blog since i could not download this script to the server. Is there anyways i could download the script to the blogspot server??? Please suggest.
Not that I am aware of. In fact I think it is totally fine.
asclick is a very worthy thing to use for generating more qaulity statistics :)
Robert Joosen
Hi All,
I have successfully implemented astrack, and can see, via my google analytics, clicks on adsense and correlation with adwords campaigns.
What is confusing me is what to do with Google Conversion Tracking GCT and AdSense. What does GCT do? Do I have to enable it, and how it works with astrack.
Thanks for you help.
steve
Is this script still uptodate? I think in 2 years there are a lot of changes in browsers and in adsense.
Do you already have UrchinTracker on your site Bernis?
This is working great! Is there a way to also capture the value of the click?
Google does not share click value with publishers, so you can't really grab a value for that.
Excellent addition to statisticans. Has started to use on Russian site infpartner.com
It would be excellent, if it is possible still $ for cliques to consider :-)
This doesn't make any sense. I always have WAY more clicks detected on analytics with this script, than I get in my adsense.
For example today, I have analytics is telling me 14 clicks, and adsense says 1 click for a total of 3 cents!?
It is like this everyday. I feel like I am being scammed.
This doesn't seem to work with GA's new js. Do we need to modify something in astrack.js?
Thanks!!
I have blogspot account with my own domain and no server... just the Google/Blogger thing.
Can I also use the free Adsense Tracker by including the code in the template?
If not... what other free tool can I use?
thx
Hi,
as some will already have noticed, the code above has certain problems.
1) the IE part: here the script just checks for onfocus. So clicking in the background of the iframe will count as a click. Or if the iframe already has the focus (due to position on the page) the event will not fire although you click the link. Better: trace onfocus (gets focus) and onblur (loses focus) and onmouseover, onmouseout as boolean flags and check for the link via onbeforeunload. This is way more accurate.
2) the firefox part: uses mousemove to update x,y coordinates. First Problem: "py=e.clientY;" is IE syntax, not Firefox (has to be "e.pageY;" instead, as with the X coordinate).
Second problem: In Firefox the iFrame swallows the mouseevent, i.e. while moving inside the iFrame, the handler is not called anymore which will lead to the coordinates being the last ones outside of the frame.
better: track for mouseover, mouseout event and look in the beforeunload event, if you were in the iframe.
3) testing: in order to test, just create an own iframe on a page and a document with a link as the content. then replace the 'googlesyndication.com' string in the script with the filename of this content document and you can test the script without having to point to real adsense ads.
Or, just click on the "ads by google" link at the border, this is allowed as it is not an ad.
Here we have the final drawback: For IE it would be possible to check, that the mouse click was done farther in the iframe, for Firefox there is no way to tell where in the iframe the click occured or if the beforeunload was even triggered by a click.
You can also position the mouse over the iframe and then press alt + <- to return to the page before. the js will still count it...
But thanks for the script, for me it was a good starting point to figure everything out.
Cheers
If we install third party adsense tracker softaware, is it violating google adsense TOS ?
As other commenters have noted the script does not work with the new 'ga' version of Google Analytics.
Is an updated version expected soon?
Doesn't work probably because like Storyman pointed out with the new "ga" version of Google Analytics.
I added code like 4 days ago and I can see clicks in adsense but not in analytics.
I got this code working with the new Google Analytics ("ga") with a minor update to the js.
Change the two places where it has:
urchinTracker ('/asclick');
to
pageTracker._trackPageview("/asclick");
Like other people have mentioned, Analytics is reporting more clicks than Adsense, but it's not horribly different.
yes oddsim this change works well
http://www.mediafire.com/?sharekey=73b3a89d92f64a7691b20cc0d07ba4d2cfb7e...
Installed yesterday with the script
on all my webpages
and today, have first results ;)
The code below used to work (I haven't tried it recently), for tracking which ads were clicked on. This exact code requires server side programming though to store the data. Hopefully, someone can integrate this with google analytics.
In the server side page, there will be two querystring vars passed: R = the current page, and U = the page the user clicked on.
function log() {
if (window.status.indexOf('go to') == 0)
{
adsenseimg = new Image();
adsenseimg.src = 'adsensetracker.php?R=' + document.location + '&U=' +
window.status.substring(6);
}
}
var elements;
elements = document.getElementsByTagName("iframe");
for (var i = 0; i < elements.length; i++) {
if(elements[i].src.indexOf('googlesyndication.com') > -1)
{
elements[i].onfocus = log;
}
}
This 3 year old blog post is still useful. God u rock...
great tip and there are other useful ones too like making it semi real-time 2 hr delay. I was particularly more interested in tracking a visitor page sequence and then bouncing.
This worked like a charm for me until I updated my GA code to track across subdomains. I can't get it to work now, not with or without this edit:
>> pageTracker._trackPageview("/asclick");
I think the problem seems to have something to do with the subdomains since that seems to make everything much harder, does anyone have a workaround for this?
... Google now provides click & revenues data by the page + keyword inside Google Analytics if you enable that data sharing across AdSense & Analytics?
Does anyone know if this script works for adsense ads delivered through DFP?
Thanks
...AdSense data in Google Analytics with integration directly in Google Analytics by linking the accounts.
It may not (and often does not) work with DforP by default, but if you use the old Google Analytics tags I believe it still does send data across.
If this tip saves you time and/or helps you make more money, please share some love with a good charity. :)
Hi Aaron!
Awesome code. I understand that we can see Adsense data in Analytics now, but it would be a huge benefit for some people to set Adsense clicks as goals under the "expirements" section of Analytics. Is there anyway to get this code working again so we could track that functionality?
Thank you,
Jessica
Hi, Araon
This script might be not working anymore, I tried but not getting any data in analytics!
I want to sure before i use :)
Add new comment