Skip to content
/ track Public

Track AI coding agents visiting your docs (Claude Code, Codex, OpenCode)

License

Notifications You must be signed in to change notification settings

team2027/track

Repository files navigation

2027 Track

2027 Track

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 MIT License

2027 Track Dashboard


Quick Start

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.

One-Click Deploy (Framer, static sites, any Cloudflare-proxied domain)

No npm install needed. Deploy a lightweight Cloudflare Worker that sits in front of your site and tracks AI agent visits automatically.

Deploy to Cloudflare Workers

After deploying:

  1. In Cloudflare DNS, make sure your domain is proxied (orange cloud)
  2. Add a Worker Route matching your domain (e.g. yourdomain.com/*)
  3. 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.).

How It Works

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]

Detection

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.

Test Detection

See how your request gets classified:

curl https://ai-docs-analytics-api.theisease.workers.dev/detect
{"category": "coding-agent", "agent": "opencode"}

Privacy

  • 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

Self-Hosting

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 deploy

Set custom endpoint:

AI_ANALYTICS_ENDPOINT=https://your-worker.workers.dev/track

Set to empty to disable entirely:

AI_ANALYTICS_ENDPOINT=""

API Reference

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

Project Structure

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

License

MIT — use it however you want.


Built by team2027 · @2027dev

About

Track AI coding agents visiting your docs (Claude Code, Codex, OpenCode)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors