I‘ve been using Adsense for over three years to monetize my sites but even though I’ve followed the Adsense TOS and never clicked on my own ads, I was actually banned from Adsense for supposed invalid clicks last November. It turns out I was the victim of a click-bombing by some disgruntled ex-Adsense publisher who was stalking the Adsense support forums looking for innocent victims to get their accounts banned by clicking incessantly on their ads.
I did manage to have my Adsense account re-instated a few days later - minus two months earnings - so since then I have been looking at various solutions to prevent any click-bombings of my account in the future. I’ve tried several commercial solutions that were bloated with additional options that were unnecessary for my simple applications. Finally, I decided to begin coding my own solution based on the KISS (Keep It Simple Stupid) model that has only one function : disable Adsense ads after they have been clicked on “x” amount of times.
Over the next few days I will be publishing the solution, code named “ClickDodger”, to aid other publishers avoid the pitfall of click-bombing or invalid clicks. I would sincerely appreciate any input on this project and will work with anybody interested in utilizing this code to add additional functionality as the need arises.
Starting With The Simplest Scenario
In order for to accurately record the number of clicks a website visitor has made, it would be logical to use a simple html tracking cookie to record events. Granted, a hacker or click-bomber could easily delete the cookie each time they’ve clicked enough times to set off the tripwire but we’ll keep this simple for the moment.
I’ve opted to use Javascript because the modern DOM model supports event handlers as well as the ability to generate content on the fly. Javascript is also a viable option because it can be used in any scripting language (PHP, ASP, ColdFusion, Ruby) in addition to plain html.
Displaying the Appropriate Ads
Working backwards, the code to display either an Adsense ad or an alternative ad network based on the tripwire settings would look like this :
<div id="banners" onclick="trackclick();">
<script language="JavaScript">
if ( clickCount > 2 ){
document.write('
<a href="http://www.pjtra.com/t/RD1FRklFPURASUk9RURISQ">
<img src="http://www.pjtra.com/b/RD1FRklFPURASUk9RURISQ?sid=AFFBEST">
</a>
');
}else{
document.write('
<script type="text/javascript"><!--
google_ad_client = "pub-8299655316220106";
/* C4G-Forum-728x90, created 5/9/08 */
google_ad_slot = "3304568502";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
');
}
</script>
</div>
We have wrapped the banner code in a DIV element with the ID “banners”. The DIV also has an onclick event handler which calls a function trackclick() when a link within the DIV is clicked on. If the clickcount is less than 2, a Google Adsense ad is shown but if the clickcount is greater than 2, the PepperJam Network code is displayed.
Tracking Clicks Using a Cookie
Now that we have the code to display the appropriate ad block, we will need a Javascript handler to record the visitor’s clicks and set a cookie that keeps a running count of the number of clicks a visitor has made on an ad block. The Javascript code below is a basic implementation to handle these actions :
<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>
The script is rather simple. When the page loads, the script attempts to call readCookie and set a variable called clickcount. If readCookie() returns null (the cookie has not been set), then the clickcount is set to 0. The trackclick() function is called whenever the DIV we created in the previous step is clicked and it increments the clickcount and calls setCookie to set the incremented value.
This solution will work across all the pages on a site using the code and the Javascript can be stored in a .js file so it can easily be included into any page you wish to utilize it on. Although as I mentioned above, this method could be over-ridden if the clickbomber deletes the cookie each time the clickcount is maxxed, however, for most purposes, this application should suffice.
In tomorrows installment, we will be examining a more robust solution built on this example that uses PHP and mySQL to track the visitors IP address to ensure the Adsense click count can’t be reset by deleting the cookie.
Please feel free to leave comments on this article and I’ll be more than happy to address any questions or comments any of my readers might have.





















This article is THE BOMB. I just subscribed to your RSS feed because your blog is so different than the average affiliate markeing blog. You really give us readers the tips we’re looking for and you don’t make like you’re God’s gift to blog readers.
Keep up the good work Dave. You have a loyal fan in me.
I want to do the same… it’s for my personal protection on my Adsense account ::: know you. someone might sabotage your account if you are not good to everyone.
Hi Dave,
This is a very useful tip and I must say today I have learned a new tip that I new nothing about. I have been using Google Adsense sparingly but at least now I do know what to do to protect your Adsense earnings.
Yes click bomb is a very big problem, first of all Google Adsense has no way of telling if you are the one who did the clicks, or it is someone that hates your guts. Thank you for the tips, I will be installing them on my blogs. The more protected you are the better, and make sure you don’t make alot of enemies online.
how to add this in wordpress??? can u show me step by step
will appreciate for your great support
thanx
murtaza habib
www.paintonmycanvas.com
Good post. I work with Adsense much. I hope you don’t mind if a shameless promote my service here.
If you would like to make a substantial income by building Adsense Websites and displaying ads? This set of scripts automates the task and allows you to continue in your regular job. Only a few hours a week will have you up and running and generating a great income. Look at the amm-info dot com site for specific information.
I found your blog via Google while searching for first aid step 1 and your post regarding Prevent Adsense Click-Bombing and Invalid Clicks looks very interesting to me. I could not believe the amount of quality material on this site. The site is extremely eyecatching and pulls the reader straight it, the articles are great quality and are very professionally written. I have seen too many of these sites where it looks like they pay an 8 year old to do the writing - Not this one. Your site is easily the best that I have seen in a long while.
That was a really useful read,well written - nice work!
I wish I had seen this article a few months ago when I was a victim of Click-Bombing. This is why I’m out searching for new affiliate programs. I have to do something to earn from my websites.
It’s a shame that Adsense allows the click-bombing to happen but I think some of it has to do with webmasters doing things to get traffic (like buying cheap traffic) that causes a lot of the trouble and bannings.
There are half a dozen scripts on the net to prevent the click-bombing. The problem with most of them is that they are outdated. Will give a try to this script and write here later if it works for me.
The script I whipped up here is really just a basic concept that could be ammended to make a very powerful script to prevent click-bombing.
One thing all publishers should be aware of is to always use your “allowed sites” in the Adsense control panel. This way a bomber can’t put your ads on his/her site and fire away.
Dave, thats a good code. Though its not so powerful in protecting websites from advanced click bombers ,its powerful. Looking forward for your next version of sophisticated code. I guess that would be powerful like openx or adlogger, but still simple.
Gamer, you’re right. The script prevents simple click-bombs. I think it would probably better if the open source community developed a robust solution because after all, Google Adsense is a component of any online income. Plus, Google pays on time.
Thanks for your nice work.
I would like to ask if you can prevent invalid clicks on custom search result.
Thanks very much!
I think I got click-bombs. I will try your solutions.
Thanks again!
very informative article. Where is the PHP code for this?