Skip to content

feat: add DevTune AI Traffic integration#1116

Open
subsy wants to merge 2 commits intoGitbookIO:mainfrom
devtunehq:feat/devtune-integration
Open

feat: add DevTune AI Traffic integration#1116
subsy wants to merge 2 commits intoGitbookIO:mainfrom
devtunehq:feat/devtune-integration

Conversation

@subsy
Copy link

@subsy subsy commented Feb 11, 2026

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

  • Uses site:script:inject scope to inject a ~1KB tracking beacon
  • fetch_published_script handler replaces the snippet key placeholder and returns JavaScript
  • Beacon fires via navigator.sendBeacon() to devtune.ai/api/v1/llm-traffic/collect
  • SPA navigation handled via history.pushState interception + popstate listener (same pattern as the Plausible integration)
  • No cookies, no PII — only page URL, title, user agent, and referrer are transmitted

Architecture

Follows the same pattern as existing analytics integrations (Plausible, Ahrefs, Google Analytics):

File Purpose
gitbook-manifest.yaml Declares scopes, CSP (connect-src: devtune.ai), site config
src/index.ts fetch_published_script handler with snippet key validation
src/script.raw.js Tracking beacon with SPA navigation + dedup + prerender support

Security

  • Snippet key validated against /^[a-zA-Z0-9_-]+$/ before injection (XSS prevention)
  • No script-src CSP needed — script is fully inlined
  • Only connect-src: devtune.ai for the beacon POST
  • sessionStorage used instead of cookies (no site:script:cookies scope needed)

Testing

  • gitbook check passes
  • Manually tested beacon firing on initial load and SPA navigation
  • Verified deduplication (same path does not double-fire)
  • Verified back/forward navigation triggers beacons
  • Verified invalid/missing snippet key produces no script injection

About 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.

  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
@changeset-bot
Copy link

changeset-bot bot commented Feb 11, 2026

⚠️ No Changeset found

Latest commit: ec9f2fd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant