Skip to content

PostHog

Emulated PostHog analytics API for local development and testing.

Included now:

  • Event capture and per-project event reads (/api/projects/:id/events)
  • /api/projects and /api/users/@me
  • OAuth 2.0: dynamic client registration (/oauth/register), authorize/token
  • RFC 8414 and OIDC discovery documents
  • OpenAPI subset at /openapi.json
Terminal window
# From this repo (after `bun install && bun run build`)
bun packages/emulate/dist/index.js --service posthog
# Or from the published package
npx @pleaseai/emulate --service posthog

A single service starts on the base port (default 4000). Use -p <port> to change it. When started alongside other services, ports are assigned sequentially from the base port.

Use a seeded project API token (or a personal API key) as a bearer token.

Terminal window
curl http://localhost:4000/api/projects \
-H "Authorization: Bearer phc_test_token"
Terminal window
curl "http://localhost:4000/api/projects/1/events" \
-H "Authorization: Bearer phc_test_token"

Add a posthog: section to emulate.config.yaml (or pass --seed <file>):

posthog:
users:
- email: dev@example.com
name: Developer
projects:
- name: Demo Project
api_token: phc_test_token
events:
- event: $pageview
distinct_id: user-1
oauth_clients:
- client_id: posthog-client
client_secret: posthog-secret
redirect_uris:
- http://localhost:3000/callback