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
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