Plugins
Custom analytics plugins that extend the analytics plugin API.
posthogPlugin
PostHog integration for the analytics library.
Install
pnpm add posthog-js
Usage
import Analytics from 'analytics'
import { posthogPlugin } from '@repo/analytics'
export const analytics = Analytics({
app: 'my-app',
plugins: [
posthogPlugin({
apiKey: 'phc_...',
initSettings: {
api_host: 'https://eu.i.posthog.com',
person_profiles: 'identified_only',
},
}),
],
})
Config
| Option | Type | Description |
|---|---|---|
apiKey | string | PostHog project API key |
initSettings | posthog.init config | Passed directly to posthog.init() -- see PostHog docs |
Tracked methods
The plugin implements:
- page -- captures
$pageviewwith title, url, path, hash, search, and referrer - track -- captures custom events with
user_idand all properties - identify -- calls
posthog.identify(userId) - loaded -- returns
truewhenwindow.posthogexists (SSR-safe)