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.
- ✅ Time Delay Filter: Blocks clicks that happen too fast after the page loads (a common sign of bots).
- ✅ Honeypot Trap: Adds an invisible field that real users won’t fill, but bots usually will — when triggered, it disables all button clicks.
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:
- Adds an invisible textbox to your page.
- If a bot fills it in, all clickable buttons (
<a>and<button>) get disabled. - Human users won’t even see the field.
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:
- One hidden input field anywhere in the body.
- One script at the end of the page.
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:
- Copy and paste the HTML where you want the CAPTCHA to appear (usually before the call-to-action button).
- Replace the
CTA linkin the button with your destination URL. - 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>