Forum Moderators: martinibuster
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?
Thanks
'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?
Thanks
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.
Also, the 'if (document.getElementById("google_ads_frame"))' statement allows the code to be inserted in all pages, as per scangwinnett's request, without throwing up a javascript error (I hope).
function in_adsense()
{
ad_focus = 1;
}
function out_adsense()
{
ad_focus = 0;
}
function log()
{
if (ad_focus == 1)
{
if (window.status.indexOf('go to') == 0)
{
bug = new Image();
bug.src = 'clicks.php?' + url_array[1] + '&dest=' + window.status.substring(6);
}
}
}
var ad_focus;
if (document.getElementById("google_ads_frame"))
{
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
<script language=javascript>function hit(){
window.focus();
if (window.status){
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;</script>
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!
Noel
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)
Noel
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.
Alternatively, stick around here for a bit. It won't be long until a very good .php script is hammered out on here in the same way the javascript was.
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.
TJ
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.
I bet there are a deluge of such scripts being built right now. I'm sure 99% of them will be posted up here. Open-source always produces the best material in the long run anyway - look at how the Javascript code got honed from an idea back on post 1 only a few days ago.
TJ
You will still need some way (.PHP, .ASP, .CGI, .CFM or maybe even VBS) to write the data from the javascript to the "text" file!
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#"
>
Noel
[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.
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!
ASA.
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).