Skip to content

feat(docs): add server-side tracking for AI crawlers#2129

Merged
o-az merged 1 commit intomainfrom
liam/track-ai-crawlers
Jan 17, 2026
Merged

feat(docs): add server-side tracking for AI crawlers#2129
o-az merged 1 commit intomainfrom
liam/track-ai-crawlers

Conversation

@snario
Copy link
Copy Markdown
Contributor

@snario snario commented 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

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

@snario snario requested a review from o-az January 16, 2026 21:24
@vercel
Copy link
Copy Markdown

vercel bot commented Jan 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
tempo-docs Ready Ready Preview, Comment Jan 16, 2026 9:29pm

Request Review

- 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>
@snario snario added this pull request to the merge queue 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>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 16, 2026
@o-az o-az added this pull request to the merge queue Jan 17, 2026
Merged via the queue into main with commit b34123f Jan 17, 2026
16 of 17 checks passed
@o-az o-az deleted the liam/track-ai-crawlers branch January 17, 2026 01:48
gakonst added a commit that referenced this pull request Jan 17, 2026
gakonst added a commit that referenced this pull request Jan 17, 2026
gakonst added a commit that referenced this pull request Jan 17, 2026
legion2002 pushed a commit that referenced this pull request Jan 19, 2026
legion2002 pushed a commit that referenced this pull request Jan 19, 2026
legion2002 pushed a commit that referenced this pull request Jan 19, 2026
legion2002 pushed a commit that referenced this pull request Jan 19, 2026
legion2002 pushed a commit that referenced this pull request Jan 21, 2026
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