AdSense Click Protection: A Comprehensive Guide and free JavaScript

Code JavaScript  for AdSense Click Protection

AdSense is a popular advertising program run by Google that allows website owners to earn revenue by displaying ads on their sites. However, one of the challenges faced by AdSense publishers is invalid clicks, which can harm their earnings and even lead to account suspension. In this article, we will provide a detailed guide on how to protect your AdSense clicks from invalid activity.




What are Invalid Clicks?

Invalid clicks refer to clicks on AdSense ads that are generated by means other than a user genuinely interested in the ad. This could be due to accidental clicks, clicks generated by automated bots, or clicks generated by individuals with malicious intent. Invalid clicks can harm the advertiser, the publisher, and the user experience.

Why Protect AdSense Clicks?

Protecting your AdSense clicks is essential to ensure the stability and growth of your earnings. Google has a strict policy against invalid clicks and takes measures to detect and prevent such activity. If invalid clicks are detected on your account, you may face penalties such as account suspension or reduced earnings.

How to Protect AdSense Clicks

There are several measures you can take to protect your AdSense clicks from invalid activity. These include:

  1. Implementing AdSense click protection script
  2. Placing ads in well-defined areas on your website
  3. Regularly monitoring your account for suspicious activity
  4. Using third-party tools to monitor clicks

Implementing AdSense Click Protection Script

One of the most effective ways to protect your AdSense clicks is by implementing an AdSense click protection script on your website. This script helps prevent invalid clicks by verifying the authenticity of clicks before they are recorded.

Placing Ads in Well-Defined Areas

Placing your AdSense ads in well-defined areas on your website can also help reduce the risk of invalid clicks. This is because well-defined areas are less likely to be accidentally clicked, and it becomes easier to identify suspicious activity.

Regularly Monitoring Your Account

Regularly monitoring your AdSense account for suspicious activity can help you detect and prevent invalid clicks. You can use the AdSense reporting tools to monitor your click activity and identify any anomalies.

Using Third-Party Tools

There are several third-party tools available that can help you monitor your AdSense clicks and protect your account from invalid activity. Some of these tools can provide real-time monitoring and alerts for suspicious activity, making it easier to prevent invalid clicks.

And You Can Use JavaScript like 

Prevent Adsense from Click Bombing using Vanilla JavaScript - Cookie Based for Protection AdSense

How does it function?

In simple terms, a cookie is set in the user's browser that tracks the number of times they have clicked on an ad. The value of the cookie increments with each click until the maximum number of clicks, set by you (e.g. 3 clicks), is reached. At that point, the ads will no longer be displayed for a specified amount of time. For example, if you set the limit at 3 clicks, the cookie value would increase each time the user clicks on an ad until it reaches 3, and the ads will then disappear.

    Here's how you can use this code on your Blogger:

    1. Login to your Blogger account and navigate to your blog's dashboard.
    2. Click on the "Theme" option and then click on the "Edit HTML" button.
    3. Locate the </head> tag in your theme's HTML code and paste the script code above it.

    Code JavaScript
    <p><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>
     </p>

    This code is a JavaScript implementation of an anti-bomb mechanism, which is used to limit the number of clicks on ads on a web page. The code makes use of the Cookie object to store and retrieve information about the number of clicks on ads.


    4.Locate the </body> tag in your theme's HTML code and paste the script code above it.

    Code JavaScript
    <p><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>
     </p>

    5.Save the changes to your theme.

    The code uses the Cookie object to store the number of clicks on ads and the number of clicks is updated every time the ads are clicked. Once the maximum number of clicks (defined by the maxClick constant) is reached, the anti-bomb mechanism takes effect and the ads are disabled for the period defined by the timeOut constant.

    You can customize the code according to your needs by modifying the values of the timeOut, maxClick, and cookieKey constants, as well as the adsSelectors and iframeSelectors selectors to match the selectors of the ads on your blog.

    Source Code JavaScript  by fineshopdesign

    Next Post Previous Post
    No Comment
    Add Comment
    comment url