> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zopio.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Product Analytics

> Captures product events and metrics.

`zopio` comes with support for product analytics via PostHog — a single platform to analyze, test, observe, and deploy new features.

## Usage

To capture product events, you can use the `analytics` object exported from the `@repo/analytics` package.

Start by importing the `analytics` object for the relevant environment:

```tsx theme={"system"}
// For server-side code
import { analytics } from '@repo/analytics/posthog/server';

// For client-side code
import { analytics } from '@repo/analytics/posthog/client';
```

Then, you can use the `capture` method to send events:

```tsx theme={"system"}
analytics.capture({
  event: 'Product Purchased',
  distinctId: 'user_123',
});
```

## Webhooks

To automatically capture authentication and payment events, we've combined PostHog's Node.js server-side library with Clerk and Stripe webhooks to wire it up as follows:

<Mermaid
  chart={`
graph TD
A[User Action in App] -->|Triggers| B[Auth Webhook]
A -->|Triggers| E[Payments Webhook]
A -->|Client-Side Call| PostHog
B -->|Sends Data| C1[webhooks/auth]
E -->|Sends Data| C2[webhooks/payments]

subgraph API
C1
C2
end

subgraph PostHog
end

C1 -->|Auth Events| PostHog
C2 -->|Payments Events| PostHog
`}
/>

## 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.
