Get started

A few imports.
Your analytics.

MiniHog sends events to your existing PostHog project. Use the TypeScript client directly or let the Nuxt module handle startup and proxying.

Installation

Terminal
pnpm add @minihog/core
analytics.ts
import { createMiniHog } from '@minihog/core';
import { startBrowserCapture } from '@minihog/core/browser';

const analytics = createMiniHog('phc_your_public_token', {
  apiHost: 'https://eu.i.posthog.com',
  personProfiles: 'identified_only'
});

startBrowserCapture(analytics);

Use a public project token. Direct ingestion defaults to US Cloud; the example uses EU Cloud. A relative apiHost requires a proxy. The Nuxt module provides one.

Capture events

Register shared properties once, and pass event-specific properties to capture.

TypeScript
analytics.capture('project_opened', { slug: 'my-project' });
analytics.register({ app_version: '1.0' });
analytics.registerOnce({ first_visit_source: 'docs' });
await analytics.flush();

// Remove listeners, stop extensions, and flush pending events.
await analytics.destroy();

Events are batched automatically. Use flush() to send pending events immediately. See delivery and teardown for queue limits, retries, and cleanup.

Nuxt integration

Choose start: 'ready', 'idle', or 'manual'. Manual startup keeps the analytics implementation unloaded until start(). The controller is safe during SSR.

plugins/analytics.client.ts
export default defineNuxtPlugin({
  dependsOn: ['minihog'],
  setup() {
    const analytics = useMiniHog();
    onNuxtReady(async () => {
      await loadContent().catch(showFallback);
      await analytics.start();
    });
  }
});

The module provides a same-origin proxy and requires a Node-based Nitro deployment. See the Nuxt module reference for all options and proxy routes. Replace loadContent and showFallback with your application's loading and error handlers.

Enable extensions through webVitals, heatmaps, replay, consoleRecording, and networkTiming. These default to false. Remote settings must also permit collection.

Entry points

Each extension is imported explicitly. Unused imports can be removed by your bundler. Prefix short paths below with @minihog/core.

ImportAPIPurpose
@minihog/corecreateMiniHogEvents, sessions, persistence, consent
/browserstartBrowserCapturePageviews, SPA navigation, autocapture
/identityidentify, group, aliasPeople and group properties
/flagscreateFeatureFlagsVariants, payloads, exposure events
/heatmapsstartHeatmapsClick, movement, rage, and dead-click points
/surveysgetSurveys, surveySentHeadless definitions and responses
/errorscaptureExceptionManual and global error capture
/web-vitalsstartWebVitalsCLS, FCP, INP, and LCP
/replaystartSessionReplayDOM recordings with rrweb
/replay-consoleconsoleRecordingPluginConsole recording for replay
/replay-networknetworkTimingPluginResource and navigation timings
/remote-configgetRemoteConfigJSON project settings

Replay & web vitals

Import the extensions you use. If your package manager does not install peers automatically, add the required peers explicitly.

TypeScript
import { startSessionReplay } from '@minihog/core/replay';
import { consoleRecordingPlugin } from '@minihog/core/replay-console';
import { networkTimingPlugin } from '@minihog/core/replay-network';
import { startWebVitals } from '@minihog/core/web-vitals';

startWebVitals(analytics);
const replay = startSessionReplay(analytics, {
  maskAllInputs: true,
  plugins: [consoleRecordingPlugin(), networkTimingPlugin(analytics.apiHost)]
});
replay.stop();

Inputs are masked by default. Block content with .ph-no-capture, .ph-sensitive, or [data-private]. Console output may contain application data. Network diagnostics capture URLs and timings, without headers or bodies.

See the replay guide for masking, sampling, canvas recording, and delayed loading.

Feature flags

TypeScript
import { createFeatureFlags } from '@minihog/core/flags';

const flags = createFeatureFlags(analytics);
await flags.reload();
const variant = flags.getFeatureFlag('new-checkout');
const payload = flags.getFeatureFlagPayload('new-checkout');

Unknown flags return undefined. Access records a deduplicated exposure event. Identity and group changes invalidate the previous result and reload flags. In a Nuxt app, install @minihog/core directly before importing its helpers.

Compatibility

MiniHog targets modern browsers with ES2022, Web Crypto, and Fetch. It adds no polyfills. The Nuxt module supports Nuxt 4 and Node-based Nitro servers.

Migrating from posthog-js requires updating calls to MiniHog's separate imports and camelCase API. Check supported features and compatibility before migrating.

Complete core reference ↗