Overview
init() sets up the SDK with your API key. It must be called once, at the very start of your app.
React / Next.js users: You don’t need to call
init() directly. The useAnalytiq() hook calls it automatically. See the useAnalytiq referenceinit() is called are automatically queued and sent as soon as init() finishes.
Signature
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | string | Yes | Your project’s API key from the Settings page. Starts with pk_live_ |
options.autoTrackPageViews | boolean | Optional | If true, automatically fires a page_view event on every URL/route change via the History API. Default: false |
options.debug | boolean | Optional | If true, logs SDK actions to the browser console. Useful during development. Default: false |
options.host | string | Optional | Override the Analytiq backend URL. Leave blank — defaults to the production server automatically. |
Example (Vue / Vanilla JS)
With environment variables
- React / Vite
- Next.js
What it does
- Validates and stores your API key
- Enables automatic page view tracking if
autoTrackPageViews: true - Restores a previously identified
userIdfromlocalStorage(persists across page refreshes) - Retries any events that were queued offline in a previous session
- Logs
[analytiq] Initialized successfully.to the browser console
Important rules
- Call it before any
track(),identify(), orbatchTrack()calls - If called a second time, it is safely ignored (guarded against double-init)
- React / Next.js users: Use
useAnalytiq()instead — it handlesinit()for you