@vetaui/analytics-kit
v0.1.2
Published
Veta analytics kit — provider-agnostic event tracking, page views, A/B tests + consent UI (PostHog / Plausible / GA4 / mock).
Maintainers
Readme
@vetaui/analytics-kit
Provider-agnostic analytics for Next.js. Track events, page views, identify users, run A/B tests, manage consent — all behind a single API that doesn't change when you swap providers.
Install
pnpm add @vetaui/analytics-kit @vetaui/foundations @vetaui/atoms
# Optional — only for the provider you choose:
pnpm add posthog-js # PostHog (browser)
# Plausible / GA4 need no SDK — we use fetch / gtag directly.Configure once
// app/veta.config.ts
import { configureVeta } from "@vetaui/foundations/runtime";
import { posthogAnalyticsStrategy } from "@vetaui/analytics-kit/strategies";
configureVeta({
analytics: posthogAnalyticsStrategy({
apiKey: process.env.NEXT_PUBLIC_POSTHOG_KEY!,
}),
});Use anywhere
import { track, useAnalytics, usePageView, FeatureFlag, TrackEvent } from "@vetaui/analytics-kit";
function CTA() {
return (
<TrackEvent name="cta_signup_clicked" properties={{ position: "hero" }}>
<Button>Start free</Button>
</TrackEvent>
);
}
function Dashboard() {
usePageView("/dashboard");
return (
<FeatureFlag flag="new_dashboard" fallback={<OldDashboard />}>
<NewDashboard />
</FeatureFlag>
);
}Adapters
| Adapter | Events | Page views | Identify | Flags | Experiments | Consent |
|---|---|---|---|---|---|---|
| posthogAnalyticsStrategy | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| plausibleAnalyticsStrategy | ✓ | ✓ | — | — | — | ✓ |
| ga4AnalyticsStrategy | ✓ | ✓ | ✓ | — | — | ✓ |
| mockAnalyticsStrategy | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Screens / hooks read getCapabilities() and gracefully hide unsupported features (no flags shown if your provider doesn't have them).
