API reference: init, trackEvent, flush
Three functions. None of them throw, and calls before init are ignored.
init(appKey, options?)#
Starts the SDK. Call it once, on the client, at app startup. An invalid key logs one warning, and every later call does nothing.
| Option | Type | Default | |
|---|---|---|---|
host | string | https://api.shipabase.dev | API host (proxies) |
appVersion | string | "" | Your app version, for version breakdowns |
isDebug | boolean | auto | true on localhost / 127.0.0.1 or when NODE_ENV is development. Debug events are hidden unless you turn on the debug toggle |
flushInterval | number | 5000 | Milliseconds between batch sends |
pageviews | boolean | true | Browser: send page_viewed on load and on every route change. See Page views |
trackEvent(eventName, props?)#
eventName: 1–64 characters from[A-Za-z0-9_.:-].props: at most 20 keys of 40 characters. Values: string (≤ 200), finite number or boolean.- Never throws. Calls made before
initare ignored.
trackEvent("invoice_sent", { plan: "pro", count: 3 });trackPageview(path?)#
Records a page or screen view (page_viewed). In the browser it happens automatically; call it yourself with hash routers or in React Native. Without a path, the current page is used.
trackPageview("/settings");flush(): Promise<void>#
Sends queued events now. It resolves even when the network fails. Useful in short-lived Node processes, before exit.
Delivery#
- Events are sent in batches of up to 25 (and about 20 KB): every
flushInterval, and right away when 25 events are queued. - When the tab is hidden or closed, the queue is sent with
navigator.sendBeacon. - On a network error or a 5xx, the batch is retried once.
- The queue holds at most 100 events; the oldest are dropped first.
Related guides
DocsAutomatic page view tracking for SPAs and mobile screensPages are tracked automatically in the browser. Screens in mobile apps take one line.DocsEvent props without personal data: limits and the PII guardAdd context to events without collecting personal data.DocsCheck if analytics is workingSee your first event, and fix it when nothing shows up.DocsNode.js analytics for API servers, CLIs, scripts and cronsTrack events from API servers, CLIs, scripts and cron jobs.