feat: add DevTune AI Traffic integration#1116
Conversation
Adds a new analytics integration that tracks AI bot crawlers and LLM referral traffic on published GitBook documentation sites. - Lightweight ~1KB beacon using navigator.sendBeacon - SPA navigation support (pushState/popstate) for GitBook routing - No cookies, no PII - only page metadata and user agent - XSS prevention via snippet key format validation - Prerender-aware tracking
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5d9c9e2ed
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
String.prototype.replace with a string pattern only substitutes the first match. The comment contained the literal <SNIPPET_KEY> token before the variable assignment, so the runtime variable was left unchanged and beacons were sent with the placeholder.
Summary
Adds a new DevTune AI Traffic analytics integration that tracks AI bot crawlers (GPTBot, ClaudeBot, PerplexityBot, etc.) and LLM referral traffic on published GitBook documentation sites.
How it works
site:script:injectscope to inject a ~1KB tracking beaconfetch_published_scripthandler replaces the snippet key placeholder and returns JavaScriptnavigator.sendBeacon()todevtune.ai/api/v1/llm-traffic/collecthistory.pushStateinterception +popstatelistener (same pattern as the Plausible integration)Architecture
Follows the same pattern as existing analytics integrations (Plausible, Ahrefs, Google Analytics):
gitbook-manifest.yamlconnect-src: devtune.ai), site configsrc/index.tsfetch_published_scripthandler with snippet key validationsrc/script.raw.jsSecurity
/^[a-zA-Z0-9_-]+$/before injection (XSS prevention)script-srcCSP needed — script is fully inlinedconnect-src: devtune.aifor the beacon POSTsessionStorageused instead of cookies (nosite:script:cookiesscope needed)Testing
gitbook checkpassesAbout DevTune
DevTune helps companies understand how AI platforms discover and reference their content. The tracking beacon classifies visitors server-side as AI bot crawlers or LLM-referred users.