Skip to content

bot-vasectomy: Filter Bot Traffic from Web Analytics

bot-vasectomy is a small, zero-dependency TypeScript library. It detects common automation signatures in the browser and holds analytics tags until a visitor passes human engagement checks. It works with React, Next.js, Astro, and plain HTML.

Why Do Analytics Tools Count Bot Traffic?

Analytics tools count many visitors that are not people:

How Does bot-vasectomy Detect Bots?

The gate uses two layers to filter synthetic traffic before vendor tags load.

Layer 1: Heuristic Evaluation

The gate builds a single browser context snapshot with the user agent, screen size, window size, language list, touch points, and navigator.webdriver. It runs 13 pure rules in sequence and stops at the first rule that detects a bot:

You can also add custom rules or configure exemptions for internal teams, monitors, and end-to-end tests.

Layer 2: Hybrid Gating

Visitors who pass the heuristics enter the running state. The gate opens on the first of two conditions:

  1. Interaction: A trusted pointerdown, scroll, keydown, touchstart, or pointermove event.
  2. Visible dwell time: A fallback timer that counts only visible tab time.

Which Frameworks and Analytics Vendors Are Supported?

The library ships entrypoints for core TypeScript/JavaScript, React, Astro, and vanilla HTML. It gates tags for GA4 / Google Tag Manager, Plausible, PostHog, Umami, Cloudflare Web Analytics, Microsoft Clarity, and Matomo.

Installation

npm install bot-vasectomy

See the bot-vasectomy package on npm for full API documentation and integration examples.