Skip to main content

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 reference
Any events tracked before init() is called are automatically queued and sent as soon as init() finishes.

Signature

Parameters

Example (Vue / Vanilla JS)

With environment variables

What it does

  1. Validates and stores your API key
  2. Enables automatic page view tracking if autoTrackPageViews: true
  3. Restores a previously identified userId from localStorage (persists across page refreshes)
  4. Retries any events that were queued offline in a previous session
  5. Logs [analytiq] Initialized successfully. to the browser console

Important rules

Call init() only once — at the root entry file of your app. Don’t call it inside components or on every page.
  • Call it before any track(), identify(), or batchTrack() calls
  • If called a second time, it is safely ignored (guarded against double-init)
  • React / Next.js users: Use useAnalytiq() instead — it handles init() for you

TypeScript