Hello everyone! Today in this article, I will tell you how to prevent Adsense from Click Bombing using Vanilla JavaScript by using Cookies.
Friends, as we know that getting AdSense approved on any site is difficult nowadays. We do hard work to get our site Google AdSense approved. I have faced the issue of Ad-limits due to invalid clicks. For these invalid clicks, Adsense may restrict showing Ads on your site for a limited time.
So to control clicks on AdSense by visitors, I will give you scripts that reduce Invalid Clicks on any Blogger Website.
![]() |
AdSense Anti Click Bomb Script |
How does this Script work
By setting Cookies in the visitor's browser we can prevent Invalid AdSense Clicks. For example:
Suppose you have set 3 maximum clicks in the script. So, when the visitor clicks on ads 3 times and again clicks on the ads, the ads will disappear. They will not be able to see ads for the time you set on the script.
Clearing cookies will still allow users to click on Ads. So, it will not totally prevent Click Bombing but it will help you to control the clicks.
How to install Anti AdSense Bombing Script on Blogger
Important!
Before we start adding codes in XML, I will recommend you take a Backup of your current theme. By chance, if any problem occurs, you can restore it later.
STEP 1: Go to Blogger Dashboard
STEP 2: Click on the Theme
STEP 3: Click the arrow down button next to 'customize'
STEP 4: Click on 'Edit HTML', the theme coding section will be opened.
STEP 5: Now search
</head>
tag and just above it, paste the following JavaScript Code.
JavaScript
<script> /*<![CDATA[*/ /* Cookie functions */ const Cookie = { get: (e) => { e = document.cookie.match(new RegExp("(?:^|; )" + e.replace(/([.$?*|{}()[\]\\/+^])/g, "$1") + "=([^;]*)")); return e ? decodeURIComponent(e[1]) : void 0 }, set: (e, n, o = {}) => { o = { path: "/", ...o }, o.expires instanceof Date && (o.expires = o.expires.toUTCString()); let c = unescape(encodeURIComponent(e)) + "=" + unescape(encodeURIComponent(n)); for (var t in o) { c += "; " + t; var a = o[t]; !0 !== a && (c += "=" + a) } document.cookie = c }, rem: (e) => { Cookie.set(e, "", { "max-age": -1 }) } } /* Anti bomb config */ const antiBombSet = { timeOut: 3600, /* Timeout in seconds, when to ads appear after maximum clicks */ maxClick: 3, /* No of maximum clicks */ cookieKey: "MAX_CLICKED", /* Cookie key to set */ adsSelectors: "ins.adsbygoogle", /* Ads selectors */ iframeSelectors: "ins.adsbygoogle iframe", /* Ads iframe selectors */ callback: () => { /* Runs only one time if/when clicked maximum times on ads */ if (antiBombSet.executed === undefined) { antiBombSet.executed = !0; /* Prevent clicks on ads placement with pointer-events:none | You can also try display:none */ if (document.getElementById("mxAds_stl") == null) { var stl = document.createElement("style"); stl.id = "mxAds_stl"; stl.innerHTML = (antiBombSet.adsSelectors || ".adsbygoogle") + "{pointer-events:none}"; document.head.appendChild(stl); } /* Add your js below to execute if/when clicked maximum times on ads */ /* console.warn("You have clicked the maximum times on ads. Don't click on ads if you don't want to support us."); */ } } }; if (Cookie.get(antiBombSet.cookieKey || "ADS_CLICK") != undefined && parseInt(Cookie.get(antiBombSet.cookieKey || "ADS_CLICK")) >= (antiBombSet.maxClick || 3)) { antiBombSet.callback() }; /*]]>*/ </script>
</body>
tag and paste the following JavaScript code just above </body>
tag.JavaScript
<script> /*<![CDATA[*/ ! function () { function n(e, o) { return null != (e = Cookie.get(e)) && parseInt(e) >= o } var l = antiBombSet.cookieKey || "ADS_CLICK", e = antiBombSet.adsSelectors || ".adsbygoogle", i = antiBombSet.timeOut || 7200, c = antiBombSet.maxClick || 3; 0 < document.querySelectorAll(e).length && document.querySelectorAll(e).forEach(e => { e.addEventListener("click", function () { var e, o; n(l, c) ? antiBombSet.callback() : (e = l, null != (o = Cookie.get(e)) ? (o = parseInt(o) + 1, Cookie.set(e, o.toString(), { secure: !0, "max-age": i })) : Cookie.set(e, "1", { secure: !0, "max-age": i })) }) }), window.addEventListener("blur", function () { n(l, c) && antiBombSet.callback(); for (var e, o, t = document.querySelectorAll(antiBombSet.iframeSelectors || ".adsbygoogle iframe"), a = 0; a < t.length; a++) document.activeElement == t[a] && (n(l, c) ? antiBombSet.callback() : (e = l, null != (o = Cookie.get(e)) ? (o = parseInt(o) + 1, Cookie.set(e, o.toString(), { secure: !0, "max-age": i })) : Cookie.set(e, "1", { secure: !0, "max-age": i }))) }) }(); /*]]>*/ </script>
Source: fineshopdesign.com
You may want to read these posts :