agent-analytics
AI agent traffic analytics for Next.js
A small TypeScript library for Next.js that detects and logs visits from AI tools like Claude, ChatGPT, and Perplexity, so you can see how much of your site traffic comes from AI crawlers versus real humans.
agent-analytics is a small TypeScript library for Next.js websites that detects and records visits from AI tools. When AI systems like Claude, ChatGPT, or Perplexity reference your website or fetch its content, they identify themselves through request headers. This library reads those identifiers and logs the traffic so you can see how often AI tools are visiting your pages.
The library is designed to slot into Next.js middleware, which is a layer that runs on every incoming request before your pages load. You initialize it once with a Redis connection from Upstash, then call a single tracking function on each request. The setup shown in the README takes about ten lines of code.
Once connected, the traffic data appears in the Upstash dashboard under an AI Tracking section. This lets you see which AI tools are visiting your site and how frequently, without needing to build or host any separate analytics infrastructure.
The README is minimal and only shows the code required to get started. It does not explain what signals the library uses to identify AI traffic, what data fields are recorded, or what level of detail the dashboard provides beyond showing which AI tools have visited.
This library would be useful for website owners who want to understand how much of their traffic comes from AI crawlers and citation-fetching systems rather than human visitors. As AI assistants increasingly surface web content in their answers, knowing which tools are pulling from your site becomes useful context for understanding your audience.
Where it fits
- Find out how often AI tools like ChatGPT or Claude are fetching content from your website.
- Separate AI crawler traffic from real human visitors in your analytics.
- Track which specific AI systems are referencing or indexing your site's pages.