Resources to Native Ads Course

Bot traffic can drain your ad spend and skew your results. These quick code snippets help filter out non-human clicks and improve your campaign quality.

You don’t need any advanced coding skills — just copy and paste the code into your landing page, and it’ll quietly protect you in the background.

These filters won’t catch everything, but they’re a smart first step to reduce junk traffic and keep your native ad campaigns cleaner and more cost-effective.

Time Delay Bot Filter

Just paste this script in the <body> or at the end of the page, and all clickable <a> elements will be protected against bot-like fast clicks.

<!-- Bot Filter -->
<script>
  const minDelay = 4000; // 4 seconds
  const pageLoadTime = Date.now();

  document.addEventListener("DOMContentLoaded", function () {
    document.querySelectorAll("a").forEach(link => {
      link.addEventListener("click", function (e) {
        const clickTime = Date.now();
        const timeSinceLoad = clickTime - pageLoadTime;

        if (timeSinceLoad < minDelay) {
          e.preventDefault();
          alert("Please wait a moment before clicking."); // Optional
          console.log("Click blocked — too fast, possible bot.");
        }
      });
    });
  });
</script>

Honeypot Bot Filter

What It Does:

Step 1: **Paste the Invisible Honeypot Field Anywhere in the <body>:

You can place it right after your opening <body> tag:**

<!-- Invisible Honeypot Field -->
<input type="text" id="bottrap" name="bottrap" style="position: absolute; left: -9999px;" autocomplete="off">

Step 2: Paste This Script Just Before the Closing </body> Tag

<!-- Bot Trap Script: Disables All Clicks if Bot Fills Field -->
<script>
  document.addEventListener("DOMContentLoaded", function () {
    const honeypot = document.getElementById("bottrap");

    if (honeypot && honeypot.value.trim() !== "") {
      // Disable all buttons and links
      const buttons = document.querySelectorAll("a, button");
      buttons.forEach(btn => {
        btn.onclick = function (e) {
          e.preventDefault();
          alert("Bot activity detected. Action blocked.");
        };
        btn.style.opacity = "0.5";
        btn.style.pointerEvents = "none";
      });

      console.log("Bot trap triggered: honeypot field was filled.");
    }
  });
</script>

That’s It! Just Two Steps:

Simple CAPTCHA Bot Filter

Add this snippet to any HTML page to make sure real users answer a quick math question before clicking through. Great for filtering out basic bots.

Instructions:

  1. Copy and paste the HTML where you want the CAPTCHA to appear (usually before the call-to-action button).
  2. Replace the CTA link in the button with your destination URL.
  3. Done!

✅ HTML + JavaScript Code:

<!-- Simple CAPTCHA Filter -->
<div id="captcha-box" style="margin-bottom: 20px;">
  <label for="captcha-answer"><strong>Are you human? What is 2 + 3?</strong></label><br>
  <input type="text" id="captcha-answer" placeholder="Your answer" style="margin-top: 5px; padding: 5px;">
  <p id="captcha-error" style="color: red; display: none;">Incorrect answer. Try again.</p>
</div>

<a href="#" id="captcha-btn" style="
  background-color: #28a745;
  color: white;
  padding: 10px 20px;
  text-decoration: none;
  border-radius: 5px;
  font-weight: bold;
  display: inline-block;
  pointer-events: none;
  opacity: 0.5;
">Continue</a>

<script>
  const correctAnswer = "5";
  const input = document.getElementById("captcha-answer");
  const button = document.getElementById("captcha-btn");
  const errorMsg = document.getElementById("captcha-error");

  input.addEventListener("input", function () {
    if (input.value.trim() === correctAnswer) {
      button.style.pointerEvents = "auto";
      button.style.opacity = "1";
      errorMsg.style.display = "none";
      button.href = "https://yourdestination.com"; // Replace with your real link
    } else {
      button.style.pointerEvents = "none";
      button.style.opacity = "0.5";
      errorMsg.style.display = input.value.trim() !== "" ? "block" : "none";
    }
  });
</script>