Know who's using your product: humans or agents
A lightweight, open source library to detect and track AI coding agents visiting your docs.
npm install 2027-track// middleware.ts (Next.js)
import { withAIAnalytics } from "2027-track/next";
export default withAIAnalytics();
export const config = {
matcher: ["/((?!api|_next|admin).*)",],
};Works with any Vercel deployment too (Remix, SvelteKit, Astro, Nuxt):
// middleware.ts (Vercel)
import { withAIAnalytics } from "2027-track/vercel";
export default withAIAnalytics();
export const config = {
matcher: "/((?!_next|api|favicon.ico|assets|.*\\..*).*)",
};Cloudflare Pages:
// functions/_middleware.ts
import { onRequest as withAIAnalytics } from "2027-track/cloudflare";
export const onRequest = withAIAnalytics();Express / Node.js:
import express from "express";
import { withAIAnalytics } from "2027-track/express";
const app = express();
app.use(withAIAnalytics());That's it. AI agent visits are now tracked.
No npm install needed. Deploy a lightweight Cloudflare Worker that sits in front of your site and tracks AI agent visits automatically.
After deploying:
- In Cloudflare DNS, make sure your domain is proxied (orange cloud)
- Add a Worker Route matching your domain (e.g.
yourdomain.com/*) - Done — all requests pass through the tracker to your origin
This is perfect for sites that don't support middleware (Framer, Carrd, static HTML, etc.).
AI coding agents (Claude Code, Codex, OpenCode) send Accept: text/markdown when fetching docs — browsers never do. We detect this signal and classify the visitor.
[Your Site] → [2027-track middleware] → [Analytics API] → [Your Dashboard]
| Agent | Signal |
|---|---|
| Claude Code | axios user-agent + text/markdown accept |
| OpenCode | text/markdown with q= quality weights |
| Codex | ChatGPT-User user-agent |
| Unknown AI | text/markdown in accept (fallback) |
Bots and crawlers (Googlebot, GPTBot, etc.) are automatically filtered.
See how your request gets classified:
curl https://ai-docs-analytics-api.theisease.workers.dev/detect{"category": "coding-agent", "agent": "opencode"}- Events sent server-side from your edge/server — visitor IPs never reach us
- No cookies, no fingerprinting, no PII
- Only: host, path, user-agent, accept header, country
- Fully open source — audit the code yourself
Don't want to send data to our API? Self-host everything:
# Clone and deploy your own API
git clone https://github.com/team2027/track
cd track/api
npx wrangler deploySet custom endpoint:
AI_ANALYTICS_ENDPOINT=https://your-worker.workers.dev/trackSet to empty to disable entirely:
AI_ANALYTICS_ENDPOINT=""Hosted API: https://ai-docs-analytics-api.theisease.workers.dev
| Endpoint | Description |
|---|---|
POST /track |
Record a visit |
GET /detect |
Test your headers |
GET /query?q=agents |
Agent breakdown |
GET /query?q=sites |
Visits by site |
GET /query?q=feed |
Recent visits |
track/
├── api/ # Cloudflare Worker (analytics API)
│ ├── detect.ts # Classification logic
│ ├── index.ts # API routes
│ └── wrangler.toml # CF config
├── workers/tracker/ # One-click deployable proxy tracker
│ ├── index.ts # Passthrough proxy + tracking
│ ├── wrangler.toml # CF config
│ └── package.json
├── packages/middleware/ # npm package (2027-track)
│ └── src/
│ ├── index.ts # Core tracking
│ ├── next.ts # Next.js wrapper
│ ├── vercel.ts # Vercel edge middleware wrapper
│ ├── cloudflare.ts # Cloudflare Pages/Workers wrapper
│ └── express.ts # Express/Node.js middleware
└── dashboard/ # Analytics UI
MIT — use it however you want.

