FabricFabricSDK
Plugins

PostHog

Capture events, evaluate feature flags, and query cohorts.

Authentication

TypeDefaultDetails
api_keyPersonal 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

PathRiskDescription
events.capturewriteRecord a single analytics event.
events.batchwriteRecord up to 100 events in one call.
featureFlags.evaluatereadEvaluate all feature flags for a user.
cohorts.listreadList cohorts for a project.
cohorts.getreadGet a single cohort.

events.capture

Record a single analytics event.

Input:

FieldTypeRequiredDescription
eventstringEvent name
distinct_idstringUser identifier
propertiesobjectEvent properties
timestampstringISO datetime (defaults to now)

Output: { status: 1 } \| { ok: boolean }

events.batch

Record up to 100 events in one call.

Input:

FieldTypeRequiredDescription
batcharrayArray of event objects (same shape as events.capture)

Output: { status: 1 } \| { ok: boolean }

featureFlags.evaluate

Evaluate feature flags for a user.

Input:

FieldTypeRequiredDescription
distinct_idstringUser identifier
groupsobjectGroup mappings { groupType: groupKey }

Output: { featureFlags: Record<string, boolean \| string> }

cohorts.list

List cohorts for a project.

Input:

FieldTypeDescription
projectIdnumber | stringProject ID (defaults to @current)
limitnumberMax results
offsetnumberPagination offset

Output: { results: Array<{ id: number; name: string; count?: number }> }

cohorts.get

Get a single cohort.

Input:

FieldTypeRequiredDescription
projectIdnumber | stringProject ID
cohortIdnumberCohort 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;
}