Analytics (GA + PostHog)
The kit ships both Google Analytics 4 and PostHog built in. There is no code to add — each one turns on the moment you set its environment variable, and stays completely off (no script, no network calls) when the variable is unset. You can run either, both, or neither.
Because the kit is a single-page app, both integrations are wired to track client-side route changes as page views — not just the first load.
Google Analytics 4
-
Create a GA4 property at analytics.google.com and copy its Measurement ID (format
G-XXXXXXXXXX). -
Add it to
.env:VITE_GA_MEASUREMENT_ID=G-XXXXXXXXXX -
Restart the dev server.
That is all. The kit loads gtag.js, initializes it, and sends a page_view on every route change
automatically. You do not need to edit app/routes/__root.tsx or paste any <script> tags —
that is handled by the bundled GoogleAnalytics component.
PostHog
-
Create a project at posthog.com and copy its Project API Key (format
phc_…). -
Add it to
.env:VITE_POSTHOG_KEY=phc_xxxxxxxxxxxxxxxxxxxxxxxx # VITE_POSTHOG_HOST=https://us.i.posthog.com -
Restart the dev server.
VITE_POSTHOG_HOST defaults to https://us.i.posthog.com. For an EU project, set it to
https://eu.i.posthog.com.
Once configured, the kit automatically:
- captures
$pageviewon every route change, - identifies the signed-in user (so events tie to a real person),
- and sends
user_logged_inanduser_signed_upevents from the auth flow.
The PostHog library is loaded lazily and never reaches the browser bundle when VITE_POSTHOG_KEY
is unset.
Cookie consent
Google Analytics sets cookies. In many jurisdictions (EU, UK, several US states) this requires a cookie consent banner before you load it. The kit does not ship a consent banner — add one (Cookiebot, Osano, or a custom banner) before launching to those audiences. PostHog can be configured cookieless; see its privacy docs if that matters for you.
Verify
- GA4: build and deploy (GA4 does not log
localhost). Visit the live site; your visit appears in GA4 → Realtime within a minute. Use DebugView to inspect individual events. - PostHog: works on
localhost. Open the site, then check Activity in PostHog — pageviews and (after signing in)user_logged_inshould show up within seconds.
Useful docs: