PostHog
Capture events, evaluate feature flags, and query cohorts.
Authentication
| Type | Default | Details |
|---|---|---|
api_key | ✅ | Personal API key (phx_...) for management endpoints |
Event ingestion (events.capture, events.batch) uses the project API key (phc_...) sent in the request body, not as a Bearer header. Management endpoints (featureFlags.evaluate, cohorts.*) use the personal API key as Bearer.
Endpoints
| Path | Risk | Description |
|---|---|---|
events.capture | write | Record a single analytics event. |
events.batch | write | Record up to 100 events in one call. |
featureFlags.evaluate | read | Evaluate all feature flags for a user. |
cohorts.list | read | List cohorts for a project. |
cohorts.get | read | Get a single cohort. |
events.capture
Record a single analytics event.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
event | string | ✅ | Event name |
distinct_id | string | ✅ | User identifier |
properties | object | Event properties | |
timestamp | string | ISO datetime (defaults to now) |
Output: { status: 1 } \| { ok: boolean }
events.batch
Record up to 100 events in one call.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
batch | array | ✅ | Array of event objects (same shape as events.capture) |
Output: { status: 1 } \| { ok: boolean }
featureFlags.evaluate
Evaluate feature flags for a user.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
distinct_id | string | ✅ | User identifier |
groups | object | Group mappings { groupType: groupKey } |
Output: { featureFlags: Record<string, boolean \| string> }
cohorts.list
List cohorts for a project.
Input:
| Field | Type | Description |
|---|---|---|
projectId | number | string | Project ID (defaults to @current) |
limit | number | Max results |
offset | number | Pagination offset |
Output: { results: Array<{ id: number; name: string; count?: number }> }
cohorts.get
Get a single cohort.
Input:
| Field | Type | Required | Description |
|---|---|---|---|
projectId | number | string | Project ID | |
cohortId | number | ✅ | Cohort ID |
Output: { id: number; name: string; count?: number }
Usage
import { createFabric } from "@fabricorg/integrations";
import { posthog } from "@fabricorg/integrations/plugins";
const fabric = createFabric({
plugins: [
posthog({
apiKey: process.env.POSTHOG_PERSONAL_API_KEY,
projectApiKey: process.env.POSTHOG_PROJECT_API_KEY,
host: "https://us.i.posthog.com",
}),
],
});
// Capture an event
await fabric.posthog.api.events.capture({
event: "user_signed_up",
distinct_id: "user_123",
properties: { plan: "pro", source: "invite" },
});
// Evaluate feature flags
const { featureFlags } = await fabric.posthog.api.featureFlags.evaluate({
distinct_id: "user_123",
});
if (featureFlags["new_dashboard_v2"]) {
// Show new dashboard
}Webhooks
PostHog does not expose webhook handlers in this plugin. Event ingestion is push-based via events.capture and events.batch.
Types
interface PosthogEvent {
event: string;
distinct_id: string;
properties?: Record<string, unknown>;
timestamp?: string;
}