Skip to content

feat(docs): add PostHog analytics with search tracking#24

Merged
adiman9 merged 2 commits intomainfrom
docs-posthog-analytics
Jan 21, 2026
Merged

feat(docs): add PostHog analytics with search tracking#24
adiman9 merged 2 commits intomainfrom
docs-posthog-analytics

Conversation

@adiman9
Copy link
Contributor

@adiman9 adiman9 commented Jan 21, 2026

Summary

  • Add PostHog analytics to docs site for user behavior tracking
  • Track search queries with debouncing to understand what users are looking for
  • Set up Vercel proxy rewrites (/ingest) to bypass ad-blockers (~30-50% data loss prevention)

Changes

File Purpose
docs/src/components/PostHog.astro PostHog initialization with EU region
docs/src/components/overrides/Head.astro Injects PostHog into every page
docs/src/components/overrides/Search.astro Tracks search queries, results, clicks
docs/vercel.json Proxy rewrites for ad-blocker bypass
docs/astro.config.mjs Registers Head and Search overrides

Events Tracked

Event When Properties
docs_search_opened User opens search modal page
docs_search User types query (debounced 1s, 3+ chars) query, has_results, page
docs_search_no_results Query returns no results query, page
docs_search_result_click User clicks a search result query, result_url, page
Autocaptured Page views, clicks, scroll (automatic)

Setup Required

Add environment variable in Vercel:

PUBLIC_POSTHOG_KEY=phc_your_key_here

Testing

  • Localhost auto-detects and uses direct EU API (no proxy needed)
  • Production uses /ingest proxy through Vercel rewrites

- Add PostHog analytics component with EU region support
- Track search queries, results, and clicks via custom Search override
- Set up Vercel proxy rewrites to bypass ad-blockers
- Support PUBLIC_POSTHOG_KEY environment variable
- Auto-detect localhost for direct API access during development
@vercel
Copy link

vercel bot commented Jan 21, 2026

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

Project Deployment Review Updated (UTC)
hyperstack-docs Ready Ready Preview, Comment Jan 21, 2026 3:28am

Request Review

- Add tsconfig.json with Starlight types
- Add env.d.ts for pagefind types
- Fix localhost detection for PostHog API host
- Remove unused @ts-expect-error directive
@adiman9
Copy link
Contributor Author

adiman9 commented Jan 21, 2026

Implements HYP-105

Copy link
Contributor

@vimmotions vimmotions left a comment

Choose a reason for hiding this comment

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

Looks good to me. Never used PH so cool to see it in action.

@adiman9 adiman9 merged commit 3d680ac into main Jan 21, 2026
8 checks passed
@adiman9 adiman9 deleted the docs-posthog-analytics branch January 21, 2026 14:14
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