Skip to content

feat: add DevTune AI Traffic integration#1116

Merged
addisonschultz merged 8 commits intoGitbookIO:mainfrom
devtunehq:feat/devtune-integration
Mar 24, 2026
Merged

feat: add DevTune AI Traffic integration#1116
addisonschultz merged 8 commits intoGitbookIO:mainfrom
devtunehq:feat/devtune-integration

Conversation

@subsy
Copy link
Copy Markdown
Contributor

@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

Preview

DevTune AI Traffic Analytics

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
Copy Markdown

changeset-bot Bot commented Feb 11, 2026

⚠️ No Changeset found

Latest commit: 82f596c

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
Copy Markdown

@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".

Comment thread integrations/devtune/src/index.ts
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.
@subsy
Copy link
Copy Markdown
Contributor Author

subsy commented Feb 20, 2026

@taranvohra @addisonschultz any chance someone could please take a look at this - have a mutual customer waiting on the integration. Thanks so much 🙏

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 3, 2026

Open in StackBlitz

bun add https://pkg.pr.new/GitbookIO/integrations/@gitbook/api@1116

commit: 82f596c

@subsy
Copy link
Copy Markdown
Contributor Author

subsy commented Mar 3, 2026

Hi — I wasn't able to self-publish this integration because the site:script:inject scope is restricted for third-party publishers. Could the GitBook team publish it and provide the install link? Happy to help with anything else needed to get this across the line.

@addisonschultz
Copy link
Copy Markdown
Collaborator

Hi @subsy I’m having a look at this and sent you an email - would love to get access to this feature in DevTune so I can test this out and help get this published!

@subsy
Copy link
Copy Markdown
Contributor Author

subsy commented Mar 4, 2026

Hi @subsy I’m having a look at this and sent you an email - would love to get access to this feature in DevTune so I can test this out and help get this published!

Thanks @addisonschultz just replied to your mail and got you set up 🙌

@addisonschultz addisonschultz merged commit f682876 into GitbookIO:main Mar 24, 2026
6 of 7 checks passed
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.

2 participants