API reference
Every public method, option, hook, and type. The React hooks and Vue composables are thin wrappers over the same client methods, so anything documented here is reachable from all three packages.
init
init(apiKey: string, overrides?: Partial<IntunixConfig>): Promise<void>Boots the client: starts the session, loads the form catalog, attaches trigger watchers, and starts the event queue. The returned promise resolves once the first catalog load has settled, so triggers are evaluated against real data.
The React and Vue providers call this for you. You only call it directly when using @intunix/core.
Configuration
| Option | Type | Default | Meaning |
|---|---|---|---|
apiKey | string | — | Your public client key. Safe to ship in a bundle. |
register | string[] | 'all' | [] | Which forms this install requests. [] skips the catalog fetch entirely. See Showing forms. |
apiHost | string | https://api.intunix.com | Override only for self-hosted or non-production backends. |
debug | boolean | false | Log why forms were shown or skipped. Invaluable during integration. |
flushIntervalMs | number | 5000 | How often queued events are uploaded. |
maxQueueSize | number | 100 | Events buffered before an early flush is forced. |
urlTriggerDelayMs | number | 600 | Delay before a URL-triggered form appears. |
disableEventApi | boolean | false | Stop uploading events. They still drive triggers locally. |
Showing forms
showForm
showForm(idOrSlug: string, opts?: { context?: ContextData }): Promise<void>Opens a form by slug or id, fetching it on demand if it is not cached. Targeting, eligibility, and cadence are still checked. The promise resolves when the form is enqueued, not when the user finishes with it.
register
register(idOrSlug: string): Promise<() => void>Makes a form's triggers live. Returns a function that unregisters it. Safe to call before init() has finished — it waits.
unregister
unregister(idOrSlug: string): voidStops a form auto-triggering. Does not affect manual shows.
Identity
identify
identify(userId: string, traits?: UserTraits): voidIdentifies the user and moves anonymous records onto their id. Traits are Record<string, string | number | boolean | null> and are held in memory only.
reset
reset(): voidCall on logout. Forgets the user, rotates the anonymous id, ends the session, and clears sticky context. Keeps the catalog and device-level eligibility counters. See Identity & sessions.
Context
setContext(ctx: ContextData | null): void // merges; null clears
clearContext(): voidEvents
track(name: string, properties?: Record<string, unknown>): voidRecords an event. Drives event triggers immediately and locally; the upload is batched.
React hooks
| Hook | Returns | Notes |
|---|---|---|
useIntunix() | IntunixClient | The raw client, for anything without a dedicated hook. |
useExperience(slug) | { show } | Show that form. Accepts per-call context. |
useRegisterForm(slug) | void | Registers on mount, unregisters on unmount. |
useTrack() | (name, props?) => void | Stable callback. |
useIdentify() | (id, traits?) => void | Stable callback. |
useSetContext() | (ctx) => void | Stable callback. |
useReset() | () => void | Stable callback. |
useActiveExperiences() | ActiveExperience[] | Forms currently on screen. For custom rendering. |
Identical names and identical behaviour: useIntunix, useExperience, useRegisterForm, useTrack, useIdentify, useSetContext, useReset, useActiveExperiences. Plus useIntunixContext() when you need the renderer to mount <ExperienceHost> yourself.
Script-tag commands
Every method above is available as a command string on window.intunix:
intunix('init', 'pk_live_xxx', { register: ['nps_q4'] });
intunix('identify', 'user_42', { plan: 'pro' });
intunix('track', 'checkout_completed', { value: 99 });
intunix('setContext', { courseId: 'c-101' });
intunix('showForm', 'nps_q4');
intunix('register', 'exit_survey');
intunix('reset');Types
Cadence
type Wait = number | 'session' | 'never'
interface Cadence {
mode: 'once' | 'every_session' | 'cooldown' | 'always'
cooldown?: {
answered?: Wait
dismissed?: Wait
ignored?: Wait
}
giveUpAfterShows?: number
}Trigger
type Trigger =
| { kind: 'event'; eventName: string; propertyEquals?: Record<string, unknown> }
| { kind: 'url'; match: 'exact' | 'contains' | 'regex'; value: string }
| { kind: 'user'; traitEquals: Record<string, unknown> }
| { kind: 'time'; afterMs: number }
| { kind: 'exit_intent' }
| { kind: 'manual' }Targeting and eligibility
interface TargetingRule {
kind: 'trait' | 'context' | 'url'
key?: string
op: 'eq' | 'neq' | 'in' | 'nin' | 'gt' | 'lt' | 'contains' | 'exists'
value?: unknown
}
interface Eligibility {
minDaysSinceFirstSeen?: number
minSessions?: number
startAt?: string // ISO date-time
endAt?: string // ISO date-time
}Renderer
Implement this only if you are writing a binding for another framework.
interface Renderer {
render(exp: Experience, ctx: RenderContext): Promise<ExperienceResult>
dismiss(experienceId: string): void
}
interface RenderContext {
onImpression: () => void
onResponse: (answer: unknown) => void
onDismiss: () => void
}
interface ExperienceResult {
experienceId: string
outcome: 'responded' | 'dismissed' | 'timeout'
response?: unknown
}The outcome you return selects which cadence wait applies, so report it accurately.