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

# Connect with PostHog

> Connect a PostHog Cloud project to Hyperline and import product events into usage-based billing using a scheduled HogQL query data loader.

You can connect a PostHog Cloud project to Hyperline and use its product events as usage data. Hyperline runs a [HogQL query](https://posthog.com/docs/sql) on a schedule and imports the results as events.

<Note>
  Hyperline supports PostHog Cloud projects hosted in the EU or US. The connection uses read-only query access.
</Note>

## Connect your PostHog project

1. Go to **Settings** > **Integrations** in Hyperline.
2. Find **PostHog** and select **Connect**.
3. Sign in to PostHog if prompted.
4. Select one PostHog project and authorize Hyperline.

After authorization, Hyperline automatically creates a PostHog connection on the [data loaders page](https://app.hyperline.co/app/events/loaders). You do not need to copy an API key or project ID.

## Create a data loader

1. Go to the [data loaders page](https://app.hyperline.co/app/events/loaders).
2. Select **New data loader**.
3. Choose the PostHog connection created for your project.
4. Enter the event type that Hyperline should use for the imported records.
5. Choose how often Hyperline should refresh the data.
6. Enter a HogQL query and preview the results.

Your query must return these fields with the exact casing:

* `id` — a stable, unique identifier for the record
* `customerId` — the Hyperline customer ID or external ID associated with the record
* `timestamp` — when the event occurred

For example, the following query imports PostHog events named `api_call`:

```sql theme={null}
SELECT
  uuid AS id,
  distinct_id AS "customerId",
  timestamp,
  properties.endpoint AS endpoint
FROM events
WHERE event = 'api_call'
```

In this example, each PostHog `distinct_id` must match a Hyperline customer ID or external ID. You can select additional event properties when you need them for aggregation or pricing.

<Tip>
  Filter the query to include only billable events and properties. This keeps each refresh focused on the data Hyperline needs for billing.
</Tip>

7. Check that the preview contains the expected customers and records.
8. Save the data loader.

Hyperline imports the query results on the selected schedule. For more information about customer matching, record updates, and required fields, see [Pull usage data with connectors](./usage-data-with-connectors).

## Next steps

* [Configure aggregators](./aggregators)
* [Explore usage consumption](./explore-usage-consumption)
* [View customer usage](./customer-usage)
