Browser Quickstart
Add Xaiku tracking to any website with vanilla JavaScript.
Prerequisites
- A Xaiku account with a public key (
pk_*) - A experiment created in the Xaiku dashboard
1. Install
- npm
- pnpm
- yarn
npm install @xaiku/browser
pnpm add @xaiku/browser
yarn add @xaiku/browser
2. Initialize the SDK
import xaiku from '@xaiku/browser'
const sdk = xaiku({
pkey: 'pk_your_public_key',
experimentIds: ['your_experiment_id'],
})
Options
| Option | Type | Default | Description |
|---|---|---|---|
pkey | string | — | Your public key (required). Starts with pk_. |
experimentIds | string[] | [] | Experiment IDs to fetch variants for. |
store | object | { name: 'localStorage' } | Storage backend. Options: localStorage, sessionStorage, cookie, memory. |
dev | boolean | false | Use local development API (localhost:3000). |
proxyApiUrl | string | — | Custom API URL for proxied setups. |
onReport | function | null | Callback called with event buffer on each flush. |
3. Track your first event
const { events } = sdk.track
events.trackView()
events.trackClick({ label: 'signup-button' })
events.trackConversion({ value: 49.99 })
Next steps
- Tracking Events — full list of tracking functions
- A/B Testing — variant weights and selection
- Configuration — storage, proxying, and more
- @xaiku/browser reference — full API