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:
- Phantom sessions: Headless browsers, scrapers, and screenshot services load pages and run analytics tags, which creates sessions with no engagement.
- Standard bot filters fail: Most filters read only the user agent string, while modern automation tools set normal user agents.
- WAF friction: Strict web application firewalls block real visitors or show CAPTCHAs that add friction for people without stopping scripted traffic.
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:
webdriverβnavigator.webdriver === truescraper-resolutionsβ Known headless screen sizes (800x600,1280x1052,1366x1366,1280x1200,1280x1280,1600x1600)square-screenβ Equal screen width and heightheadless-uaβ User agent containingHeadlessChromeorPhantomJSzero-outer-dimensionsβ Window outer size of0x0with a non-zero screenempty-languagesβ Emptynavigator.languagesarrayapple-800x600β Apple user agent with an800x600screeniphone-dimensionsβ iPhone, iPod, or Android phone user agent with impossible screen dimensionslegacy-chromiumβ Chrome major version below 100 (with exemptions for known WebViews)mobile-zero-touchβ Mobile user agent withmaxTouchPoints === 0incoherent-dimensionsβ Window outer size larger than the orientation-normalized screen sizesuspicious-webviewβ Generic Android WebView user agent without a known host app identifiermissing-chrome-runtimeβ Standard Chromium user agent wherewindow.chromeis undefined
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:
- Interaction: A trusted
pointerdown,scroll,keydown,touchstart, orpointermoveevent. - 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.