# Sending data from PostHog

Source: https://kirora.io/docs/api/posthog

Send PostHog's people and events to Kirora through a destination in PostHog's data pipeline.

If your team tracks product usage in PostHog, PostHog can send its people and events to
Kirora as they happen, through a destination in PostHog's data pipeline. Contacts and
events arrive as Kirora data, ready for segments and journeys.

## Add the destination

In PostHog, open **Data pipeline → Destinations**, create a **HTTP Webhook** destination
and set:

| Setting | Value |
| --- | --- |
| Webhook URL | `https://api.kirora.io/segment/v1/track` |
| Method | `POST` |
| Headers | `Authorization: Bearer <your Kirora API key>` and `Content-Type: application/json` |
| Filters | The events you want in Kirora, and **person property `email` is set** |

Use this JSON body:

```json
{
  "type": "track",
  "event": "{event.event}",
  "userId": "{event.distinct_id}",
  "messageId": "{event.uuid}",
  "timestamp": "{event.timestamp}",
  "properties": "{event.properties}",
  "context": { "traits": { "email": "{person.properties.email}" } }
}
```

To keep contacts' details up to date, add a second destination filtered to `$identify`,
posting to `https://api.kirora.io/segment/v1/identify` with this body:

```json
{
  "type": "identify",
  "userId": "{event.distinct_id}",
  "messageId": "{event.uuid}",
  "timestamp": "{event.timestamp}",
  "traits": {
    "email": "{person.properties.email}",
    "firstName": "{person.properties.first_name}",
    "lastName": "{person.properties.last_name}"
  }
}
```

These are Segment's tracking API paths and format, which Kirora reads as Segment's own
libraries send them. How each call becomes Kirora data is in
[Sending data from Segment](https://kirora.io/docs/api/segment#how-calls-become-kirora-data).

## How PostHog data becomes Kirora data

- **The contact**: PostHog's `distinct_id` becomes the contact's `externalId`, so it
  should be your own ID for the user (what you pass to `posthog.identify()`). The email
  finds a contact you imported by email instead of creating a second one.
- **Events** keep their PostHog name and properties. Pick the events journeys and
  segments need; PostHog's own events (`$pageview`, `$autocapture`) are rarely worth
  sending, and a workspace tracks at most 1,000 distinct event names.
- **Anonymous users** are skipped: Kirora keeps no anonymous contacts. The filter on
  `email` sends only people you can message.
- **Consent** is never read from PostHog: a contact it creates has no marketing consent
  until your app records it through the contacts API or a form.
- **Retries**: PostHog's event `uuid` is the call's `messageId`, so a retried event is
  recorded once.

## Requirements

- **The key**: make it from **Integrations → PostHog** in Kirora (or with `source:
  "posthog"`), with `contacts:write` and `events:write`. Its events are then labelled
  `posthog`, and the PostHog card shows its last activity.
- **Plan**: the integrations feature (Starter and above). On Free, each call is refused
  with 403 `PLAN_FEATURE_UNAVAILABLE`. Each tracked event counts against the plan's
  monthly event allowance.
- **Limits**: 32 KB a call; event properties up to 16 KB. `{event.properties}` includes
  what PostHog adds itself (`$geoip_*`, `$browser`, and `$set` and `$set_once` copies),
  which can make up most of an event. To keep only your own, list them instead:
  `"properties": { "plan": "{event.properties.plan}", "seats": "{event.properties.seats}" }`.

## Next steps

- [Events](https://kirora.io/docs/api/events): how tracked events are named and stored
- [IDs and identity](https://kirora.io/docs/api/identifiers): how a PostHog user becomes a contact
- [Webhooks](https://kirora.io/docs/api/webhooks): Kirora's message activity, signed, for PostHog or anything else