PostHog Plugin
Install
pnpm add -D @theholocron/holocron-plugin-posthogCapabilities
| Capability | Token |
|---|---|
analytics | HOLOCRON_POSTHOG_TOKEN (posthog) |
Config
Section titled “Config”providers: { analytics: "posthog",}Or with options:
providers: { analytics: ["posthog", { // EU cloud or self-hosted instance host: "https://eu.posthog.com", }],}Options
Section titled “Options”| Option | Required | Description |
|---|---|---|
host |
No | PostHog instance URL. Defaults to https://app.posthog.com (US cloud). Use https://eu.posthog.com for EU cloud. |
Authentication
Section titled “Authentication”The plugin uses a personal API key — not the project API key. The personal key (phx_*) is org-scoped and can create projects; the project key (phc_*) is the runtime tracking token your app embeds.
- Go to app.posthog.com/settings/user/api-keys
- Click Create personal API key, give it a label (e.g. “Holocron”), and copy it
holocron auth set posthog phx_xxxxxxxxxxxxxxxxxxxxOr via env var:
export HOLOCRON_POSTHOG_TOKEN=phx_...# Also recognized:export POSTHOG_PERSONAL_API_KEY=phx_...What analytics provides
Section titled “What analytics provides”describe()— returns the provider name and required env var keys (NEXT_PUBLIC_POSTHOG_KEY,NEXT_PUBLIC_POSTHOG_HOST)whoami()— verifies the personal API key by fetching the current user and orgensureProject(name)— find or create a PostHog project by name, returning its tracking token (phc_*) and whether it already existed
Example
Section titled “Example”import { createPlugin } from "@theholocron/holocron-plugin-posthog";
const plugin = createPlugin({ cliToken: process.env.HOLOCRON_POSTHOG_TOKEN });const an = plugin.capabilities.analytics();
const { token, alreadyExists } = await an.ensureProject("my-app");// Push NEXT_PUBLIC_POSTHOG_KEY=token and NEXT_PUBLIC_POSTHOG_HOST=https://app.posthog.com// to GitHub Secrets via the secrets capability.console.log(`PostHog key: ${token} (${alreadyExists ? "existing" : "created"})`);