Forum Moderators: martinibuster
[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
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
<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>
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
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
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
[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?
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
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.
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
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 :)