@aranx/ai-analytics package adds a Hono middleware. It records requests
from AI bots such as ChatGPT-User and PerplexityBot, and visits from
people who open your site from a link in an AI app. It works on Cloudflare
Workers, Node.js, Bun, and Deno.
Before you start
- In Aranx, open AI Visibility for the website and create a server key. Aranx shows the key once.
Setup
1
Install the package
2
Set the key
On Cloudflare Workers, add it as a secret:On Node.js, Bun, or Deno, set the
ARANX_TRAFFIC_KEY environment
variable on the server. Do not commit the key. If you keep the key in
.env, the server must load the file before it creates the middleware.
On Node.js, use node --env-file=.env server.js (Node.js 20.6 or later)
or the dotenv loader of the project. On Deno, use
deno run --env-file=.env main.ts. Bun loads .env by itself.3
Add the middleware
Register it before your routes:On Workers, the middleware reads the key from the
src/index.ts
ARANX_TRAFFIC_KEY
binding. Elsewhere it reads process.env.Aranx counts a bot visit only when its IP is in the bot’s published IP
ranges. On Workers the client IP comes from CF-Connecting-IP. On
Node.js, Bun, and Deno it comes from the connection. Behind a proxy
that is the only way to reach the server, name the one header it sets,
for example aiTraffic({ clientIpHeader: 'x-real-ip' }).4
Deploy
Deploy the app. Aranx shows the first bot visits on the AI visibility
page.
Check the setup
Send a request with an AI user agent:What the package sends
For each AI request: the page URL without its query (it keepsutm_source),
the user agent, the response status, and the time. Bot visits also carry the
client IP, which Aranx checks against the bot’s published IP ranges and does
not store. Tracking never throws and never delays the response.
