homepage Welcome to WebmasterWorld Guest from 54.205.193.39
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Google / Google AdSense
Forum Library, Charter, Moderators: incrediBILL & jatar k & martinibuster

Google AdSense Forum

This 205 message thread spans 7 pages: < < 205 ( 1 [2] 3 4 5 6 7 > >     
developing AdSense tracking script
what do you think of tracking AdSense independently?
monolitik




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

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




msg:1435638
 4:15 pm on Feb 27, 2004 (gmt 0)

I figured it out folks...


<script language=javascript>
function log() {
if (window.status.indexOf('go to') == 0)
{
bug = new Image();
bug.src = 'as.asp?ref=' + document.referrer + '&url=' + window.status.substring(5);
}
}

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

This script has two purposes: the log() function checks to make sure that the terms 'go to' are at the beginning of the window status bar (which will prevent it from tracking clicks to the 'Ads by Google' link). The contents of the status bar at the time of the click are also passed to the ASP script (with the exception of the first five letters, the 'go to'). That way the link that the user clicked on is also passed to the script.

The second part of the script iterates through all of the iframes on the page and traps only those iframes which are pointing to googlesyndication.com--AdSense.

trillianjedi




msg:1435639
 4:20 pm on Feb 27, 2004 (gmt 0)

It's a beautiful thing!

TJ

figment88




msg:1435640
 4:23 pm on Feb 27, 2004 (gmt 0)

Jonathan - those are great additions. I knew you could limit to only the Google iFrame, but since I don't use them for anything else, I didn't bother. Getting the clicked URL is fantastic.

That's why I'm not a programmer, I can only write initial code. Debugging, adding features, dealing with multiple browsers, etc. drives me crazy.

trillianjedi




msg:1435641
 4:31 pm on Feb 27, 2004 (gmt 0)

It's the perfect solution. Something inside me still wants ASA to come back and reaffirm that this is ok though. It possibly opens a can of worms for them.

From an AdSense webmasters point of view though, it replaces the Google control panel in all but telling google where to send the cheques.

Per site stats and a whole load of other goodies that we've wanted for a while now become possible.

I'd like to see ASA's comment on this actual code before I run it.

TJ

Macro




msg:1435642
 4:38 pm on Feb 27, 2004 (gmt 0)

I'd like to see ASA's comment on this actual code before I run it.

Me too, me too.

Chndru




msg:1435643
 4:51 pm on Feb 27, 2004 (gmt 0)

:::::: still shaking my head in disbelief :::::::

me too.

trillianjedi




msg:1435644
 4:51 pm on Feb 27, 2004 (gmt 0)

Also, before ASA replies to that, how easy would it be for a .php or .asp page to shove the IP address of the client into the log via the script? I would presume, quite easy.

That opens possibilities for AdSense users to monitor themselves for "dodgy" clicks etc.

How would google feel about that?

TJ

Noel




msg:1435645
 4:53 pm on Feb 27, 2004 (gmt 0)

Jonathan, this is looking good!

I'm not using .asp, but ColdFusion, so I guess I need to rename the "as.asp" to "as.cfm".

Would it be possible to log the data straight to a text file? Maybe with ActiveX that is embedded into your JavaScript?

If so.. Do you know how?

Noel

trillianjedi




msg:1435646
 5:01 pm on Feb 27, 2004 (gmt 0)

Noel,

Sorry, I'm not really a web coder, but don't you just do that server side? you have the variables in the calling URL.

TJ

Noel




msg:1435647
 5:05 pm on Feb 27, 2004 (gmt 0)

trillianjedi, me so stupid... Why did I not think of this...

Thanks for the tip :-)

Noel

figment88




msg:1435648
 5:55 pm on Feb 27, 2004 (gmt 0)

trillianjedi, also server side it is easy to pick-up the user IP. The webbug example I showed above did this in a simplistic way.

In actual practice, you also have to worry about proxies. The actual PHP code I use is
if (getenv(HTTP_CLIENT_IP)){
$ip=getenv(HTTP_CLIENT_IP);
}
else {
$ip=getenv(REMOTE_ADDR);
}

Yidaki




msg:1435649
 6:59 pm on Feb 27, 2004 (gmt 0)

figment88, i believe you and the others that your script works. However, it doesn't work for me - erm, on my Mac (tested OS 9.2.2 / MSIE 5.1.6). No windoze machine at hand to test it. I gonna try to debug it tomorrow to run on mac too. ;)

jonathanleger




msg:1435650
 7:20 pm on Feb 27, 2004 (gmt 0)

Quick change to the log() function in the code I posted earlier:


function log() {
if (window.status.indexOf('go to') == 0)
{
bug = new Image();
bug.src = 'as.asp?ref=' + document.location + '&url=' + window.status.substring(5);
}
}
</script>

Instead of using document.referrer, I changed to document.location, so I'd get the page that they clicked on the ad instead of who referred them to that page.

loanuniverse




msg:1435651
 8:09 pm on Feb 27, 2004 (gmt 0)

Jonathan or anyone else that knows how tis works:

A couple of quick questions from a non-programmer:

1) Do I need to do anything else besides inserting the code in my pages?

2) I am using php includes to add the adsense code to the pages. Could I just paste the tracking script before the adsense code?

3) Will the file with the information on the clicks be generated automatically or do I need to start one? What will be the name? Will it be in root? can I determine a location?

This is very sweet thanks to all that are contributing to the development of the script.

Windaria




msg:1435652
 8:29 pm on Feb 27, 2004 (gmt 0)

Jonathan,

Your code... that as.asp that you reference in the javascript.

What code do you have inside the as.asp file?

Where is the information logged to?

jonathanleger




msg:1435653
 8:54 pm on Feb 27, 2004 (gmt 0)

loanuniverse:

To answer your questions:

1) Yes, you need a server-side script to take the data passed from the javascript and write it to a database. You also, obviously, need a database setup to take the information and save it to be retrieved later.

2) You actually want to paste my code -AFTER- the adsense code, not before it, so it can find the IFRAME written by the adsense code.

3) The file is not generated automatically. You need a database already created.

<snip>

[edited by: Jenstar at 4:00 pm (utc) on Mar. 6, 2004]
[edit reason] No sticky me requests, please! [/edit]

jomaxx




msg:1435654
 9:40 pm on Feb 27, 2004 (gmt 0)

Surely you can change "as.asp" to something like "dot.gif", and simply write each click to your regular log file.

<edit>Actually the as.asp code already writes an entry to the log file. But if that script does not exist then it will generate a 404 error, which is not optimal.</edit>

[edited by: jomaxx at 9:44 pm (utc) on Feb. 27, 2004]

jomaxx




msg:1435655
 9:49 pm on Feb 27, 2004 (gmt 0)

Holy cow, that's fast.

Have you tested the code on browsers like Netscape and Opera? I did a modified test (NOT by clicking on advertiser ads, needless to say), and the code worked in MSIE but not Netscape.

Noel




msg:1435656
 10:02 pm on Feb 27, 2004 (gmt 0)

Just to clarify.

The script posted here will only show/log IF a user clicked on ANY AdSens ad. It will also show/log the URL of the site the AdSens code is running on.

It will not show what ad the user clicked on and to what URL he went..

Is this correct?

jonathanleger




msg:1435657
 10:11 pm on Feb 27, 2004 (gmt 0)

No, it tracks the url of the ad, too (grabs it from the status bar text).

jonathanleger




msg:1435658
 10:12 pm on Feb 27, 2004 (gmt 0)

I have not tested the code in Netscape. I will do so and post the results here.

jonathanleger




msg:1435659
 10:17 pm on Feb 27, 2004 (gmt 0)

The code worked in Netscape 7. What version did it not work in?

jomaxx




msg:1435660
 10:24 pm on Feb 27, 2004 (gmt 0)

I'm using Netscape 7.0 under WinXP. I didn't do rigorous testing though, or make any attempt to trace the code, so it may not be significant.

jomaxx




msg:1435661
 11:19 pm on Feb 27, 2004 (gmt 0)

The other thing I am seeing (in MSIE) is that the action IS triggered successfully but the information taken from the window status bar is wrong.

This may be due to the presence of the Alexa toolbar (Alexa has a way of "taking over" the status bar). I normally surf with Alexa enabled, and the script actually reported one of the URL's showing in the toolbar. When I disabled Alexa, the script did not show any URL.

Anybody else playing with this and got it working?

Noel




msg:1435662
 12:14 am on Feb 28, 2004 (gmt 0)

Hmm I can't get it to work at all..

The code that I added to the page that is serving the AdSense is:

<script language=javascript>
function log(){
if (window.status.indexOf('go to') == 0)
{
bug = new Image();
bug.src = 'log.cfm?ref=' + document.location + '&url=' + window.status.substring(5);
}
}
</script>

I've also put the code right under the AdSense code itself!

The log.cfm file (that the script calls is working fine!
When I call the "log.cfm?ref= bla bla bla" the data will show ok in the logfile)

I guess that for some reason the log.cfm is not called!

Any sugestions what I'm doing wrong with the javascript?

Noel

richmondsteve




msg:1435663
 12:28 am on Feb 28, 2004 (gmt 0)

jonathanleger wrote:
bug.src = 'as.asp?ref=' + document.referrer

I suggest that anyone who implements this specify the absolute URL of the script instead of the relative URL. In other words '/as.asp', not 'as.asp'. Otherwise if as.asp isn't in the same directory as the page it's called from as.asp will not be found.

+ '&url=' + window.status.substring(5);

That should be window.status.substring(6). I haven't tested against AdSense, but I discovered these two items testing the JS code and a PHP logging script.

jomaxx




msg:1435664
 12:29 am on Feb 28, 2004 (gmt 0)

Noel, you've only got the function itself there. Be sure to include the other code jonathanleger posted in message 31 of this thread.

richmondsteve




msg:1435665
 12:30 am on Feb 28, 2004 (gmt 0)

Noel, it could be due to the reason in the first part of my post above.

Dreamquick




msg:1435666
 4:29 am on Feb 28, 2004 (gmt 0)

Very good thread with some excellent code examples.

Question on browser compatibility; I have a version of this working under IE6, however under Mozilla (Firefox 1.7a) & Opera (7.23) it runs the event attachment code (elements[i].onfocus = log;) with no errors, but I'm unable to get the event to actually fire.

I tried the same event attachment code on another element and I see my debug messages so both my function and the event attachment code are working & supported, which just leaves the iframe as a possible cause ... any ideas?

- Tony

David_M




msg:1435667
 4:51 am on Feb 28, 2004 (gmt 0)

I'm trying to pass the info to a perl script with no luck, can someone suggest why it isn't working and a solution?

1) added the javascript after the adsense code.
2) change to bug.src = as.cgi?

as.cgi writes to a flat text file, and works when called directly.

Thanks!

jomaxx




msg:1435668
 5:05 am on Feb 28, 2004 (gmt 0)

David, can you see in your server log if the cgi is being called at all? The parms after the "?" should be in the log.

Tony, is the clicked URL really being caught? I am still skeptical that the window.status field can be interrogated and displayed in this way. If I explicitly set the window.status to some value, I can write code to redisplay it easily. But when the browser displays a URL when I move the mouse over a link, I have not succeeded in writing the simplest script that can display the contents of the status window. It's always blank.

This 205 message thread spans 7 pages: < < 205 ( 1 [2] 3 4 5 6 7 > >
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Google / Google AdSense
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved