Skip to content

Add PostHog analytics integration#630

Merged
bokelley merged 2 commits into
mainfrom
bokelley/posthog-analytics
Jan 5, 2026
Merged

Add PostHog analytics integration#630
bokelley merged 2 commits into
mainfrom
bokelley/posthog-analytics

Conversation

@bokelley

@bokelley bokelley commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add PostHog analytics for tracking user behavior (rage clicks, dead clicks, session recordings, heatmaps)
  • Configure via optional POSTHOG_API_KEY environment variable
  • Inject PostHog script into all HTML pages when configured
  • Identify logged-in users for session filtering
  • Mask all form inputs except search fields for privacy

Configuration

Variable Required Default Description
POSTHOG_API_KEY No - PostHog project API key (enables analytics when set)
POSTHOG_HOST No https://us.i.posthog.com PostHog API host URL

Test plan

  • Set POSTHOG_API_KEY in environment
  • Visit site and verify PostHog script loads in browser dev tools
  • Check PostHog dashboard for incoming events
  • Verify session recordings capture page interactions
  • Confirm logged-in users are identified by user ID

🤖 Generated with Claude Code

bokelley and others added 2 commits January 5, 2026 12:07
Adds PostHog for tracking user behavior:
- Rage clicks detection
- Dead clicks detection
- Session recordings (with masked inputs)
- Heatmaps
- Performance metrics

Configuration:
- POSTHOG_API_KEY (optional) - enable by setting your project API key
- POSTHOG_HOST (default: https://us.i.posthog.com)

When a user is logged in, they're identified by their user ID for
filtering sessions. The script respects DNT (Do Not Track) browser
settings and masks all form inputs except search fields.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Frontend:
- Enable capture_exceptions option
- Add window.onerror handler for uncaught errors
- Add onunhandledrejection handler for promise rejections

Backend:
- Add posthog-node package for server-side tracking
- Create server/src/utils/posthog.ts utility with:
  - captureEvent() for custom events
  - captureException() for error tracking
  - identifyUser() for user identification
  - shutdownPostHog() for graceful shutdown
- Add global Express error middleware to capture unhandled errors
- Flush PostHog events on server shutdown

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bokelley bokelley merged commit b05a75e into main Jan 5, 2026
6 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.

1 participant