--- title: Product Analytics description: Captures product events and metrics. product: Analytics type: reference summary: How product analytics captures events and metrics. related: - /en/docs/packages/analytics/web --- # Product Analytics kreogen has support for product analytics via PostHog — a single platform to analyze, test, observe, and deploy new features. PostHog is an optional integration. If `NEXT_PUBLIC_POSTHOG_KEY` and `NEXT_PUBLIC_POSTHOG_HOST` are not set, the `analytics` export will be `undefined` and client-side initialization will be skipped. ## Usage To capture product events, you can use the `analytics` object exported from the `@kreogen/analytics` package. Since analytics is optional, use optional chaining when calling methods. Start by importing the `analytics` object for the relevant environment: ```tsx // For server-side code import { analytics } from '@kreogen/analytics/server'; // For client-side code import { analytics } from '@kreogen/analytics'; ``` Then, you can use the `capture` method to send events: ```tsx analytics?.capture({ event: 'Product Purchased', distinctId: 'user_123', }); ``` ## Server-side events Authentication events are captured in-process. Better Auth runs database and organization hooks inside the application, so sign-ups, sign-ins, organization creation and membership changes reach PostHog without an inbound webhook — no signature verification, no delivery latency, and no retry semantics to reason about. Payment events still arrive by webhook, because Stripe is genuinely external. |Client-side call| PostHog A -->|Better Auth hook| B[packages/auth/lib/analytics] A -->|Stripe webhook| C[api/webhooks/payments] subgraph PostHog end B -->|Auth events| PostHog C -->|Payment events| PostHog `} /> Every tracking call is individually guarded: a PostHog outage can never fail a sign-up. ## Reverse Proxy We've also setup Next.js rewrites to reverse proxy PostHog requests, meaning your client-side analytics events won't be blocked by ad blockers. --- For a semantic overview of all documentation, see [/sitemap.md](/sitemap.md) For an index of all available documentation, see [/llms.txt](/llms.txt)