Welcome to WebmasterWorld Guest from

Forum Moderators: incrediBILL & martinibuster

Message Too Old, No Replies

developing AdSense tracking script

what do you think of tracking AdSense independently?



9:44 am on Feb 25, 2004 (gmt 0)

10+ Year Member


I have seen posts that wish detailed AdSense reports such as site level or page level stats.

Currently, we are working on a script to track AdSense impressions and clicks. The script lets you track the stats of sites, pages, referrers, color combinations, ad formats, visitor countries, paid or alternate ads displayed etc.

To remove questions, it conforms to Google TOC completely. No change to AdSense code, no interference.

I want to know your opinions on tracking AdSense independently. Do you personally want to use such a script? What features would you expect?



4:35 pm on Mar 4, 2004 (gmt 0)

10+ Year Member

Today I have seen an example of the same IP address clicking on the same ad from the same page 37 times in a period of less than a minute. I've asked Google AdSense how they would interpret a pattern like that. What do you think?

Dan Grossman

4:51 pm on Mar 4, 2004 (gmt 0)

10+ Year Member

I would hope their software would automatically throw those clicks out without even requiring human intervention.


5:43 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

i think they'll call that click fraud. naturally, i also believe they should just throw it out and ignore it, but just from the past posts here, it sounds like they tend to lean more towards punishment than merely filtering out these things. hope i'm wrong in your case.


5:52 pm on Mar 4, 2004 (gmt 0)

10+ Year Member

Saying what Google will do in such a situation is very speculative. IIRC, europeforvisitors' site was the victim of a massive AdSense click attack one day and he's still an AdSense publisher. EFV, can you refresh our memory on the extent of the click fraud and how you and Google handled it?

Also, depending on what JS script you're using I want to remind everyone that the scripts have the potential to record actions as clicks when they aren't clicks. I'm talking about right-clicking, dragging without releasing the mouse button, etc. that some of us mentioned early in this thread. I'm not saying that someone came and right-clicked an ad 37 times in one minute, but it's possible and only Google would have the data to verify or eliminate.


6:01 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member jomaxx is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Double-clicking is reasonably common, especially among people who don't use the Web that often. Even multiple clicks are very likely if the site doesn't respond within a couple of seconds. Overture filters out these clicks easily, and Google probably does as well.

Even clicking 37 times, by itself, is probably no big deal. The fact that it was observed it within a couple of days of a relatively small number of people starting to track their clicks suggests that it must occur frequently.


4:22 am on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Here's a quick Perl / CGI script to log the output from the tracking JavaScript. The script runs in two "modes";

- logging (default, saves output of javascript)
- reporting (creates HTML table of data)

(see comments in code for how to specify mode)

To use the script follow these steps-

1. copy and paste this script to a text editor and save the file as 'tracklix.cgi'

2. change value "YOURTRACKINGSCRIPT" to in the JavaScript to-


(or wherever you keep your CGI scripts)

3. upload the file to your CGI bin (FTP/ASCII mode)

4. CHMOD 755 the file (-rwxr-xr-x)

Next ad click will create a file "tracklix.db" in the same directory as the script (you can change the path once you get to know the script).

NOTE: This file creates a simple ASCII 'pipe delimited' file, which will grow quickly... it should probably have some method for daily archiving, (and a million other features)... but I gotta go earn a living... <grin>

#!/usr/local/bin/perl -w
# ===========================================
# TRACKLIX.CGI (c)rmh 2004
# ===========================================
# *** FREEWARE *** Released to public.
# Set some parameters (if you want to).
# Data is displayed on alternating row
# background colors pick two new ones
# if you like.
$DATA_bgcolor_1 = "#F4F4F4";
$DATA_bgcolor_2 = "#E0F4F4";
# data is output to ASCII (pipe delimited)
# database file. Next line puts it where
# you want it.
$datafile = "tracklix.db";
# if your date command is different, change this too.
$dateCmd = '/bin/date';
# with nothing but the parameters from the JavaScript,
# this Perl code wil just write it to disk, BUT...
# call this script with '?f_mode=RPT1' ie-
# /cgi-bin/tracklix.cgi?f_mode=RPT1
# and it prints a report! (everything in the log)
# this is for testing and then modify the code to
# use whatever DB you're comfortable with that
# can handle the share / lock needs, etc..
use CGI;
$query = new CGI;
$f_ref = ($query->param("ref"));
$f_url = ($query->param("url"));
$f_w = ($query->param("w"));
$f_h = ($query->param("h"));
$f_f = ($query->param("f"));
$f_cb = ($query->param("cb"));
$f_cbg = ($query->param("cbg"));
$f_cl = ($query->param("cl"));
$f_cu = ($query->param("cu"));
$f_ct = ($query->param("ct"));
$f_mode = uc($query->param("f_mode"));
if ($f_mode eq "") {
chop ($DateStamp = `$dateCmd +"%Y%m%d"`);
$rec = join ( "\", $DateStamp, $f_ref, $f_url, $f_w, $f_h, $f_f, $f_cb, $f_cbg, $f_cl, $f_cu, $f_ct );
open (RAW,">>$datafile");
printf (RAW "$rec\n");
close (RAW);

} elsif ($f_mode eq "RPT1") { # report #1, list all
print "Content-type: text/html\n\n";
print "<html>\n\n<head>\n<title>Ad / Click Tracking Report</title>\n</head>\n\n<body>\n";
$flipper = "0";
print "<TABLE border=\"1\" cellspacing=\"0\"cellpadding=\"2\" width=\"100%\">\n";
open (DAT,"$datafile") ;
seek (DAT,0,0);
while ($rec = <DAT>) {
@rec = split (/\/,$rec);
if ($flipper eq "0") { $bg = $DATA_bgcolor_1; $flipper = "1";} else {$bg = $DATA_bgcolor_2;$flipper = "0";}
print "<TR bgcolor=\"$bg\"><TD>$rec[0]</TD><TD>$rec[1]</TD><TD>$rec[2]</TD><TD>$rec[3]</TD><TD>$rec[4]</TD><TD>$rec[5]</TD><TD>$rec[6]</TD><TD>$rec[7]</TD><TD>$rec[8]</TD><TD>$rec[9]</TD></TR>\n";
print "</TABLE>\n";
print "</body>\n";
print "</html>\n";
# ==================
# end of script
# ==================


4:34 am on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Just noticed a closing curly bracket out of place.. the last one (after the </TABLE> tag) needs to be moved to just below the </HTML> tag line or the script will output the </BODY> and </HTML> tags during logging.. works anyway, but should be fixed.

print "</TABLE>\n";
} <----- move this
print "</body>\n";
print "</html>\n";
<----- to here
# ==================
# end of script
# ==================


6:25 pm on Mar 5, 2004 (gmt 0)

10+ Year Member

Hi, I tried to run teh vbs file, and i get this:

Line: 157
Char: 1
Error: Wrong number of arguements or invalid property assignment: 'year'
Code: 800A01C2
Source: Microsoft VBScript runtime error.

Anyone knows what's wrong? thank you.

too much information

6:52 pm on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I don't know what problems you are having with VBScript but here's what I'm using:

':::: Record Visit in Log File

':: Open Log File
dim aslg, logFile8
set aslg=createObject("scripting.FileSystemObject")
set asLog=aslg.openTextFile(server.mappath("NAME-OF-YOUR-FILE.txt"),8,True)

':: Record Date and Time of Visit
asLog.write date & "," & time & chr(9)

':: Record IP Address of Visitor
asLog.write Request.ServerVariables("Remote_Addr") & chr(9)

':: Record Users OS Type
if Instr(Request.ServerVariables("HTTP_USER_AGENT"), "Mac") then
asLog.write "Mac User" & chr(9)
elseif Instr(Request.ServerVariables("HTTP_USER_AGENT"), "Win") then
asLog.write "Windows" & chr(9)
elseif Instr(Request.ServerVariables("HTTP_USER_AGENT"), "Linux") then
asLog.write "Linux" & chr(9)
asLog.write "Other" & chr(9)
end if

':: Record Browser Type
asLog.write Request.ServerVariables("HTTP_USER_AGENT") & chr(9)

':: Record Referrer for Visit
if Request.ServerVariables("HTTP_REFERER") = "" then
asLog.write "Not Refered" & chr(9)
asLog.write Request.ServerVariables("HTTP_REFERER") & chr(9)
end if

':: Record This Page Name
asLog.write Request.Querystring("ref") & chr(9)

':: Record The Ad Destination
asLog.write Request.Querystring("url")

':: End line for this Record
asLog.write vbcrlf

':: Close Log File
set asLog=nothing
set aslg=nothing

':::: Done Recording Visit

you will have to set your read/write permissions on your text file and be sure not to make the text file available on the web.

It is a fairly simple format to follow incase you want to add more details to your log, this is just what I wanted to begin with.


9:13 pm on Mar 5, 2004 (gmt 0)

10+ Year Member


I had the same problem with that vbs script!

I've emaild monitorman about this, and he told me to change line 157 to:

TheCurrentDate = Day(AdjustedTime) & ", " & Year(AdjustedTime)

After I changed it, it fixed that error, but now I'm getting a new error at line: 212

Still trying to fix that!



7:26 pm on Mar 7, 2004 (gmt 0)

10+ Year Member

I have had a play with jonathanleger's AdSense tracking script and everything seems to be working well.

However some webmasters including myself have notice multiple clicks from the same IP on the same ad with in a matter of seconds. I managed to repeat the problem by clicking on an ad (first click), then hitting the back button where a second click was logged. It seems that if the status bar contains the relevant text then a click is logged. Is their any work around for this? Maybe clear the status bar on page load or something? I don't know Javascript so I have no idea...


1:28 am on Mar 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Just curious, does this kind of 'external javascript tracker' slow URL direct performance when a visitor clicks on a Adsense link?



10:06 pm on Mar 9, 2004 (gmt 0)

10+ Year Member

Here's a workaround for the issue of duplicate clicks. This version of the log() function checks to see if the last clicked ad is the same as the ad being clicked currently. If it is, the click is not logged.

var lastStatus = '';

function aslog(e) {
if (window.status && (window.status!= lastStatus))
lastStatus = window.status;
var bug = new Image();
bug.src = 'YOURSCRIPT?ref=' + escape(document.location.href) +
'&url=' + escape(window.status);


11:10 pm on Mar 11, 2004 (gmt 0)

10+ Year Member

It has been a while since I started this topic. As I said in a previous post, unfortunately I had to travel for 15 days without going online much. By the time, I saw that the community developped its own version of the tracking script. Good work.

Well, if you are interested, our solution is now ready on the web. You can reach it through my profile (I think) and download the free evaluation copy.
We prefer contacting us directly if you need to ask or tell something about the script, instead of posting here.

Thank you all.


1:01 am on Mar 12, 2004 (gmt 0)

10+ Year Member

Monolitik I can't see a URL in your profile....


1:59 am on Mar 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

>>IIRC, europeforvisitors' site was the victim of a massive AdSense click attack one day and he's still an AdSense publisher. EFV, can you refresh our memory on the extent of the click fraud and how you and Google handled it? <<

I'd like to hear more about this EFV.


6:14 pm on Mar 12, 2004 (gmt 0)

10+ Year Member

I have a question about Dan's tracker script.

It turns out that javascript generated is not remotely compliant.
Line 120, column 67: cannot generate system identifier for general entity "SectionID" /tracker/tracker.php?SiteID=5&SectionID=1&SetID=3&page=' + escape(docu
Line 120, column 67: general entity "SectionID" not defined and no default entity (explain...). /tracker/tracker.php?SiteID=5&SectionID=1&SetID=3&page=' + escape(docu
Line 120, column 76: reference not terminated by REFC delimiter /tracker.php?SiteID=5&SectionID=1&SetID=3&page=' + escape(document.loca

And on an on. How do I fix this? Is it just a matter of escaping the & or is something else the problem. My pages were XHTML 1.0 compliant before I added this code, and I'd like to keep them that way.


12:44 am on Mar 14, 2004 (gmt 0)

10+ Year Member

Since the onFocus event handler doesn't seem to work in Mozilla, did anybody try to use addEventListener('click', log, false) to do the same for Mozilla?

I think that should work, but I didn't get it right, yet.


10:04 am on Mar 14, 2004 (gmt 0)

10+ Year Member

Great Job Everyone...

About the time you all get this code perfected
Google will have a killer stats package...


1:27 pm on Mar 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I was able to log clicks on Moz and Opera but I cannot seem to capture the window.status. Pretty useless w/out that.


3:23 pm on Mar 15, 2004 (gmt 0)

10+ Year Member

It seems to me that all of these tracking scripts use onFocus to check for the click on the iFrame. Doesnt onfocus also get called when the user uses the tab key to the tab through the iframe? Can this be the reason for the multiple clicks people are seeing? This can register a 'hit' in the tracking script although the user never clicked on the iframe. Does this make sense to anyone else? Is there a better way to check for the click on the iframe (onClick, etc)?



4:56 pm on Mar 15, 2004 (gmt 0)

10+ Year Member

ari11210, did I see the same post from you in 3 or 4 threads or is my mind just playing tricks on me today?


5:35 pm on Mar 15, 2004 (gmt 0)

WebmasterWorld Senior Member jomaxx is a WebmasterWorld Top Contributor of All Time 10+ Year Member

No, your mind isn't playing tricks on you. For some reason the issue is so urgent it had to go into every thread.


6:44 pm on Mar 15, 2004 (gmt 0)

10+ Year Member

First, my apologies for posting my message multiple times.
Second, I was wondering if anyone else had the same issue I was having. I was seeing that only the first click on an ad was getting logged, subsequent clicks were not. It seems that the 'image' was getting cached somewhere and was therefore not getting called the second time, etc. I had to add the current time (new Date.valueOf()) to the parameter string in the URL to get around the caching. Did anyone else have this issue? If you did, this should fix it.



4:40 pm on Mar 19, 2004 (gmt 0)

10+ Year Member

Hi all.
firstly thanks to all for writing these great free tracking scripts.
monolitik: I looked at your script and liked it. Now that google has released there own tracking and Dans script is totaly free, are you going to drop the upgrade cost?

I also noticed that information is being sent back to your own server each time I use this script.

I am no programmer but I would like to know what info is being asked for and why you would want this information.

Is this a case of tracking the trackers?

I have now taken this code off my server and happy to use Dans free tracking program.

Whilst the google tracking feature is a good start, I do like to know in real time what is happening and not wait 8, 12, 24 hours to see what is working and what is not. The guessing of which ad is also brillient.
Thanks Dan!
If anyone has a different script, please let me know.

This 205 message thread spans 7 pages: 205

Featured Threads

Hot Threads This Week

Hot Threads This Month