Forum Moderators: martinibuster

Message Too Old, No Replies

AdSense Tracking Script within the TOS

         

Tonearm

5:16 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Has anyone had any success with the tracking discussed here:

[webmasterworld.com...]

The length of the thread, its age, and my non-existant expertise in Javascript are keeping me from being able to draw any conclusions. It sounds useful.

- Grant

Noel

6:44 pm on Jan 12, 2005 (gmt 0)

10+ Year Member



Yes it does work. I'm using a "custom" made one!

You will need to add some code to the page that is running your Adsense code, and you will need to make a page that will "trap/log" the click!

The code that is needed on the page with your Adsense code is no problem.

What might be a problem (for you?) is the "trap/log" page!
This you will need to "custom" make

My sites are all running on a Coldfusion server. I've coded the "trap/log" page so that it will log the click to a database, and that it will also send me an email :-)

This can also be coded in any other server-side scripting languages.

Noel

Tonearm

7:02 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Really!

I can code up a storm, but not in javascript. Can you tell me a little more about how it works and what data you end up with from it? Is custom javascript required?

- Grant

ari11210

8:10 pm on Jan 12, 2005 (gmt 0)

10+ Year Member



This is the javascript code I use. You can simplify it, but I track which of the 3 ad units the click was on as well, so that complicates it. Note, that I also tack on the current time to the tracking - otherwise I had issues with the click not registering due to the browsers caching. The script tells me what ad was clicked, on what page, and which of the 3 ad units were clicked. Also, I have some extra code in there to check if there is an anchor (#) in the URL - which it strips off when tracking the page name. My adsenseTo.php page is a php page that takes the information and puts it in a database. Good luck!

<script type="text/javascript">
var HASH_ESCAPED="%23";
function TrackIt(adUnit)
{
if (window.status)
{
var adDomain = escape(window.status.substring(6));
var pyPage = document.location.pathname;
var params = document.location.search;
var hasAnchor = params.lastIndexOf(HASH_ESCAPED)!= -1;
params = hasAnchor? (params.substring(0, params.lastIndexOf(HASH_ESCAPED))) : params;
pyPage = escape(pyPage.substring(pyPage.lastIndexOf('/') + 1));
pyPage = pyPage + params;
var curTime = new Date().valueOf();
var bug = new Image();
bug.src = 'adsenseTo.php?pyPage=' + pyPage + '&adDomain=' + adDomain + '&adUnit=' + adUnit + "&time=" + curTime;
}
}
function TrackIt0() {TrackIt(0); }
function TrackIt1() {TrackIt(1); }
function TrackIt2() {TrackIt(2); }
var elements = document.getElementsByTagName("iframe");
for (var i = 0; i < elements.length; i++)
{
if(elements[i].src.indexOf('googlesyndication.com') > -1)
{
//elements[i].onfocus = TrackIt;
if (i==0) elements[i].onfocus = TrackIt0;
if (i==1) elements[i].onfocus = TrackIt1;
if (i==2) elements[i].onfocus = TrackIt2;
}
}
</script>

Tonearm

8:32 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alright! Thanks a lot! Can that code go at the very bottom of the page? Are there any downsides? I'm going to work on this tonight.

Does everyone use something like this? It sounds extremely useful.

- Grant

Noel

10:29 pm on Jan 12, 2005 (gmt 0)

10+ Year Member



Alright! Thanks a lot! Can that code go at the very bottom of the page? Are there any downsides? I'm going to work on this tonight.
Does everyone use something like this? It sounds extremely useful.

- Grant

Not sure who is using it, but it's been very useful for me.

There are (for me) two downsides.

1) The code will not work with every browser! If a Netscape user clicks on an add the click will not be loged. (Adsense will still get the click)

2) If a user right clicks on an add it will show as a click for you. (Not for Adsense)

Noel

ari11210

2:33 am on Jan 13, 2005 (gmt 0)

10+ Year Member



I think you should put the code on the bottom of the page (or after the 3 ads) to be sure. As far as the right-click, I guess that could be corrected with some more javascript. Also, why dont you think it will work in Netscape?

Thanks
Aaron

UnnamedPlayer

4:47 pm on Jan 14, 2005 (gmt 0)

10+ Year Member



Hi all, this is my first post here :P

I'm also writing an AdSense tracking script but I can't find the way for it to work on Firefox (haven't tested it with Netscape, but it could have the same problem).

In Firefox the onfocus event of the iframe doesn't fire when you click inside the iframe but only when you click in the iframe border so it will not track the clicks on the ads.

Did anyone get something that works in all browsers? Any help would be appreciated :)

Sergio

Noel

9:17 pm on Jan 14, 2005 (gmt 0)

10+ Year Member




In Firefox the onfocus event of the iframe doesn't fire when you click inside the iframe but only when you click in the iframe border so it will not track the clicks on the ads.

Same problem with Netscape. I've been looking arround for a fix on the "onfocus" problem, but till now no luck.

I think the problem is with all the "Mozilla" type browsers.

Noel

amznVibe

4:52 am on Jan 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Has anyone looked at the old suggestion for making the script work with Mozilla/Firefox?

[webmasterworld.com...]

elements[i].contentWindow.onfocus = log;
Instead of :
elements[i].onfocus = log;

I've tinkered with it but to little success.

Do the commercial tracking scripts work with Mozilla/Firefox? How do they do it if so?

UnnamedPlayer

11:12 am on Jan 15, 2005 (gmt 0)

10+ Year Member



Has anyone looked at the old suggestion for making the script work with Mozilla/Firefox?

Yes, I tried that too but nothing :(

It seems the onfocus event on iframes is not defined by the W3C as a standard, that's probably why some browsers don't support it.

[w3schools.com...]

Do the commercial tracking scripts work with Mozilla/Firefox? How do they do it if so?

I would say they don't support Mozilla/Firefox. Yesterday I found a site selling an AdSense tracking script for 100 USD and looking at their JavaScript code for the online demo I can assure it only works on IE or other browsers that support the iframe.onfocus event, if any.

Sergio

tebrino

2:00 pm on Jan 15, 2005 (gmt 0)

10+ Year Member



I just tested the code submitted above and it works like a charm. After first few hours of testing it looks very accurate.

monolitik

4:42 pm on Jan 15, 2005 (gmt 0)

10+ Year Member



I would say they don't support Mozilla/Firefox.

Not really. My script asrep does support firefox/mozilla and plus Opera.
Instead of using onfocus event of iframe, you monitor some series of events to come to a click conclusion such as if the browser is going to load some new page and if the mouse was over the iframe some short time ago and ... Not very simple but can be done.

amznVibe

5:08 am on Jan 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Very interesting Monolitik. I don't suppose you would donate a snippet that would empower firefox tracking to the public domain here would you?

Does your technique also work for Safari? I have one site that gets a bit of mac visitors...

zoltan

7:10 am on Jan 16, 2005 (gmt 0)

10+ Year Member



Ari, where on that script you specify where to store the data?
Also, how can we store user's IP address as well?

Thanks for the code.

Noel

11:06 am on Jan 16, 2005 (gmt 0)

10+ Year Member



Ari, where on that script you specify where to store the data?
Also, how can we store user's IP address as well?
Thanks for the code.

Thats the custom part you will have to code your self.

In Coldfusion it would look something like this:


<cfquery name="clickResult" datasource="AdSenseClicks" dbtype="ODBC">
INSERT INTO clicks (puPage, adDomain, adUnit, time, IP)
VALUES ('#puPage#', '#adDomain#', '#adUnit#', '#time#', '#cgi.remote_addr#')
</cfquery>

The code will log the value(s): puPage, adDomain, adUnit, time and cgi.remote_addr to a database named AdSenseClicks

Noel

UnnamedPlayer

11:35 am on Jan 16, 2005 (gmt 0)

10+ Year Member



Not really. My script asrep does support firefox/mozilla and plus Opera.
Instead of using onfocus event of iframe, you monitor some series of events to come to a click conclusion such as if the browser is going to load some new page and if the mouse was over the iframe some short time ago and ... Not very simple but can be done.

Thanks for pointing that out Monolitik, that opens a new line of investigation for me :)