Overview
@saflib/vendors-posthog wires PostHog as the production backend for @saflib/analytics-service on Node services.
What this package provides
configureAnalytics()— idempotent startup helper; registersPosthogAnalyticsServiceor falls back to in-memory when the API key is missing/mockorNODE_ENV=testPosthogAnalyticsService— implementsAnalyticsService; captures server-side product events via PostHog's HTTP APIgetAnalyticsClient()/resetAnalyticsForTests— read or reset the configured client
Integration
Call configureAnalytics() at process startup before handling requests. In development the in-memory buffer from @saflib/analytics-http is used when PostHog is not configured.
Environment (see env.schema.json):
POSTHOG_PROJECT_API_KEY— project API key; omit, leave empty, or set tomockfor in-memoryPOSTHOG_PROJECT_HOST— ingest host (defaults tohttps://us.i.posthog.com)
Browser PostHog loading and feature flags live in @saflib/vendors-posthog-client.