MonoStack
Concepts

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

OptionTypeDescription
apiKeystringPostHog project API key
initSettingsposthog.init configPassed directly to posthog.init() -- see PostHog docs

Tracked methods

The plugin implements:

  • page -- captures $pageview with title, url, path, hash, search, and referrer
  • track -- captures custom events with user_id and all properties
  • identify -- calls posthog.identify(userId)
  • loaded -- returns true when window.posthog exists (SSR-safe)

On this page