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

# PostHog

> Send usage events from Layer's embedded components to PostHog.

Track how your customers use Layer's embedded accounting features in [PostHog](https://posthog.com/), alongside the rest of your product analytics. Layer's React components emit [UI events](/embedded-components/ui-events) as users interact with them, and you can forward those events to PostHog from a single callback.

## Setup

Subscribe to component events through the `onEvent` callback on `<LayerProvider>` and pass them to PostHog's `capture` method:

```tsx theme={null}
import { LayerProvider } from "@layerfi/components";
import posthog from "posthog-js";

<LayerProvider
  businessId="<layer_business_id>"
  businessAccessToken="<access_token>"
  eventCallbacks={{
    onEvent: (event) => {
      posthog.capture(`layer.${event.type}`, {
        ...event.payload,
        component: event.metadata.component,
      });
    },
  }}
>
  {...}
</LayerProvider>
```

Every event includes a `type`, a typed `payload`, and metadata identifying the component it came from. Prefixing the event name (for example `layer.tasks.month_selected`) keeps Layer activity easy to filter in PostHog.

See the [UI events reference](/embedded-components/ui-events) for the full catalog of events and their payloads.

## What to measure

* **Adoption** - which businesses open accounting features, and which components they use
* **Engagement** - how often customers review transactions, run reports, or complete tasks
* **Funnels** - where customers drop off in flows like account linking or transaction categorization
