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
pnpm add @minihog/coreimport { 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.
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.
Consent & identity
Use optOutByDefault when analytics should wait for permission. Opt-out stops collection and replay. A request already delivered cannot be recalled.
const analytics = createMiniHog('phc_your_public_token', {
optOutByDefault: true,
respectDnt: true
});
analytics.optIn();
import { identify, group } from '@minihog/core/identity';
identify(analytics, 'account-123', { plan: 'pro' });
group(analytics, 'organization', 'team-456');
analytics.reset(); // Return to an anonymous identity on logout.
analytics.optOut(); // Clears the queue and persisted MiniHog identity. Standard PostHog identity and session data migrate from the default storage keys. MiniHog persists its own state in localStorage, with memory fallback. Use persistence: 'memory' to avoid durable state.
Nuxt integration
Choose start: 'ready', 'idle', or 'manual'. Manual startup keeps the analytics implementation unloaded until start(). The controller is safe during SSR.
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.
| Import | API | Purpose |
|---|---|---|
@minihog/core | createMiniHog | Events, sessions, persistence, consent |
/browser | startBrowserCapture | Pageviews, SPA navigation, autocapture |
/identity | identify, group, alias | People and group properties |
/flags | createFeatureFlags | Variants, payloads, exposure events |
/heatmaps | startHeatmaps | Click, movement, rage, and dead-click points |
/surveys | getSurveys, surveySent | Headless definitions and responses |
/errors | captureException | Manual and global error capture |
/web-vitals | startWebVitals | CLS, FCP, INP, and LCP |
/replay | startSessionReplay | DOM recordings with rrweb |
/replay-console | consoleRecordingPlugin | Console recording for replay |
/replay-network | networkTimingPlugin | Resource and navigation timings |
/remote-config | getRemoteConfig | JSON project settings |
Replay & web vitals
Import the extensions you use. If your package manager does not install peers automatically, add the required peers explicitly.
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
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.