Forum Moderators: open

Message Too Old, No Replies

Need Help with JS that makes Ads Disappear after 2 Clicks

My Code Doesn't Seem to Work

         

kickerman360

12:54 pm on Jul 1, 2009 (gmt 0)

10+ Year Member



Hi
I was wondering if maybe a Javascript expert can help me out. I want my Adsense ads to disappear after 2 clicks. So for example, a click bomber comes in, starts spamming, but after to clicks he's stopped.

I have this script but I couldn't get it to work:

--------------------------------------
<html>
<head>
<title>Click Bomber Defense</title>
<script language="JavaScript">

var clickCount = readCookie();
if ( clickCount == null ){
clickCount = 0;
}

function trackclick() {
clickCount = parseInt(clickCount)+1;
setCookie( clickCount, 2 );
return true;
}

function setCookie( cookieValue, nDays) {
var today = new Date();
var expire = new Date();
if (nDays==null ¦¦ nDays==0) nDays=1;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = "clicktrack="+escape(cookieValue)
+ ";expires="+expire.toGMTString();
}

function readCookie() {
var nameEQ = "clicktrack=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0){
return c.substring(nameEQ.length,c.length);
}
}
return null;
}

</script>
</head>

<body>

<div id="banners" onclick="trackclick();">

<script language="JavaScript">

if ( clickCount > 2 ){
document.write('
<a href="http://example.net">
<img src="http://example.net/click-bomb.jpg" />
</a>
');
}else{
document.write('

ADSENSE Code Here


');
}

</script>
</div>

</body>
</html>
---------------------------------------
It doesn't seem to work however. I'm not very good at Javascript so perhaps guys can help me. Also, I am aware the cookies can be cleared which is a flaw in the method but you have to be determined to click bomb, 2 click at a time.

Is there anything wrong with the code?

londrum

2:53 pm on Jul 1, 2009 (gmt 0)

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



isn't the adsense code displayed inside an iframe?

i'm not much of an expert on javascript either, but if you want to record clicks from inside that iframe then the javascript would have to come from that frame as well, which you can't do.

fredw

4:12 pm on Jul 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And besides, it's generally believed that Adsense is really good at being able to tell the difference between someone who's clicking on their own ads, and a site that is being click-bombed from outside. The clicks are just not counted by Google, and you're not penalized. If you're still afraid, keep good server logs.

kickerman360

4:29 pm on Jul 1, 2009 (gmt 0)

10+ Year Member



Well this script isn't supposed to record any data for long periods of time. It's a user only deal.

For example, the user can click any ads, twice on the site and get linked to that ad, before an alternate image appears.

The user will see ads when the cookies are cleared.

Google has a guilty until proven innocent policy. It's far easier to prevent invalid clicks than it is to go through the hassle of sending in data.

Can anyone help me out?

londrum

4:38 pm on Jul 1, 2009 (gmt 0)

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



but the ads aren't displayed on your site... they are displayed on google's site (and displayed on yours through an iframe).

there is no javascript that you can write on your site that will record clicks on google's