feat(docs): add server-side tracking for AI crawlers#2129
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
efc735d to
a55b9e3
Compare
- Add middleware.ts at project root (proper Vercel Routing Middleware) - Runs server-side on every request before page loads - Only tracks requests from known AI crawlers (GPTBot, ClaudeBot, etc.) - Sends 'crawler_pageview' event to PostHog with crawler_name - No layout changes needed - middleware intercepts all requests - Uses matcher to skip static assets Amp-Thread-ID: https://ampcode.com/threads/T-019bc889-197d-71fb-b47e-990975761a3a Co-authored-by: Amp <amp@ampcode.com>
a55b9e3 to
d8570b5
Compare
o-az
approved these changes
Jan 16, 2026
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jan 16, 2026
## Summary AI crawlers (GPTBot, ClaudeBot, PerplexityBot, etc.) don't execute JavaScript, so they're invisible to PostHog's client-side tracking. This PR adds a server-side tracking pixel that captures crawler visits. ## Changes - **`docs/api/track-crawler.ts`** - Vercel serverless function that: - Serves a 1x1 transparent GIF - Logs user-agent to PostHog server-side - Detects 30+ known AI crawler patterns - Tags events with `is_crawler: true` and `crawler_name` - **`docs/layout.tsx`** - Adds invisible tracking pixel to every page ## Tracked Crawlers GPTBot, OAI-SearchBot, ChatGPT-User, ClaudeBot, anthropic-ai, PerplexityBot, Google-Extended, Googlebot, Bingbot, Amazonbot, CCBot, Bytespider, YouBot, and more. ## PostHog Event - **Event name:** `server_pageview` - **Properties:** `is_crawler`, `crawler_name`, `user_agent`, `path` ## Query Example ```sql SELECT crawler_name, count() as visits FROM events WHERE event = 'server_pageview' AND properties.is_crawler = true GROUP BY crawler_name ORDER BY visits DESC ``` Co-authored-by: Amp <amp@ampcode.com>
gakonst
added a commit
that referenced
this pull request
Jan 17, 2026
slop This reverts commit b34123f.
legion2002
pushed a commit
that referenced
this pull request
Jan 19, 2026
slop This reverts commit b34123f.
legion2002
pushed a commit
that referenced
this pull request
Jan 19, 2026
This reverts commit 9a4c422.
legion2002
pushed a commit
that referenced
this pull request
Jan 19, 2026
slop This reverts commit b34123f.
legion2002
pushed a commit
that referenced
this pull request
Jan 19, 2026
This reverts commit 9a4c422.
legion2002
pushed a commit
that referenced
this pull request
Jan 21, 2026
This reverts commit 9a4c422.
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
AI crawlers (GPTBot, ClaudeBot, PerplexityBot, etc.) don't execute JavaScript, so they're invisible to PostHog's client-side tracking.
This PR adds a server-side tracking pixel that captures crawler visits.
Changes
docs/api/track-crawler.ts- Vercel serverless function that:is_crawler: trueandcrawler_namedocs/layout.tsx- Adds invisible tracking pixel to every pageTracked Crawlers
GPTBot, OAI-SearchBot, ChatGPT-User, ClaudeBot, anthropic-ai, PerplexityBot, Google-Extended, Googlebot, Bingbot, Amazonbot, CCBot, Bytespider, YouBot, and more.
PostHog Event
server_pageviewis_crawler,crawler_name,user_agent,pathQuery Example