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

# PostHog Analytics

> Track user behavior and conversion funnels

## Setup

1. Create account at [posthog.com](https://posthog.com)
2. Get project API key
3. Add to `.env.local`:

```bash theme={null}
NEXT_PUBLIC_POSTHOG_KEY=phc_xxxxx
NEXT_PUBLIC_POSTHOG_HOST=https://app.posthog.com
```

## Events Tracked

### Store Views

```typescript theme={null}
posthog.capture('store_view', {
  store_id: store.id,
  subdomain: store.subdomain
});
```

### Product Views

```typescript theme={null}
posthog.capture('product_view', {
  product_id: product.id,
  product_name: product.title,
  price: product.price
});
```

### Order Events

* `order_started`
* `order_details_filled`
* `order_placed`
* `order_abandoned`

## Funnels

Track conversion funnels:

```
Store View → Product View → Cart Add → Checkout → Order Placed
```

<Info>
  PostHog is used in both web store (buyer analytics) and iOS app (seller analytics).
</Info>
