Skip to main content
The SDK is a singleton — initialize once, import the same orwel instance anywhere. Every method is safe to call after init().

Methods

MethodSignatureDescription
initinit(config)Initialize with your API key + options. Call once, client-side.
tracktrack(code, props?)Record a named event.
identifyidentify(traits?)Attach identity / traits to the visitor.
conversionconversion(code, props?)Record a conversion / lead.
sessionsession(props?)Update per-session state. Returns { success, sessionId }.
monitormonitor(opts?)Enable performance / error / network monitoring.
formform(el, opts?)Track interactions on a form element.
experimentexperiment(key, variants)Assign a sticky A/B variant + auto-fire exposure.
flushflush()Force-send queued events (rarely needed).

init options

OptionTypeDescription
apiKeystringWorkspace ingest key (from env). Required.
autoMonitorbooleanJS errors, console errors, failed network requests, and navigation/resource performance timings.
autoEventDetectionbooleanAuto page_view / click / scroll / element_visible.
debugbooleanVerbose console logging (dev only).
import orwel from 'orwel';

orwel.init({
  apiKey: process.env.NEXT_PUBLIC_ORWEL_KEY,
  autoMonitor: true,
  autoEventDetection: true,
  debug: process.env.NODE_ENV !== 'production',
});

Validation

The SDK validates inputs at runtime and throws descriptive errors:
  • apiKey must start with orwel_ and be ≥ 20 characters.
  • Event codes match ^[a-z0-9_]{1,50}$.
  • Emails inside properties / traits are validated — pass valid addresses or omit the field.
One instance. Never re-initialize. Import orwel from your wrapper module everywhere; the visitor + session are managed for you and persist across reloads.