Skip to main content
The @aranx/ai-analytics package wraps the Worker fetch handler. 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 sends events with ctx.waitUntil, after the response.
If your site runs on Hono, use the Hono guide. If it is a Shopify Hydrogen storefront, use the Shopify Hydrogen guide.

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

Add the key as a secret

Paste the key when Wrangler asks for it. For wrangler dev, add it to .dev.vars:
.dev.vars
3

Wrap the fetch handler

src/index.ts
The wrapper reads the key from the ARANX_TRAFFIC_KEY binding, and the client IP from CF-Connecting-IP, which Cloudflare sets. Keep the other handlers (scheduled, queue) as they are.
4

Deploy

Check the setup

Send a request with an AI user agent:
Aranx does not count this visit. It counts a bot visit only from an IP in the ranges that OpenAI, Anthropic, and Perplexity publish for their bots, and scanners often fake these user agents. The request still marks the key as used. In Aranx, Settings > Sources on the AI visibility page shows when the key was last used.

What the package sends

For each AI request: the page URL without its query (it keeps utm_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.