# API reference

> Three functions. None of them throw, and calls before init are ignored.

Source: https://shipabase.dev/docs/api

## 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](https://shipabase.dev/docs/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 `init` are ignored.

`example`

```ts
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.

`example`

```ts
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.
