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

# PostHog

> Query product analytics and feature flags through the Modem Agent

export const Prompt = ({text, variant = 'accent'}) => {
  const [copied, setCopied] = useState(false);
  const handleCopy = async () => {
    try {
      await navigator.clipboard.writeText(text);
      setCopied(true);
      setTimeout(() => setCopied(false), 2000);
    } catch {}
  };
  const clipboardIcon = <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
            <title>Copy</title>
            <rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
            <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
        </svg>;
  const checkIcon = <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
            <title>Copied</title>
            <polyline points="20 6 9 17 4 12" />
        </svg>;
  const promptIcon = <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style={{
    flexShrink: 0,
    opacity: 0.4
  }}>
            <title>Prompt</title>
            <path d="M20 2H2v20h2V4h16v12H6v2H4v2h2v-2h16V2zM6 7h12v2H6zm8 4H6v2h8z" />
        </svg>;
  return <div className={`prompt prompt-${variant}`} style={{
    marginTop: '12px',
    marginBottom: '12px'
  }}>
            {promptIcon}
            <span className="prompt-text">{text}</span>
            <button className="prompt-copy" onClick={handleCopy} title="Copy to clipboard" type="button">
                {copied ? checkIcon : clipboardIcon}
            </button>
        </div>;
};

The PostHog integration connects your PostHog instance to the Modem Agent. Once connected, the agent can query your product analytics, check feature flag states, review experiment results, and search error tracking data from chat.

<Info>
  PostHog is a query-based integration. Modem does not sync or store PostHog data. Instead, the agent queries your PostHog instance on
  demand when you ask a question.
</Info>

## Prerequisites

* **Admin or Owner** role in your Modem organization
* A [PostHog](https://posthog.com) account with a Personal API key

## Setup

<Steps>
  <Step title="Generate a PostHog API key">
    In PostHog, go to **Settings** → **Personal API Keys** and create a new key. The key should start with `phx_`.

    * [US Cloud settings](https://app.posthog.com/settings/user-api-keys)
    * [EU Cloud settings](https://eu.posthog.com/settings/user-api-keys)
  </Step>

  <Step title="Connect in Modem">
    Go to **Settings** → **Integrations** → **PostHog** in your Modem dashboard.

    1. Select your **Region** (US Cloud or EU Cloud) to match your PostHog instance
    2. Paste your Personal API key
    3. Click **Connect**

    Modem validates the connection by reaching your PostHog instance. If validation fails, double-check your region and API key.
  </Step>

  <Step title="Start asking questions">
    The agent can now query your PostHog data. Try it from the dashboard or [Slack](/docs/integrations/slack).
  </Step>
</Steps>

<Tip>
  Your API key is encrypted at rest and never exposed in API responses. You can test the connection or rotate your key at any time from
  the integration settings page.
</Tip>

## What the Agent Can Access

| Category          | Examples                                                   |
| ----------------- | ---------------------------------------------------------- |
| Product analytics | Event counts, funnels, retention, trends via HogQL queries |
| Feature flags     | Flag states, rollout percentages, targeting filters        |
| Experiments       | A/B test results with statistical significance             |
| Error tracking    | Error rates, types, and affected users                     |

The agent **cannot** access session recordings, PostHog billing settings, or team member information.

## What the Agent Can Do

With PostHog connected, you can ask the agent to:

* Query product usage metrics (signups, active users, conversion rates)
* Check feature flag rollout states and targeting rules
* Analyze A/B experiment results
* Search error tracking data for patterns
* Generate HogQL queries from natural language questions
* Cross-reference PostHog analytics with feedback from your other [data sources](/docs/integrations/overview)

### Example Prompts

These work from the dashboard, Slack DMs, or by mentioning `@modem` in a channel.

Simple:

<Prompt text="How many users signed up last week?" />

<Prompt text="What's the rollout percentage for the new-dashboard feature flag?" />

<Prompt text="Are there any errors spiking today?" />

Advanced:

<Prompt text="Compare signup conversion rates this month vs last month, broken down by day" />

<Prompt text="Which feature flags are at partial rollout? List them with their current percentages." />

<Prompt text="Look at the pricing page A/B test results and tell me if we've reached statistical significance" />

<Prompt text="Cross-reference the top error types in PostHog with recent bug report topics in Modem" />

## Troubleshooting

<AccordionGroup>
  <Accordion title="Connection test fails">
    * Verify your API key starts with `phx_` and hasn't been revoked in PostHog - Confirm you selected the correct region (US or EU)
      matching your PostHog instance - The connection timeout is 15 seconds. If your PostHog instance is behind a slow network, the test
      may time out.
  </Accordion>

  <Accordion title="Agent says PostHog tools aren't available">
    * Check that PostHog is connected in **Settings** → **Integrations** → **PostHog** - Try running **Test Connection** to verify the
      connection is still valid - If your API key was rotated in PostHog, disconnect and reconnect with the new key
  </Accordion>

  <Accordion title="Queries return empty results">
    * Start with a broad query and a recent time range to confirm data exists - Check that the events or properties you're asking about
      match what's in your PostHog project - PostHog Personal API keys can be scoped to a single project. If yours is, the agent can only
      access data within that project.
  </Accordion>

  <Accordion title="Queries are slow">
    PostHog queries over large date ranges or without filters can take time. Ask the agent to narrow the time range or add filters.
    Starting with the last 7 days is a good default.
  </Accordion>
</AccordionGroup>

## Disconnecting

To disconnect PostHog:

1. Go to **Settings** → **Integrations** → **PostHog**
2. Click **Disconnect** and confirm

The agent will no longer be able to query your PostHog data. No data is deleted from PostHog. You can reconnect at any time with the same or a different API key.

## Related

<CardGroup cols={2}>
  <Card title="The Modem Agent" icon="https://mintcdn.com/modem-844d7a4a/Wr2r4IRr97lNQiQb/icons/bot.svg?fit=max&auto=format&n=Wr2r4IRr97lNQiQb&q=85&s=2496f9106cb54fa9f4e27ad1f8f3a171" href="/docs/features/agent" width="22" height="22" data-path="icons/bot.svg">
    See what else the agent can do with your connected tools.
  </Card>

  <Card title="Integrations Overview" icon="https://mintcdn.com/modem-844d7a4a/Wr2r4IRr97lNQiQb/icons/link.svg?fit=max&auto=format&n=Wr2r4IRr97lNQiQb&q=85&s=e774d33588635d44c6c935b78ed55f13" href="/docs/integrations/overview" width="24" height="24" data-path="icons/link.svg">
    All available integrations and how they fit together.
  </Card>
</CardGroup>
