Welcome to WebmasterWorld Guest from 220.127.116.11
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?
'document.getElementById(...)' is null or not an object
regarding the line:
document.getElementById("google_ads_frame").onfocus = hit;
(using kaijohannkursch's version of the JS code).
What's the syntax of the if statement I need to put around this statement so that it isn't called when the google_ads_frame doesn't exist on the page?
But if you are able to choose what pages contain the code and what not... you could include the code only in pages with AdSense. In addition, is strongly recommended inserting the code JUST after the adsense code. If not, some clics will not count.
All the AdSense variables are passed to my click counter script as suggested by kaijohannkursch.
ad_focus = 1;
ad_focus = 0;
if (ad_focus == 1)
if (window.status.indexOf('go to') == 0)
bug = new Image();
bug.src = 'clicks.php?' + url_array + '&dest=' + window.status.substring(6);
url_array = document.getElementById("google_ads_frame").src.split("?");
document.getElementById("google_ads_frame").onfocus = in_adsense;
document.getElementById("google_ads_frame").onblur = out_adsense;
document.body.onunload = log;
it's not the script that is the "hard" part!
All you need to do is copy the following text and put it under the AdSense code
img = new Image();
img.src = 'http://domain.com/tracking.php?ref=' + escape(document.location) + '&title=' + escape(document.title) + '&ad=' + escape(window.status) + '&id=****';
document.getElementById("google_ads_frame").onfocus = hit;
The "hard" part for you I think? will be the logging part in tracking.php
So you will need to make a tracking.php page that will write the "ref", "title" and "ad" data to a DB.
You will also need some way to read the DB again!
Can someone send me tracking.php and something about DB?
The tracking.php will be a custom made file that will access the DB (database), so I'm not sure if it will help you if someone sends you his tracking.php file!
You will also need to setup the database yourself! (that is if you want to log the data to a database)
You may have to do a little learning. In a nutshell, it's as simple as collecting the logged data, analysing it, bit of trial and error for correcting false right-clicks etc (if necessary) and then a little web page to display the DB info in a meaningful fashion.
Try some of the "learn php and mySQL" type sites.
I don't think I'll be doing this via a DB, but simply through a text based log file, in the same way that most of the stats software do it for website logfiles.
We don't really need queries for what we're doing, just the stats.
I love to use queries on my DB's. You can do so many nice things with it :-)
With one small query I can sort by IP, Ad, Ref or any other data that I log!
That's why I'm loggin my AdSense data to a DB!
[edited by: Noel at 1:54 pm (utc) on Mar. 2, 2004]
I agree - very powerful stuff DB's - I've done some really useful things with them myself. Don't get me wrong, I was only saying that for the particular purpose we have in mind for using this AdSense script, a flat text file would be sufficient. I just need the clicks logged and displayed in simple fashion (I already have a picture in my head of what I need).
As I think I stated before in an earlier post, I think a lot of .php, database, flat text file etc ideas will come out of this thread over the next week or so. There's always more than one way to skin a cat - having lots of options is not a bad thing.
In ColdFusion (CFM) the "tracking" file would need something like the following code to append to a text file.
<cffile action = "append"
file = "C:\log\adsense.txt"
output = "#ref# #title# #ad#"
[edited by: Noel at 5:56 pm (utc) on Mar. 2, 2004]
title = escape(document.title) - What should this field contain?
Obviously the title of the document, for better file recognising (think for instance in this forum urls: [webmasterworld.com...] does not tell much about the content).
id = **** - Should this be the Adsense publisher id or a user-defined code of some sort?
A user-defined identificator to identify different ad styles or whatever.
Is this normal, and could it be caused by the advertiser's site not loading fast enough? Or perhaps another reason?
Something inside me (gut instinct) still wants this revisited by ASA though.
I think that the initial request has been buried behind all these great improvements to the code, but I wanted to confirm that this concept is indeed in line with the Terms and Conditions. I would suggest that, if you're passing your confidential information to a third party for logging, you make sure to use due diligence in selecting and trusting such a party.
This forum really is a great place for cooperation and information transfer!
Neat script! I tried it out, but notice that I'm getting repeat clicks in some case to the same ads, often within a few seconds of each other
Of course server side applications need to filter clicks in some way. I filtered out clicks from the same ip on the same ad in the same hour, and I am very happy with the results.
if you're passing your confidential information to a third party for logging...
Yes, that is a problem for hosted scripts. In addition scripts installed in own servers will have a better performance (lighter databases) and a better execution time (no external script is required).