AI bot tracking middleware for AgentSight — detect and monitor AI agent visits to your website
npm install @agentsight/trackingAI bot tracking middleware for AgentSight — detect and monitor AI agent visits to your website.
- Detect 19+ AI bots (GPTBot, ClaudeBot, PerplexityBot, etc.)
- Classify bots as training crawlers or live agents
- Fire-and-forget tracking events
- Framework adapters for Cloudflare Pages, Next.js, Express, Hono, Astro
``bash`
npm install @agentsight/tracking
`ts
// functions/_middleware.ts
import { createAgentsightMiddleware } from '@agentsight/tracking/cloudflare'
export const onRequest = createAgentsightMiddleware({
token: 'ast_your_token',
})
`
`ts
// middleware.ts
import { createAgentsightMiddleware, matcherConfig } from '@agentsight/tracking/nextjs'
export const middleware = createAgentsightMiddleware({ token: 'ast_your_token' })
export const config = matcherConfig
`
`ts
import express from 'express'
import { createAgentsightMiddleware } from '@agentsight/tracking/express'
const app = express()
app.use(createAgentsightMiddleware({ token: 'ast_your_token' }))
`
`ts
import { Hono } from 'hono'
import { agentsightMiddleware } from '@agentsight/tracking/hono'
const app = new Hono()
app.use('*', agentsightMiddleware({ token: 'ast_your_token' }))
`
`ts
// src/middleware.ts
import { createAgentsightMiddleware } from '@agentsight/tracking/astro'
export const onRequest = createAgentsightMiddleware({ token: 'ast_your_token' })
`
`ts
import { detectAiBot, sendTrackingEvent, AI_BOTS } from '@agentsight/tracking'
// Detect if a user-agent belongs to an AI bot
const bot = detectAiBot(userAgent)
// Returns: { name: 'GPTBot', operator: 'OpenAI', type: 'training_crawler' } | null
// Send a tracking event
await sendTrackingEvent({
token: 'ast_your_token',
path: '/about',
userAgent: 'Mozilla/5.0 AppleWebKit/537.36 ... GPTBot/1.0',
})
// Access the full bot list
console.log(AI_BOTS) // 19 bot signatures
`
| Option | Type | Required | Description |
|--------|------|----------|-------------|
| token | string | Yes | Your AgentSight site token (ast_...) |endpoint
| | string` | No | Custom API endpoint (defaults to AgentSight API) |
MIT