> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/integrations/catalog/posthog.md).

# PostHog

PostHog is a product analytics platform. Connect to run HogQL queries, read person records, evaluate feature flags, capture events, and annotate charts.

### Connectors

Choose the connector that matches your authentication method. The options below use the names shown in StackAI.

| Connector | Authentication   |
| --------- | ---------------- |
| PostHog   | API key or token |

#### PostHog

Connect to PostHog to run HogQL queries, read persons, evaluate feature flags, capture events, and annotate charts.

**Set up in PostHog**

1. Prepare the PostHog account or service that the workflow will access. Grant access to the required resources and operations.
2. **Personal API Key:** A PostHog personal API key, which starts with 'phx\_'. Create one under Settings, then Personal API keys. Grant the scopes the actions you plan to run need: user:read and project:read for the project dropdown, query:read for Run Query, person:read for List Persons, and annotation:write for Create Annotation. Add organization:read as well if the key spans several organizations.
3. **Region:** The PostHog deployment that holds your project. US Cloud serves us.posthog.com, EU Cloud serves eu.posthog.com. A key created on one cloud region is rejected by the other. Choose Self-hosted to point the integration at your own domain.
4. **Project API Key (Optional):** A PostHog project API key, which starts with 'phc\_'. Found under Settings, then Project, then Project API key. Only Capture Event and Evaluate Feature Flags use it, because those endpoints do not accept a personal API key. Leave empty if you do not run those two actions.

**Set up in StackAI**

1. Open **Settings → Connections**, add a connection, and select **PostHog**.
2. Enter the credentials and connection details in the fields below.
3. Save the connection and check its connection status. Select this saved connection when configuring an action or feature that uses it.

**Connection fields**

| StackAI field              | Required                 | What to enter                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| -------------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Personal API Key           | Yes                      | A PostHog personal API key, which starts with 'phx\_'. Create one under Settings, then Personal API keys. Grant the scopes the actions you plan to run need: user:read and project:read for the project dropdown, query:read for Run Query, person:read for List Persons, and annotation:write for Create Annotation. Add organization:read as well if the key spans several organizations. [Provider instructions](https://posthog.com/docs/api/personal-api-keys). |
| Region                     | Optional / as applicable | The PostHog deployment that holds your project. US Cloud serves us.posthog.com, EU Cloud serves eu.posthog.com. A key created on one cloud region is rejected by the other. Choose Self-hosted to point the integration at your own domain.                                                                                                                                                                                                                          |
| Self-Hosted Host           | Optional / as applicable | Base URL of a self-hosted PostHog instance, including the scheme, for example <https://posthog.internal.example.com>. Required when Region is Self-hosted and ignored otherwise, because both cloud regions have fixed hostnames.                                                                                                                                                                                                                                    |
| Project API Key (Optional) | Optional / as applicable | A PostHog project API key, which starts with 'phc\_'. Found under Settings, then Project, then Project API key. Only Capture Event and Evaluate Feature Flags use it, because those endpoints do not accept a personal API key. Leave empty if you do not run those two actions. [Provider instructions](https://posthog.com/docs/api/capture).                                                                                                                      |

#### Verify the connection

Check that the connection is healthy. Then run a read operation against a resource the connected account can access. A successful connection check confirms authentication; it does not guarantee permission for every action.

If access is denied, check the credential or OAuth permissions, the selected account or environment, and access to the specific resource. Update expired credentials or reconnect after permissions change.

### Use an action

1. Add the required **PostHog** action to the workflow.
2. Select a connection when the action requests one.
3. Complete the required fields. Use the reference picker when a value comes from another workflow step.
4. Run the workflow and inspect the action’s output. Check the result before using it in a later step.

### Actions

#### Run Query

Run a HogQL query and return the resulting rows.

**Inputs**

| Field          | Type            | Required | Description                                                                                                                         |
| -------------- | --------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| Project        | select (string) | Yes      | Select the project to query, or type its numeric ID. Options load from the selected connection.                                     |
| HogQL Query    | string          | Yes      | HogQL query to execute. HogQL is PostHog's SQL dialect.                                                                             |
| Cache Behavior | select (string) | No       | How PostHog should use cached results for this query. Available values: blocking, force\_blocking, force\_cache. Default: blocking. |

**Outputs**

| Field          | Type    | Description                                             |
| -------------- | ------- | ------------------------------------------------------- |
| Rows           | array   | Result rows, each an array of values ordered by column. |
| Columns        | array   | Column names, ordered to match each row.                |
| Records        | array   | Result rows as objects keyed by column name.            |
| Row Count      | integer | Number of rows returned.                                |
| Has More       | boolean | Whether PostHog truncated the result set.               |
| Resolved Query | string  | The query as PostHog resolved it.                       |
| Result Message | string  | Human-readable result summary.                          |

#### Capture Event

Send a product event to PostHog.

**Inputs**

| Field       | Type     | Required | Description                                                        |
| ----------- | -------- | -------- | ------------------------------------------------------------------ |
| Event Name  | string   | Yes      | Name of the event to record.                                       |
| Distinct ID | string   | Yes      | Identifier of the person the event belongs to.                     |
| Properties  | object   | No       | Additional event properties to store alongside the event.          |
| Timestamp   | datetime | No       | When the event happened. Defaults to the time PostHog receives it. |

**Outputs**

| Field          | Type    | Description                                    |
| -------------- | ------- | ---------------------------------------------- |
| Accepted       | boolean | Whether PostHog accepted the payload.          |
| Event Name     | string  | Name of the event that was sent.               |
| Distinct ID    | string  | Person identifier the event was attributed to. |
| Result Message | string  | Human-readable result summary.                 |

#### List Persons

List persons in a project, filtered by identity or properties.

**Inputs**

| Field            | Type            | Required | Description                                                                                                 |
| ---------------- | --------------- | -------- | ----------------------------------------------------------------------------------------------------------- |
| Project          | select (string) | Yes      | Select the project to read persons from, or type its numeric ID. Options load from the selected connection. |
| Search           | string          | No       | Match persons by email text or by exact distinct ID.                                                        |
| Email            | string          | No       | Return only the person with this exact email address.                                                       |
| Distinct ID      | string          | No       | Return only the person carrying this distinct ID.                                                           |
| Property Filters | array           | No       | Filter persons by their stored properties.                                                                  |
| Limit            | integer         | No       | Maximum persons to return, up to 500.                                                                       |
| Offset           | integer         | No       | Number of persons to skip before returning results.                                                         |

**Outputs**

| Field          | Type    | Description                                          |
| -------------- | ------- | ---------------------------------------------------- |
| Persons        | array   | The persons that matched.                            |
| Person Count   | integer | Number of persons returned on this page.             |
| Total Count    | integer | Total persons matching the filters across all pages. |
| Has More       | boolean | Whether another page of persons is available.        |
| Result Message | string  | Human-readable result summary.                       |

#### Evaluate Feature Flags

Evaluate feature flags for a person and read the resulting values.

**Inputs**

| Field             | Type   | Required | Description                                                                 |
| ----------------- | ------ | -------- | --------------------------------------------------------------------------- |
| Distinct ID       | string | Yes      | Identifier of the person to evaluate flags for.                             |
| Flag Key          | string | No       | Report one flag in the top-level outputs. Leave empty to return every flag. |
| Person Properties | object | No       | Property values used to match flag release conditions.                      |
| Groups            | object | No       | Group keys to evaluate group-targeted flags against.                        |
| Group Properties  | object | No       | Property values for each group, used to match conditions.                   |

**Outputs**

| Field          | Type    | Description                                                    |
| -------------- | ------- | -------------------------------------------------------------- |
| Flags          | object  | Every flag PostHog evaluated, keyed by flag key.               |
| Enabled Flags  | array   | Keys of the flags that resolved to enabled.                    |
| Enabled        | boolean | Whether the requested flag is on. False when no key was given. |
| Variant        | string  | Variant assigned for the requested flag, when it has variants. |
| Flag Found     | boolean | Whether the requested flag key exists in the project.          |
| Result Message | string  | Human-readable result summary.                                 |

#### Create Annotation

Add a dated annotation that marks an event on PostHog charts.

**Inputs**

| Field   | Type            | Required | Description                                                                                                               |
| ------- | --------------- | -------- | ------------------------------------------------------------------------------------------------------------------------- |
| Project | select (string) | Yes      | Select the project to annotate, or type its numeric ID. Options load from the selected connection.                        |
| Content | textarea        | Yes      | Text shown on the annotation marker.                                                                                      |
| Date    | datetime        | No       | Point in time the marker sits on. Defaults to now.                                                                        |
| Scope   | select (string) | No       | Whether the annotation shows on one project or across the org. Available values: Project, Organization. Default: project. |

**Outputs**

| Field          | Type    | Description                                 |
| -------------- | ------- | ------------------------------------------- |
| Annotation ID  | integer | Numeric ID of the created annotation.       |
| Date           | string  | Point in time the annotation was placed at. |
| Scope          | string  | Scope the annotation was created with.      |
| Result Message | string  | Human-readable result summary.              |

### Important behavior

Actions that create, update, send, or delete data can change the connected service. Review their inputs before running them. A retry can repeat an operation; consider this when configuring retries for actions that change data.

The catalog lists the fields and capabilities available in the supplied provider definition. Availability can also depend on your deployment and organization’s Feature Access settings.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/integrations/catalog/posthog.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
