Skip to content

feat: migrate analytics from Mixpanel to PostHog - #9

Merged
enzoftware merged 1 commit into
mainfrom
worktree-migrate-to-posthog-analytics
Sep 23, 2026
Merged

enzoftware merged 1 commit into
mainfrom
worktree-migrate-to-posthog-analytics

Conversation

@enzoftware

Copy link
Copy Markdown
Member

Summary

Replaces Mixpanel with PostHog, keeping the existing consent banner.

  • Country: PostHog GeoIP enrichment ($geoip_country_code) at ingestion — no code.
  • Source: native $referrer / utm_* / $initial_*, plus a traffic_source super property (utm_source → referrer host → direct).
  • Taps: autocapture + existing cta_clicked, contact_intent, outbound_link_clicked, language_switched, now with pointer_type (touch/mouse/pen).

Changes

  • src/lib/analytics.ts: posthog-js with opt_out_capturing_by_default, localStorage persistence, session recording/surveys/flags disabled (zero PostHog requests before consent). Public API unchanged.
  • BaseLayout.astro: removed page_viewed, page_exited, page_hidden, page_visible in favor of native $pageview (history_change, works with ClientRouter) and $pageleave.
  • deploy.yml: passes PUBLIC_POSTHOG_KEY / PUBLIC_POSTHOG_HOST repo variables to the build step.
  • Removed mixpanel-browser + types; typed env vars in src/env.d.ts.

Notes

  • Mixpanel likely never ran in prod: PUBLIC_MIXPANEL_TOKEN is a github-pages environment variable, which the build job can't read. That variable can be deleted after merge.
  • Repo variables PUBLIC_POSTHOG_KEY and PUBLIC_POSTHOG_HOST are already set.

Test plan

  • yarn lint, yarn typecheck
  • Local prod build: no PostHog requests before consent; after Accept one $pageview + consent_granted; CTA tap sends cta_clicked + $autocapture; ES→EN navigation sends a single new $pageview
  • After deploy: confirm events in PostHog Activity with $geoip_country_code, traffic_source, pointer_type

🤖 Generated with Claude Code

- Replace mixpanel-browser with posthog-js behind the existing consent flow
  (opted out by default; no PostHog requests before consent).
- Rely on native $pageview/$pageleave (history_change for ClientRouter) and
  autocapture; drop redundant page_viewed/page_exited/page_hidden/page_visible.
- Add traffic_source super property and pointer_type on click events.
- Pass PUBLIC_POSTHOG_KEY/HOST repo variables to the Pages build step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@enzoftware
enzoftware merged commit d24556d into main Sep 23, 2026
1 check 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