In this post, we will discuss how to protect your AdSense account from invalid click activities by doing some minimal code changes in your web page.





Google AdSense is a popular advertising platform and is a great way to earn money online. Most bloggers prefer Google AdSense for monetizing their websites.

To have your AdSense account approved is a great deal in recent times but one must strictly adhere to AdSense program policies. If you fail to comply with these policies, your account might get banned. The first point in AdSense program policies clearly states that Publishers may not click their own ads or use any means to inflate impressions and/or clicks artificially, including manual methods.

Google monitors the clicks on its AdSense ads very closely. In order to prevent getting your account banned, you need to save your website from click bombings. There is no easy way to monitor the ad clicks on your website. In this post, we will show you how to protect your Google AdSense account from unusual invalid clicks.



The idea is actually very simple. When the user clicks on an AdSense ad for the first time, store a cookie/local storage on his machine with some expiration date. Now when the user visits another page in the same session or a new session, don’t serve him AdSense ads if that cookie if found on his machine.



To demonstrate, lets see some code:

1. Enclose all your AdSense ad codes inside a hidden div with ads class.

<div class="ads" style="display:none;"> // insert AdSense ad code </div> 1 2 3 < div class = "ads" style = "display:none;" > // insert AdSense ad code < / div >



2. Then have below code inside the <head> section of your web page where your other scripts reside or include it just before closing </body> tag of your html page.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> jQuery(function($) { // get current date var nowDate = new Date(); var date = nowDate.getDate()+'/'+(nowDate.getMonth()+1)+'/'+nowDate.getFullYear(); // if any element with class ads is clicked $('.ads').on('click', function () { // store current date on user local storage - you can change this value! localStorageSetItem("date", date); }); }); $(document).ready(function() { // check whether current date is recorded on the user's local storage var prevDate = localStorageGetItem("date"); if (!prevDate || prevDate != date) { // serve ads $('.ads').show(); } else { // don't serve ads (serve something else - eg. show donations link) } }); </script> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 <script src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" > </script> <script> jQuery ( function ( $ ) { // get current date var nowDate = new Date ( ) ; var date = nowDate . getDate ( ) + '/' + ( nowDate . getMonth ( ) + 1 ) + '/' + nowDate . getFullYear ( ) ; // if any element with class ads is clicked $ ( '.ads' ) . on ( 'click' , function ( ) { // store current date on user local storage - you can change this value! localStorageSetItem ( "date" , date ) ; } ) ; } ) ; $ ( document ) . ready ( function ( ) { // check whether current date is recorded on the user's local storage var prevDate = localStorageGetItem ( "date" ) ; if ( ! prevDate || prevDate != date ) { // serve ads $ ( '.ads' ) . show ( ) ; } else { // don't serve ads (serve something else - eg. show donations link) } } ) ; </script>

That’s it guys. Hope you have found this little piece of code helpful for protecting your AdSense account from invalid clicks.









(12 votes, average: 5.00 out of 5)

Loading...

Thanks for reading.