Intunix

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

code
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

OptionTypeDefaultMeaning
apiKeystringYour public client key. Safe to ship in a bundle.
registerstring[] | 'all'[]Which forms this install requests. [] skips the catalog fetch entirely. See Showing forms.
apiHoststringhttps://api.intunix.comOverride only for self-hosted or non-production backends.
debugbooleanfalseLog why forms were shown or skipped. Invaluable during integration.
flushIntervalMsnumber5000How often queued events are uploaded.
maxQueueSizenumber100Events buffered before an early flush is forced.
urlTriggerDelayMsnumber600Delay before a URL-triggered form appears.
disableEventApibooleanfalseStop uploading events. They still drive triggers locally.

Showing forms

showForm

code
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

code
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

code
unregister(idOrSlug: string): void

Stops a form auto-triggering. Does not affect manual shows.

Identity

identify

code
identify(userId: string, traits?: UserTraits): void

Identifies the user and moves anonymous records onto their id. Traits are Record<string, string | number | boolean | null> and are held in memory only.

reset

code
reset(): void

Call 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

code
setContext(ctx: ContextData | null): void   // merges; null clears
clearContext(): void

Events

code
track(name: string, properties?: Record<string, unknown>): void

Records an event. Drives event triggers immediately and locally; the upload is batched.

React hooks

HookReturnsNotes
useIntunix()IntunixClientThe raw client, for anything without a dedicated hook.
useExperience(slug){ show }Show that form. Accepts per-call context.
useRegisterForm(slug)voidRegisters on mount, unregisters on unmount.
useTrack()(name, props?) => voidStable callback.
useIdentify()(id, traits?) => voidStable callback.
useSetContext()(ctx) => voidStable callback.
useReset()() => voidStable callback.
useActiveExperiences()ActiveExperience[]Forms currently on screen. For custom rendering.
Vue composables

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:

code
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

code
type Wait = number | 'session' | 'never'

interface Cadence {
  mode: 'once' | 'every_session' | 'cooldown' | 'always'
  cooldown?: {
    answered?: Wait
    dismissed?: Wait
    ignored?: Wait
  }
  giveUpAfterShows?: number
}

Trigger

code
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

code
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.

code
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.