feat: add PostHog analytics integration - #82
Conversation
✅ Deploy Preview for trainpace ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| ErrorProne | 19 high |
🟢 Metrics 0 complexity · 0 duplication
Metric Results Complexity 0 Duplication 0
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Generated-By: PostHog Code Task-Id: 66b2f920-2441-47c3-9e9a-ec8b383c0c8d
872fca1 to
ee34e51
Compare
Without VITE_PUBLIC_POSTHOG_KEY/HOST, main.tsx's new dev-mode guard throws on every page load in CI, since the e2e webServer runs `npm run dev` without them set. Generated-By: PostHog Code Task-Id: 66b2f920-2441-47c3-9e9a-ec8b383c0c8d
|
Codacy Static Code Analysis shows This looks like a Codacy-isolated-analysis artifact rather than a real type error: |

Summary
This PR ships the PostHog setup wizard's latest pass over the existing
posthog-jsintegration (v1.288.0 → v1.410.10 within the same^1.288.0semver range) invite-project:src/main.tsx— guards the existingPostHogProviderwrap: renders the app without it (skipping the crash-when-missing-env-var mentioned below) instead of unconditionally passing possibly-emptyapiKey/api_host, and throws a loud dev-only error ifVITE_PUBLIC_POSTHOG_KEY/VITE_PUBLIC_POSTHOG_HOSTare unset.src/features/auth/AuthContext.tsx— adds an account-switch guard:posthog.reset()now fires when a different Firebase uid logs in, not just on logout, so identity doesn't get merged across accounts.src/components/elevationfinder/GpxUploader.tsx—gpx_route_uploadedsrc/features/elevation/components/RouteDashboard.tsx—route_analysis_settings_updatedsrc/features/fuel/components/AIPersonalization.tsx—fuel_ai_advice_requestedsrc/features/fuel/components/FuelPlannerV2.tsx—fuel_plan_calculatedsrc/features/fuel/hooks/useFuelPlanPersistence.ts—fuel_plan_savedsrc/features/goals/components/OnboardingFlow.tsx—onboarding_completedsrc/features/pace-calculator/components/PaceCalculatorV2.tsx—pace_calculatedsrc/features/pace-calculator/hooks/usePacePlanPersistence.ts—pace_plan_savedsrc/features/plan/components/PlanInputForm.tsx—training_plan_generatedsrc/features/plan/hooks/useSavePlan.ts—training_plan_saved.env.example— documentsVITE_PUBLIC_POSTHOG_KEY/VITE_PUBLIC_POSTHOG_HOST.package-lock.json— refreshesposthog-jsand its transitive deps within the existingpackage.jsonversion range.Insights and dashboards created
How to verify
vite-project/.env).main.tsxenv-var guard.pace_calculated,fuel_plan_calculated,gpx_route_uploaded,onboarding_completed, etc.) arrive within a minute.Environment variables
TrainPace deploys to Vercel (per
vercel.json/CLAUDE.md), which keeps environment variables in its dashboard rather than in a file committed to this repo, so I could not set these up automatically.VITE_PUBLIC_POSTHOG_KEYandVITE_PUBLIC_POSTHOG_HOSTwere already in use before this PR (seesrc/main.tsxonmain), so production should already have them configured — this is a reminder to confirm, not a first-time setup:VITE_PUBLIC_POSTHOG_KEYphc_vM6GXKZAALbMzPuM8vfRsD2zaayjC7VL48kqLMWFZJNQVITE_PUBLIC_POSTHOG_HOSThttps://us.i.posthog.comTo confirm or set them:
Setting environment variables via a local CLI
Created with PostHog Code