# PostHog plugin

The PostHog plugin lets a Vaubaan Gateway mission use PostHog without handing the agent a credential. PostHog product analytics through its REST API: read dashboards, insights, experiments and errors, query events in SQL, save analyses, and change feature flags.

Version `0.1.0` · 5 permissions · 4 macro-actions · 21 tools · 0 gateways run this plugin (over the last 90 days).

## How PostHog is modelled

1 plane, 9 things. The things that exist at the service and how they nest. Every permission is written over these; a resource of an account is one of them, named by its ref.

- **Account** — One account is one PostHog personal API key, in the US or EU region.
  - Plane `analytics` — A PostHog project: its analyses, its feature flags and its users' events.
    - `project` (1; the resource; carries the environment, in the model only) — The resource: one PostHog project, labelled prod / staging by its owner.
      - `dashboard` (1 *) — A dashboard of the project.
      - `insight` (1 *) — A saved analysis of the project and its result.
      - `annotation` (1 *) — A dated note on the project's charts.
      - `experiment` (1 *) — An A/B test of the project.
      - `error-issue` (1 *) — A group of exceptions the product reported.
      - `flag` (1 *) — A feature flag: what the product's users get.
        - `delete` (1) — Verb leaf: the deletion of a flag, a write with its own risk.
      - `events` (1) — Synthetic: the project's raw tables (events, persons, sessions) a SQL query reads.

Marks: 1 exactly one, named; n a finite, known set; * an unknown number, possibly all.

- **Account**: One account is one PostHog personal API key, in the US or EU region.
- **Resource**: Reading analyses, querying raw events (personal data), saving analyses and changing feature flags are four separate permissions; a flag change reaches the product's users at once.
- **Environment**: No permission of this service depends on an environment: each is held once, whatever the resource. Known: none. Carried by: `analytics.project`, in the model only. One resource is one project the key reaches, labelled with an environment by the account's owner.

## What an agent does at PostHog: 4 macro-actions

A mission is made of them: the person ticks the ones the task needs and sets each to a trust level.

1. **Read analytics** — Read dashboards, insights, flags, experiments, annotations and errors. Looking at how the product is used: dashboards and insights with their results, the feature flags and experiments in place, the annotations, the errors users hit. Nothing changes in PostHog; an error may quote what a user typed. (1 permission)
2. **Query events** — Run SQL over the project's raw events and persons. Answering a question no saved insight answers, in SQL over the project's events, persons and sessions. The rows can hold the users' personal data, which then lands in the agent's context. (1 permission)
3. **Save analyses** — Save insights, dashboards and annotations. Keeping what the agent found: a saved insight, a dashboard to gather them, an annotation marking a release on the charts. The team sees them; the product's users never do. (1 permission)
4. **Change feature flags** — Create, change, enable, disable and delete feature flags. Rolling a feature out or back: creating a flag, changing who gets it, turning it on or off, deleting one no code reads any more. Each change reaches the product's users at once. (2 permissions)

## The map

5 permissions of 4 macro-actions, in the four rows of the tree. For the chosen trust level, each cell gives yes, ask me or no, and the quota a day.

Careful ×1: Mild actions run freely; sensitive or costly ones ask first; irreversible ones are left out. Trusting ×3: Up to sensitive actions run freely; costly and irreversible ones ask first. Limits ×3. Autonomous ×10: Everything but irreversible actions runs freely; those ask first. Limits ×10.

yes: runs freely; ask me: ask me first; no: not included. A permission sits in the first row its facts answer: irreversible; costly to undo or unbounded cost; secret or personal data, whole account or bulk, moderate cost, public; otherwise harmless.

### Cannot be repaired

Careful: no. Trusting, Autonomous: ask me.

None.

### Repairable, at a price

Careful, Trusting: ask me. Autonomous: runs freely.

- Change feature flags: Create, change, enable or disable a feature flag `posthog.flag-write`, costly to undo — What the product's users get changes at once, for everyone the release conditions reach; turning the flag back does not undo what they saw. Careful: ask me · 20 a day · Trusting: ask me · 60 a day · Autonomous: yes · 200 a day.
- Change feature flags: Delete a feature flag `posthog.flag-delete`, costly to undo — Code that still reads the flag gets nothing from then on. PostHog keeps it deleted softly, so it can be restored in PostHog. Careful: ask me · 5 a day · Trusting: ask me · 15 a day · Autonomous: yes · 50 a day.

### Worth a look

Careful: ask me. Trusting, Autonomous: runs freely.

- Query events: Query the project's events in SQL `posthog.read-events`, personal data — A SQL query reads any row of the project's raw tables, persons and their properties (emails, names, IP addresses) included, and draws on the key's hourly query budget. Careful: ask me · 200 a day · Trusting: yes · 600 a day · Autonomous: yes · 2,000 a day.

### Harmless

Runs freely at every level.

- Read analytics: Read dashboards, insights, flags, experiments and errors `posthog.read-analytics` — Aggregates and definitions of the project come back to the agent; an error issue may quote what a user typed. Nothing changes at PostHog. Careful: yes · 1,000 a day · Trusting: yes · 3,000 a day · Autonomous: yes · 10,000 a day.
- Save analyses: Save an insight, a dashboard or an annotation `posthog.analysis-write` — The team sees what the agent saved in the project; the product's users never do. Each can be edited or deleted in PostHog. Careful: yes · 100 a day · Trusting: yes · 300 a day · Autonomous: yes · 1,000 a day.

Careful: runs freely 2, ask me first 3.
Trusting: runs freely 3, ask me first 2.
Autonomous: runs freely 5, ask me first 0.

Limits are counted over a mission's period: a day unless its creator picks another, or the mission's whole life for a one-off. The figures here are per day.

## A few calls, classified by the plugin

22 declared calls, run through the plugin's own classifier when this page was built; here one per macro-action. [The 22 calls, as code](https://github.com/vaubaan/gateway/blob/main/plugins/posthog/src/examples.ts).

- `posthog__dashboards-get-all {}`
  - the plugin sees: `posthog.project[12345].dashboard[*].R`
  - the catalog answers: Read dashboards, insights, flags, experiments and errors `posthog.read-analytics`
  - a Careful mission: yes
- `posthog__execute-sql {"query":"select count() from events where event = '$pa…"}`
  - the plugin sees: `posthog.project[12345].events.R`
  - the catalog answers: Query the project's events in SQL `posthog.read-events`
  - a Careful mission: ask me
- `posthog__insight-create {"name":"Weekly signups","query":{"kind":"InsightVizNode","source":{"kind":"TrendsQuery","series":[]}}}`
  - the plugin sees: `posthog.project[12345].insight[*].W`
  - the catalog answers: Save an insight, a dashboard or an annotation `posthog.analysis-write`
  - a Careful mission: yes
- `posthog__create-feature-flag {"key":"new-checkout","active":false}`
  - the plugin sees: `posthog.project[12345].flag[*].W`
  - the catalog answers: Create, change, enable or disable a feature flag `posthog.flag-write`
  - a Careful mission: ask me

## Anything else

A call no permission covers touches `posthog.uncategorized-write` instead of slipping through. No macro-action holds it; a person ticks it knowingly.

| Permission | Risk | Careful ×1 | Trusting ×3 | Autonomous ×10 |
| --- | --- | --- | --- | --- |
| Uncategorized write `posthog.uncategorized-write`: Catch-all for writes without a dedicated entry. No tool of this plugin reaches it; seeing it means an entry is missing. | Repairable, at a price (costly to undo) | ask me · 50 a day | ask me · 150 a day | yes · 500 a day |

## Tools

21 tools. A tool's permissions depend on its arguments, so a mission is made of the macro-actions above, not of tools.

| Tool | What it does | Usually touches |
| --- | --- | --- |
| `posthog__dashboards-get-all` | List dashboards | `posthog.read-analytics` |
| `posthog__dashboard-get` | Read a dashboard | `posthog.read-analytics` |
| `posthog__insights-list` | List insights | `posthog.read-analytics` |
| `posthog__insight-get` | Read an insight | `posthog.read-analytics` |
| `posthog__insight-query` | Run an insight | `posthog.read-analytics` |
| `posthog__feature-flag-get-all` | List feature flags | `posthog.read-analytics` |
| `posthog__feature-flag-get-definition` | Read a feature flag | `posthog.read-analytics` |
| `posthog__experiment-list` | List experiments | `posthog.read-analytics` |
| `posthog__experiment-get` | Read an experiment | `posthog.read-analytics` |
| `posthog__annotations-list` | List annotations | `posthog.read-analytics` |
| `posthog__query-error-tracking-issues-list` | List error issues | `posthog.read-analytics` |
| `posthog__query-error-tracking-issue` | Read an error issue | `posthog.read-analytics` |
| `posthog__execute-sql` | Query events in SQL | `posthog.read-events` |
| `posthog__insight-create` | Save an insight | `posthog.analysis-write` |
| `posthog__dashboard-create` | Create a dashboard | `posthog.analysis-write` |
| `posthog__annotation-create` | Add an annotation | `posthog.analysis-write` |
| `posthog__create-feature-flag` | Create a feature flag | `posthog.flag-write` |
| `posthog__update-feature-flag` | Change a feature flag | `posthog.flag-write` |
| `posthog__feature-flag-enable` | Turn a feature flag on | `posthog.flag-write` |
| `posthog__feature-flag-disable` | Turn a feature flag off | `posthog.flag-write` |
| `posthog__delete-feature-flag` | Delete a feature flag | `posthog.flag-write`, `posthog.flag-delete` |

## Connecting an account

**1 of 3 · a key you create and paste** — `personal API key`

A personal API key the person creates at PostHog and pastes once; nobody declares anything beforehand.

**Scopes** — The organization, with every scope below, plus User and Project: Read. This gateway gives a mission only the projects and permissions it names; User and Project: Read list the projects to choose from.

1. Sign in to PostHog as the user the agents will act as.
2. **Settings › Personal API keys › Create a personal API key** — Open your personal API keys and start a new key; on EU Cloud, open the same page on eu.posthog.com. ([open](https://us.posthog.com/settings/user-api-keys))
3. **Organization & project access › Scopes** — Name it, choose the organization, and give every scope below the access shown, plus User and Project: Read.
4. Create the key, copy it, and paste it here with your region. PostHog shows it once.

| Permission at PostHog | Access |
| --- | --- |
| Dashboard | read-write |
| Insight | read-write |
| Feature flag | read-write |
| Experiment | read |
| Annotation | read-write |
| Error tracking | read |
| Query | read |

Where: [https://us.posthog.com/settings/user-api-keys](https://us.posthog.com/settings/user-api-keys)

Expiry: PostHog personal API keys do not expire: delete the key on the Personal API keys page to end this account.

The connect page asks: Personal API key (secret), Region.

The service's documentation: [https://posthog.com/docs/api/personal-api-keys](https://posthog.com/docs/api/personal-api-keys)

Disconnecting: In PostHog, open Settings, then Personal API keys, and delete the key this gateway was given.

## Health

0 gateways run this plugin (over the last 90 days).

No version of this plugin has reported a call or a gateway yet.

A version is marked validated by the community with at least 200 reports and a success rate of at least 90 %, over the last 90 days; a gateway shows that mark on the accounts of this service. The figures are refreshed at most hourly ([what they mean](/plugins/health)). It is a community signal, not a security guarantee.

Calls are counted over the last 90 days from the instances that share plugin health. Gateways are counted over the same window among the instances that also share usage statistics, so they are a lower bound. The success rate leaves out calls refused for a rejected credential: a revoked token is the user's configuration, not the plugin.

## Links

- [Connect a PostHog account](/plugins/posthog#connect)
- [How PostHog is modelled](https://github.com/vaubaan/gateway/blob/main/docs/handbook/services/posthog.md)
- [The catalog, as code](https://github.com/vaubaan/gateway/blob/main/plugins/posthog/src/risk-catalog.yaml)
- [The plugin source](https://github.com/vaubaan/gateway/tree/main/plugins/posthog)
- The page: [/plugins/posthog](/plugins/posthog)
