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.

Google Analytics Goal.

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.

Google Analytics Source Conversion.

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".

Google Analytics Lifetime.

Click this and you see the Goal conversion for that item. For example here is the Coversion rate for DSL users.

Google Analytics DSL user conversion rate example.

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]

Published: November 21, 2005 by Aaron Wall in contextual advertising


February 22, 2007 - 2:25am

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?

December 14, 2005 - 11:50am

There is a tool to check that Google Analytics works on your web page before you see the results in your account. Just check Feel free to post your feedback!

June 3, 2006 - 8:42am

Thanks Aaron. Just installed the script and now I'll have to wait for some clicks to see what I can learn.

August 5, 2007 - 10:04pm

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:

July 12, 2006 - 12:21pm

Thanks for a great script. I make this script integrate with Google Analytics Plugin from 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

August 26, 2007 - 1:36pm


August 26, 2007 - 1:36pm


December 17, 2005 - 4:27pm


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 ?


May 15, 2007 - 8:13pm

I tried to put this script on my page and it didn't seem to work. Has Google somehow blocked this script?

aaron wall
December 17, 2005 - 4:31pm

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 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.

December 18, 2005 - 3:14am

Do Anyone Have An Idea About Google Analytics Will Freely Used By All The Sites And Blog Etc

December 13, 2006 - 1:59pm

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.

Ho Feng Wong
July 18, 2007 - 10:04am

This method doesn't work anymore? Am I right?

August 27, 2007 - 1:07am

Do you think google analytics is good for adsense?
no.Google will kill you!

November 10, 2006 - 1:02pm

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?

March 7, 2007 - 11:06pm

Thanks for the tip; I just set this up on my site. Let's see if it works!

February 2, 2006 - 9:15pm

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?


December 23, 2005 - 7:14am

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.

February 14, 2007 - 8:48pm

This is an awesome tool! I had no idea a tool like this existed.

April 17, 2006 - 12:01pm

I need invitation code for google analytics

August 13, 2007 - 12:31pm

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)..

July 8, 2007 - 8:40am

So where do I put this code it if my blog is hosted on blogger?

July 8, 2007 - 9:52am

So where do I put this code it if my blog is hosted on blogger?

February 22, 2007 - 10:01pm

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++) {

March 18, 2007 - 12:02pm

Is the script still working?

February 22, 2007 - 10:07pm

(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 &lt el.length; i++) {

New Blogger widget compatible code:
var j = el.length;
for( var i = 0; i &lt j; i++) {

Then inside function doPageExit(e)

Original code:
for (i=0; i &lt ad.length; i++) {

New Blogger widget compatible code:
var j = ad.length;
for( var i = 0; i &lt j; i++) {

August 13, 2007 - 5:04pm

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.

October 5, 2006 - 7:53pm

I just found an amazing FREE adsense tracker..

December 15, 2006 - 8:14am

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

January 2, 2006 - 8:33am

hey, can you make some code for chitika?

January 2, 2006 - 9:18am

This is awsome Aaron, you are the best! Thanks for sharing again...

November 12, 2006 - 7:44am

Added to my site. Seem to be working fine.

June 8, 2006 - 9:28am

There is another adsense tracking script with easy integration with Analytics - check Contextual Tracker( )

aaron wall
November 21, 2005 - 11:15am

someone just sent me this link
(removed, as per below comment)

A Reader
November 21, 2005 - 4:18pm

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

November 21, 2005 - 11:41pm

i get javascript error in IE with this ... error on line:

el[i].onfocus = urchinTracker('/asclick');

Permission denied

anyone else?

November 21, 2006 - 7:20pm

It works perfectly. The right solution. Very nice scripts. Thanks!

A Reader
November 21, 2005 - 11:45pm

Do you already have UrchinTracker on your site Bernis?

Utkarsh Kukreti
July 10, 2007 - 5:44am

Great Dude, Its Really Great, BTW U Should Have Not Removed URL Submission Box, Instead Moderated The Comments...

November 22, 2005 - 12:08am

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

karim tajik
May 17, 2007 - 2:29pm


great its a very nice web!!

keep iy up !!


November 22, 2005 - 4:36am

With this work with Yahoo ads?

April 3, 2006 - 5:51pm


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"?


April 3, 2006 - 5:59pm

Hi Malte
Yes you can publish this article in German.

November 22, 2005 - 5:43pm

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...

November 23, 2005 - 12:54pm


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! :)


March 11, 2007 - 6:14am

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.

November 23, 2005 - 11:43pm

Now how do we change it to track YPN clicks? :-P

November 24, 2005 - 12:43am

I have not tested it, but Shawn gave some YPN tips here
and here is what the current AdSense code would look like with YPN added
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.

March 23, 2006 - 2:55pm

It should be able to track the pages whoes ads was clicked by users; otherwise it is useless.

March 29, 2007 - 9:21am

May work if a insert ADSENSE into a DIV and I try to track DIV onclick with analytics like:

...adsense code...


July 18, 2006 - 8:33am

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

August 28, 2007 - 11:14pm

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.

November 25, 2005 - 10:39am

Still can't get it to work for YPN. The Adsense works GREAT though. The stats were perfect.

June 29, 2006 - 7:13pm

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? ..

February 8, 2007 - 9:57pm

Seems to work very well &'s easy to implement. - Great!

February 26, 2007 - 8:20pm

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.

Tony @

August 29, 2007 - 9:42pm

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...

November 30, 2005 - 11:44pm

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 and load thee astrack.js from his or even from :)

December 1, 2005 - 12:11am

I am not certain if it would work...It may, but

  • what happens when my host goes down
  • what happens if multiple people use that page on my site
  • what happens if some unscrupulous party sent your information their way


August 30, 2007 - 10:36am

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.

April 2, 2006 - 7:05am

Is this script is useful with blogs.

April 5, 2006 - 1:10am


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?

November 15, 2006 - 6:04am

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.

December 3, 2006 - 2:57am

Is this legal to use the script with adsense?

August 17, 2007 - 6:25am

i get javascript error

anyone can help?

December 3, 2006 - 6:24am

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.

October 27, 2006 - 7:21pm

It works and it works perfectly. The right solution. Free as well. Very nice. Thanks!

July 3, 2006 - 12:06pm

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.

February 11, 2007 - 11:09am

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?

May 11, 2006 - 1:26am


Where to put the file exactly? In the root dir? or in the dir where I have the file with the script included???

May 30, 2006 - 12:32pm

I need invitation code for google analytics too! Please! Who can help Me?

July 3, 2006 - 8:51pm

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.

May 14, 2006 - 2:38am

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.

October 17, 2006 - 11:57am

You can load the script into local computer with apache, then you get PSA. Are you allow to test clicks on PSA though?

October 17, 2006 - 12:05pm

You can load the script into local computer with apache, then you get PSA. Are you allow to test clicks on PSA though?

February 20, 2007 - 6:33pm

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?

March 3, 2006 - 2:46am

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.

March 3, 2006 - 6:06pm

ASClick stopped working for me, too.

It bombs for not just one, but all of my sites. I loved it, too. :(

March 3, 2006 - 7:01pm

It has stopped working for me and a friend as well. Google must have changed something.

December 12, 2006 - 8:13am

Thanks for this!

January 28, 2007 - 4:29am

frank, That sounds like regular Google Analytics tracking that can very easily be copied and pasted into your space. Visit

August 18, 2007 - 2:31pm

Is the tracker still working?

Are earnings displayed with this tracking tool?

March 5, 2006 - 2:36am

It stopped working on my site several weeks ago. It basically got worse and worse til it wasn't tracking anything.

March 5, 2006 - 8:30pm

Anybody handy enough with javascript to try and fix this? Is it fixable? Sounds like you would be a hero to many : )

July 26, 2006 - 1:39pm

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?

March 3, 2007 - 12:29am

Thanks very much for the script ;)

March 15, 2006 - 1:22am

does anybody know when the service starts over again?

April 9, 2006 - 8:59pm

Hi mate ! Just what I was looking for ! Works perfectly and performs all jobs very nicely ! Great addition, keep it up ! :)

A Reader
April 3, 2007 - 9:59pm

Once you have the GOOGLE ANALYTICS code, which section do you paste the code into on MySpace?

June 2, 2006 - 4:43pm

Does the usage of asclick.js violate Adsense terms?

August 5, 2007 - 4:47pm

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.

June 2, 2006 - 6:43pm

Not that I am aware of. In fact I think it is totally fine.

October 3, 2007 - 12:23pm

asclick is a very worthy thing to use for generating more qaulity statistics :)

Robert Joosen

October 3, 2007 - 7:23pm

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.


October 19, 2007 - 6:33am

Is this script still uptodate? I think in 2 years there are a lot of changes in browsers and in adsense.

October 24, 2007 - 9:43pm

Do you already have UrchinTracker on your site Bernis?

October 29, 2007 - 5:42pm

This is working great! Is there a way to also capture the value of the click?

October 29, 2007 - 6:48pm

Google does not share click value with publishers, so you can't really grab a value for that.

November 23, 2007 - 6:09am

Excellent addition to statisticans. Has started to use on Russian site
It would be excellent, if it is possible still $ for cliques to consider :-)

December 17, 2007 - 7:08pm

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.

January 31, 2008 - 4:18pm

This doesn't seem to work with GA's new js. Do we need to modify something in astrack.js?


February 22, 2008 - 8:40am

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?


February 27, 2008 - 11:16am


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 '' 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.


March 30, 2008 - 10:33am

If we install third party adsense tracker softaware, is it violating google adsense TOS ?

June 2, 2008 - 2:48am

As other commenters have noted the script does not work with the new 'ga' version of Google Analytics.

Is an updated version expected soon?

June 3, 2008 - 7:32am

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.

June 5, 2008 - 2:54pm

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');

Like other people have mentioned, Analytics is reporting more clicks than Adsense, but it's not horribly different.

January 17, 2009 - 10:52pm

yes oddsim this change works well

Installed yesterday with the script

on all my webpages

and today, have first results ;)

July 11, 2008 - 7:48pm

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=' +

var elements;
elements = document.getElementsByTagName("iframe");
for (var i = 0; i < elements.length; i++) {
if(elements[i].src.indexOf('') > -1)
elements[i].onfocus = log;


November 21, 2008 - 11:36pm

This 3 year old blog post is still useful. God u rock...

June 16, 2011 - 4:53pm

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.

April 3, 2012 - 6:09pm

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?

April 3, 2012 - 7:19pm

... Google now provides click & revenues data by the page + keyword inside Google Analytics if you enable that data sharing across AdSense & Analytics?

December 23, 2012 - 3:55pm

Does anyone know if this script works for adsense ads delivered through DFP?


December 24, 2012 - 9:13am

...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. :)

December 27, 2012 - 9:28pm

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,

chirag artani
November 30, 2018 - 12:05pm

Hi, Araon

This script might be not working anymore, I tried but not getting any data in analytics!

April 12, 2019 - 8:32pm

I want to sure before i use :)

Add new comment

(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.

Gain a Competitive Advantage Today

Your top competitors have been investing into their marketing strategy for years.

Now you can know exactly where they rank, pick off their best keywords, and track new opportunities as they emerge.

Explore the ranking profile of your competitors in Google and Bing today using SEMrush.

Enter a competing URL below to quickly gain access to their organic & paid search performance history - for free.

See where they rank & beat them!

  • Comprehensive competitive data: research performance across organic search, AdWords, Bing ads, video, display ads, and more.
  • Compare Across Channels: use someone's AdWords strategy to drive your SEO growth, or use their SEO strategy to invest in paid search.
  • Global footprint: Tracks Google results for 120+ million keywords in many languages across 28 markets
  • Historical data: since 2009, before Panda and Penguin existed, so you can look for historical penalties and other potential ranking issues.
  • Risk-free: Free trial & low price.
Your competitors, are researching your site

Find New Opportunities Today