Forum Moderators: martinibuster

Message Too Old, No Replies

Possible Solution: Tracking Adsense in IE7

Possible Firefox Solution Too But Not Ideal

         

Kerrin

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

10+ Year Member



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.

Vastio

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

10+ Year Member



This is very interesting. I like your concept a lot and I'm curious to see how it works out.

Hobbs

7:02 pm on Dec 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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.

jomaxx

8:26 pm on Dec 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.