feat: add middleware to track AI coding agent traffic#2499
Open
caffeinum wants to merge 1 commit intolangfuse:mainfrom
Open
feat: add middleware to track AI coding agent traffic#2499caffeinum wants to merge 1 commit intolangfuse:mainfrom
caffeinum wants to merge 1 commit intolangfuse:mainfrom
Conversation
|
@caffeinum is attempting to deploy a commit to the langfuse Team on Vercel. A member of the Team first needs to authorize it. |
|
|
4a0b170 to
6767081
Compare
a9387c7 to
84affc6
Compare
84affc6 to
242b4ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Next.js middleware to detect and track AI coding agents (Claude Code, Codex, OpenCode, etc.) visiting the docs.
Uses the
2027-tracknpm package:How it works
AI coding agents send
Accept: text/markdownheader when fetching documentation - browsers never do this. The middleware detects this signal and sends anonymized events to an external analytics API.Detection signals:
Accept: text/markdown(primary - browsers never send this)axiosuser-agent → Claude Codetext/markdownwithq=weights → OpenCodeChatGPT-Useruser-agent → CodexConfiguration
No configuration needed. The middleware sends events to an external tracking API - no env vars or secrets required in this repo.
Optional: Set
AI_ANALYTICS_ENDPOINT=""to disable tracking entirely.Data collected
Privacy: Events are sent server-side from Vercel Edge. Visitor IP addresses never reach the analytics endpoint.
Dashboard
See collected data: screenshot
Package: https://www.npmjs.com/package/2027-track
Source: https://github.com/caffeinum/ai-docs-analytics
Important
Add middleware in
middleware.tsto track AI coding agents using2027-track, with route configuration and dependency update inpackage.json.middleware.tsto track AI coding agents using2027-trackpackage.Accept: text/markdownheader and specific user-agents.2027-tracktodependenciesinpackage.json.This description was created by
for 6767081. You can customize this summary. It will automatically update as commits are pushed.