GenerateSaaS

Analytics

Wire one or more analytics providers through config.analytics, gate the cookie-dropping ones behind consent, and dispatch events with useAnalytics().

config.analytics (in @repo/config) enables web analytics: provider scripts render client-side, plus a small server seam (@repo/analytics) for webhook-driven events. A provider sub-key turns it on - there is no enabled flag, and a generated project ships no config.analytics key.

Providers

The two tiers differ only by GDPR cookie use: consent-required providers wait for the cookie banner, privacy-focused ones load immediately.

ProviderKeyConfig valueConsent required?
Google Analytics 4google{ measurementId, ads? }Yes
PostHogposthog{ publicKey, host, uiHost? }Yes
Umamiumami{ websiteId, host }No
Plausibleplausible{ domain?, host? }No
OpenPanelopenpanel{ clientId, trackScreenViews? }No
DataFastdatafast{ websiteId, domain }No
Ahrefsahrefs{ key }No
Vercel AnalyticsverceltrueNo
  • vercel is a boolean; every other provider takes an object whose keys are all required unless marked ?.
  • vercelSpeedInsights: true additionally mounts Vercel Speed Insights (Web Vitals only) - no cookies, no identity, no consent gate.
  • enableInDev (default false) loads scripts in local development; flip it on only while wiring a provider.

All analytics keys are public (publishable) and ship to the browser by design. Never paste a secret API key into config.

PostHog analytics and PostHog error reporting are separate clients - the errorTracking instance never waits for consent, so a declining visitor's crashes still reach you.

Tracking calls

One useAnalytics() hook fans every dispatch out to every enabled provider, consent-required ones only once consent is granted.

const { track, trackRevenue, identify, reset } = useAnalytics();

track("signup_completed", { plan: "pro" }); // custom event → all providers
trackRevenue(29, "USD", { orderId: "ord_123" }); // revenue event → all providers
identify(userId, { email }); // user → consent-aware subset (see below)
reset(); // clear identity → called automatically on sign-out
MemberSignatureReaches
track(event, properties?)Every enabled provider
trackRevenue(amount, currency, options?)Every enabled provider; options takes orderId, email, and any extra event properties
identify(userId, traits?)Umami, OpenPanel, DataFast, GA, PostHog; traits and attribution wait for consent when a banner is required
reset()Providers that store an identity (GA, PostHog, OpenPanel) - clears it
isEnabled / needsConsentBanner / hasConsentflagsRead-only state for gating your own UI
grantConsent / revokeConsent()Drive the consent decision from your own controls
  • Client-side only - every function no-ops on the server and when no provider is enabled.
  • identify fires automatically for authenticated users, reset on sign-out or expiry; call them yourself only for custom flows.
  • GA receives the pseudonymous user_id only - Google prohibits PII, so identify traits are dropped there.
  • trackRevenue auto-fills email from the session for DataFast and fires automatically on the return from a checkout.

On this page