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

# PostHog

> PostHog provider allows you to query session recordings and analytics data from PostHog.

## Authentication

This provider requires authentication.

* **api\_key**: PostHog API key (required: True, sensitive: True)
* **project\_id**: PostHog project ID (required: True, sensitive: False)

Certain scopes may be required to perform specific actions or queries via the provider. Below is a summary of relevant scopes and their use cases:

* **session\_recording:read**: Read PostHog session recordings (mandatory)
* **session\_recording\_playlist:read**: Read PostHog session recording playlists
* **project:read**: Read PostHog project data (mandatory)

## In workflows

This provider can be used in workflows.

As "step" to query data, example:

```yaml theme={null}
steps:
    - name: Query posthog
      provider: posthog
      config: "{{ provider.my_provider_name }}"
      with:
        query_type: {value}  # Type of query (e.g., "session_recording_domains", "session_recordings")
        hours: {value}  # Number of hours to look back
        limit: {value}  # Maximum number of items to fetch
        # Additional arguments
```

Check the following workflow example:

* [posthog\_example.yml](https://github.com/keephq/keep/blob/main/examples/workflows/posthog_example.yml)

## Provider Methods

The provider exposes the following [Provider Methods](/providers/provider-methods#via-ai-assistant). They are available in the [AI Assistant](/overview/ai-incident-assistant).

* **get\_session\_recording\_domains** Get a list of domains from session recordings within a time period (action, scopes: session\_recording:read, project:read)

  * `hours`: Number of hours to look back (default: 24)
  * `limit`: Maximum number of recordings to fetch (default: 100)
* **get\_session\_recordings** Get session recordings within a time period (action, scopes: session\_recording:read, project:read)

  * `hours`: Number of hours to look back (default: 24)
  * `limit`: Maximum number of recordings to fetch (default: 100)

## Connecting with the Provider

### API Key

To obtain the PostHog API key, follow these steps:

1. Log in to your PostHog account.
2. Navigate to "Project Settings" > "API Keys".
3. Create a new API key or use an existing one.
4. Copy the API key value.

### Project ID

To find your PostHog project ID:

1. Log in to your PostHog account.
2. The project ID is visible in your project settings or in the URL when you're viewing your project.

## Available Methods

The PostHog provider offers the following methods:

### Get Session Recording Domains

Retrieve a list of domains from session recordings within a specified time period.

```yaml theme={null}
- name: get-posthog-domains
  provider:
    config: "{{ providers.posthog }}"
    type: posthog
    with:
      query_type: session_recording_domains
      hours: 24       # Number of hours to look back
      limit: 500      # Maximum number of recordings to fetch
```

### Get Session Recordings

Retrieve session recordings data within a specified time period.

```yaml theme={null}
- name: get-posthog-recordings
  provider:
    config: "{{ providers.posthog }}"
    type: posthog
    with:
      query_type: session_recordings
      hours: 24       # Number of hours to look back
      limit: 100      # Maximum number of recordings to fetch
```

## Example Workflow

Here's an example workflow that tracks domains from PostHog session recordings over the last 24 hours and sends a summary to Slack:

```yaml theme={null}
workflow:
  id: posthog-domain-tracker
  name: PostHog Domain Tracker
  description: Tracks domains from PostHog session recordings over the last 24 hours and sends a summary to Slack.
  triggers:
    - type: manual
    - type: interval
      value: 86400  # Run daily (in seconds)
  steps:
    - name: get-posthog-domains
      provider:
        config: "{{ providers.posthog }}"
        type: posthog
        with:
          query_type: session_recording_domains
          hours: 24
          limit: 500
  actions:
      - name: send-to-slack
        provider:
          config: "{{ providers.slack }}"
          type: slack
          with:
            blocks:
              - type: header
                text:
                  type: plain_text
                  text: "PostHog Session Recording Domains (Last 24 Hours)"
                  emoji: true
              - type: section
                text:
                  type: mrkdwn
                  text: "Found *{{ steps.get-posthog-domains.results.unique_domains_count }}* unique domains across *{{ steps.get-posthog-domains.results.total_domains_found }}* occurrences"
              - type: divider
              - type: section
                text:
                  type: mrkdwn
                  text: "Domains:*"
              - type: section
                text:
                  type: mrkdwn
                  text: "{{#steps.get-posthog-domains.results.unique_domains}}
                    • *{{ . }}*
                    {{/steps.get-posthog-domains.results.unique_domains}}"
              - type: divider
```

## Notes

The PostHog provider requires the following scopes:

* `session_recording:read` - Allows reading session recordings data
* `project:read` - Allows reading project data
* `session_recording_playlist:read` - Optional access to recording playlists

## Useful Links

* [PostHog API Documentation](https://posthog.com/docs/api/overview)
* [PostHog Session Recordings API](https://posthog.com/docs/api/session-recordings)
* [PostHog Projects API](https://posthog.com/docs/api/projects)
