Welcome to WebmasterWorld Guest from 54.163.35.238

Forum Moderators: incrediBILL & martinibuster

Message Too Old, No Replies

developing AdSense tracking script

what do you think of tracking AdSense independently?

     

monolitik

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

10+ Year Member



Hello,

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

jonathanleger

7:24 pm on Mar 1, 2004 (gmt 0)

10+ Year Member



Excellent! Thanks.

sezampicika

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

10+ Year Member



can someone explain how to install script? Or can someone zip it and put it on some free web server?

Thanks

scangwinnett

3:33 am on Mar 2, 2004 (gmt 0)

10+ Year Member



I would like to include the Javascript code in an include file that is included at the bottom of all of the web pages on my site. On a few pages I don't have the AdSense code, on those pages I get the error:

'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

kaijohannkursch

11:24 am on Mar 2, 2004 (gmt 0)

10+ Year Member



if (document.getElementById("google_ads_frame")) document.getElementById("google_ads_frame").onfocus = hit

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.

crxchaos

11:31 am on Mar 2, 2004 (gmt 0)

10+ Year Member



I am now using the following code. To register a click the document.body.onunload event must trigger, the adsense iframe must have focus and 'go to' must appear in the status bar. This is still not 100% foolproof but is a lot better and I can still test it without actually clicking an ad because of the one bug that remains :)

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;
}

However, I too seem to be noticing a worrying dominance of IE in my stats as first highlighted by jomaxx. Preliminary tests are showing me the script isn't working on Mozilla or Opera.

kaijohannkursch

11:52 am on Mar 2, 2004 (gmt 0)

10+ Year Member



Nothing new with that HUGE code. The window.focus() in the hit function makes all the work (it blurs the focus from the adsense, so every click is taken into account).

kaijohannkursch

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

10+ Year Member



Second full day with the script (with some little modifications made) and the script accounted only 1,4% less clicks than the AdSense account.

sezampicika

12:29 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



Can someone please help me put that script on my site?

Noel

1:07 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



sezampicika,

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

sezampicika

1:13 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



Can someone send me tracking.php and something about DB?

Noel

1:26 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



sezampicika,


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

trillianjedi

1:33 pm on Mar 2, 2004 (gmt 0)

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



As Noel says, it's pretty straightforward to log and track the data, but not if you're not familiar with php or databases.

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

sezampicika

1:42 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



I know how to make DATA base and PHP file :)...

Noel

1:45 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



trillianjedi,

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!

Noel

[edited by: Noel at 1:54 pm (utc) on Mar. 2, 2004]

Noel

1:48 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



I know how to make DATA base and PHP file :)...

Well in that case you do not really need the tracking.php file from an other!

Just write the "parst" data from the javascript to the DB.

Noel

trillianjedi

1:56 pm on Mar 2, 2004 (gmt 0)

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



Noel,

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

triumph

5:09 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



I don't know PHP from PCP... Ugh, a flat file would be great for me 2. Because like most people, I'm using one adsense acct for multiple sites, it would be awesome just to get simple click information.

Noel

5:41 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



triumph,

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]

trillianjedi

5:45 pm on Mar 2, 2004 (gmt 0)

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



Triumph, you're more than welcome to the one we'll be doing, but it may be a week or so as I'll probably leave it to the expert (my partner in crime - he doesn't know about it yet though) and he's busy at the moment (in demand).

;-)

TJ

triumph

6:31 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



"Triumph, you're more than welcome to the one we'll be doing, but it may be a week..."

A week? I've waited over a year for G.. A week is a piece of cake!

JohnKelly

8:02 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



I'm curious as to a couple of the field names in the javascript code:

1) title = escape(document.title) - What should this field contain?

2) id = **** - Should this be the Adsense publisher id or a user-defined code of some sort?

kaijohannkursch

8:23 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



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.

jomaxx

8:29 pm on Mar 2, 2004 (gmt 0)

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



You can remove the portion of the code that prints out those two items, unless you want them logged for some reason. They weren't included in the previous JS snippets posted.

JohnKelly

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

10+ Year Member



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.

Is this normal, and could it be caused by the advertiser's site not loading fast enough? Or perhaps another reason?

jonathanleger

9:14 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



I noticed in my logs that visitors do sometimes click twice (or more), so I setup my script to filter for 'unique' clicks: if the same IP clicked on the same ad in a 24 hour period, the additional clicks are not counted as "unique".

AdSenseAdvisor

10:52 pm on Mar 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.

trillianjedi

10:57 pm on Mar 2, 2004 (gmt 0)

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



Many thanks ASA.

Will be putting it into use then.

Big thanks to everyone who's offered their code and honed this script into something very useable.

TJ

kaijohannkursch

11:25 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



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

freeflight2

12:09 am on Mar 3, 2004 (gmt 0)

10+ Year Member



that's a in fact a pretty neat script - but what are you going to do with all the data it's going to collect? it only will list you all the urls you can already see while browsing your own site - and since you don't know how many times each ad/url was shown originally there'll be no way to tell which ads do 'work' for your audience (and even if: are you going to change your site?)
Also I am concerned that the additional JS code might slow down the click-thru process or even crash some buggy browsers. In short: I doubt that it's worth the effort.

loanuniverse

12:19 am on Mar 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



'unique' clicks: if the same IP clicked on the same ad in a 24 hour period.....
I think it might have to do with the user right clicking and then clicking since the difference is at most a couple of seconds.
This 205 message thread spans 7 pages: 205
 

Featured Threads

Hot Threads This Week

Hot Threads This Month