TypeScript
Use inferred event types and exported SDK type helpers
Infer event types from defineEvents()
import { defineEvents, p, createClient } from '@realanalytics/sdk'
export const events = defineEvents({
signup_completed: {
properties: {
plan: p.enum(['free', 'pro', 'enterprise'] as const).required(),
source: p.string(),
},
},
purchase_completed: {
properties: {
amount: p.number().required(),
currency: p.string().required(),
},
},
})
const analytics = createClient<typeof events>({
publicKey: 'pk_live_xxx',
})Compile-time safety
// ✅ valid
analytics.track('signup_completed', { plan: 'pro' })
// ❌ invalid plan literal
analytics.track('signup_completed', { plan: 'starter' })
// ❌ missing required property
analytics.track('purchase_completed', { currency: 'USD' })Reusable typed client
// lib/analytics.ts
import { createClient } from '@realanalytics/sdk'
import { events } from '../analytics/events'
export const analytics = createClient<typeof events>({
publicKey: process.env.NEXT_PUBLIC_REALANALYTICS_KEY!,
})Useful exported types
import type {
ClientConfig,
ClientEventPayload,
RetryConfig,
AutocaptureOptions,
DashboardConfig,
WidgetConfig,
BuiltinEvents,
BuiltinEventName,
} from '@realanalytics/sdk'Dashboard typing
import type { DashboardConfig } from '@realanalytics/sdk'
const dashboard: DashboardConfig = {
id: 'overview',
title: 'Overview',
defaultDateRange: 'last_30_days',
controls: [],
widgets: [],
}