Welcome to WebmasterWorld Guest from 18.204.227.250

Forum Moderators: martinibuster

Message Too Old, No Replies

Possible Solution: Tracking Adsense in IE7

Possible Firefox Solution Too But Not Ideal

     
9:13 pm on Dec 2, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 1, 2002
posts:96
votes: 0


Been playing around with javascript code using a simulated Adsense banner called via an external js file from a different domain. It seems to work in IE7 but please note that this has not been tested with a real Adsense ad.

Concept: The following uses onMouseOver and onMouseOut to change the background colour of a div containing an Adsense banner (the background colour change is not visible to a user). onbeforeunload code checks if the background colour of div with id "google_ad_1" is set to "#000000" and if it is, fires a new image to log the click.

In page header

<script type="text/JavaScript">

function log_click() {

if (document.getElementById("google_ad_1").bgColor == "#000000") {(new Image(5,5)).src = "google_track_script.cgi?adclicked=1";}

}

window.onbeforeunload = log_click;

</script>

In page body

<div style="width:[width of adsense ad]px" id="google_ad_1" onMouseOver="this.bgColor='#000000';" onMouseOut="this.bgColor='#FFFFFF';">

<SCRIPT language="JavaScript" SRC="http://www.not-same-domain.com/mock_adsense_ad.js"></SCRIPT>

</div>

In Firefox the only way I could get a click to be logged in Firefox was to insert an alert("foobar"); at the end of function log_click (not viable) or replacing:

(new Image(5,5)).src = "google_track_script.cgi?adclicked=1";

with

document.write('<img src="google_track_script.cgi?adclicked=1" width=5 height=5>');

which effectively redraws the page your on, loading the image, before going to the clicked URL. Causes a dupe log if a user hits the back button after clicking though. Also not sure if this would violate TOS.

6:36 pm on Dec 4, 2006 (gmt 0)

New User

10+ Year Member

joined:Feb 13, 2006
posts:36
votes: 0


This is very interesting. I like your concept a lot and I'm curious to see how it works out.
7:02 pm on Dec 4, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member hobbs is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 19, 2004
posts:3056
votes: 5


Also not sure if this would violate TOS

I would be extremely surprised if you can get away with it, my money is on an ear pinch or worse a TOS violation account ban.

change the background colour of a div containing an Adsense banner

Don't, or at least send an url to Google support and see what they have to say before going live with something like this.
8:26 pm on Dec 4, 2006 (gmt 0)

Senior Member

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

joined:Nov 6, 2002
posts:4768
votes: 0


Neat hack, although it doesn't tell you what ad was clicked, which was an important part of the previous script.

It sounds to me like the Firefox portion would be in violation of the TOS. If the IE portion doesn't visibly affect the appearance during a mouseover or the behaviour following a click, IMO it would probably be OK. You'd want to back-test it with a variety of browsers and versions, especially IE6.