Render Better's Bot Mitigation gives you server-side control of your site to run/block scripts or show/hide content based on whether a visitor is identified as a bot.
How it works
The Bot Mitigation feature allows you to conditionally add HTML that is run for visitors depending on whether a visitor is a bot, likely a bot, or unlikely a bot. You wrap the code you want to run for each group in an HTML template
tag with an accompanied rb-bot-detected
attribute that specifies which group of visitor it applies to like so:
<template rb-bot-detected="maybe">
<!-- Code that you want to run for suspected bots -->
</template>
The code within the template
tag is then unwrapped from the template
tag when it matches the visitor, or it is fully removed from the HTML if it doesn’t match.
Below are the three types of matches that can be applied to visitors:
- Definite Bots (
rb-bot-detected=true
) - Visitors that have identified themselves as bots through their user agent, such as Google’s and Facebook’s crawlers. - Suspected Bots (
rb-bot-detected=maybe
) - Visitors showing bot-like behavior or originating from data centers, but not clearly identifying themselves as bots. - Unlikely Bots (
rb-bot-detected=false
) - Most likely human visitors.
When a request comes in and it isn’t clear whether the request is from a bot, Render Better analyzes multiple signals including user agent strings, edge request location (i.e., data centers), and other signals.
Note: We can’t be certain visitors are not bots. This is not a substitute for CAPTCHAs or other methods to determine if a visitor is truly a human.
Example implementing
For Bot Mitigation, contents are wrapped in template tags with the rb-bot-detected
attribute. Here's how we target different visitor types. Elements and JS within each template are for example only.
<!-- Content only shown to confirmed bots -->
<template rb-bot-detected="true">
<script>
console.log("Definitely a bot");
// Add bot-specific analytics or modifications
</script>
</template>
<!-- Content shown to suspected bots -->
<template rb-bot-detected="maybe">
<script>
console.log("Suspicious visitor detected");
fetch("/analytics/suspected-bot", {
method: "POST",
body: JSON.stringify({
userAgent: navigator.userAgent,
timestamp: Date.now()
})
});
</script>
</template>
<!-- Content shown to visitors that unlikely bots -->
<template rb-bot-detected="false">
<script>console.log("Unlikely a bot. Apply regular analytics.")</script>
<script src="heavy-analytics.js"></script>
</template>
Important Notes:
- Content within matching templates is automatically applied to the html of the website
- Non-matching templates are removed
- Invalid scores result in the content being ignored
- If bot detection is disabled, all templates default to hidden
Enable Bot Mitigation
Please contact your team at Render Better to enable Bot Mitigation