Who is this for? Web developers adding analytics to game websites, landing pages, or web apps. Works with any framework (React, Next.js, Svelte, vanilla JS).
session_start, session_end) and attribution (UTM parameters, click IDs, referrer) are handled automatically. Page views are tracked by calling page() on each route change, and in-game moments like progressions, purchases, and sign-ups are triggered by your code when they happen.
What You Need
- An Immutable Hub account with a project (get started here)
- A publishable key from your project settings (API keys guide)
Installation
- npm
- yarn
- pnpm
Quick Start
Set consent
The SDK uses a three-tier consent model (At
'none', 'anonymous', 'full'). Call setConsent after the user accepts your cookie banner or privacy prompt.'anonymous', page views and events are tracked but identify() and alias() calls are dropped. At 'full', all methods are available. See the Data Dictionary for what is collected at each level.Track page views
Call
page() on each route change. The first call in each session includes attribution parameters.Track events
Log player actions with
track(). The SDK ships with predefined events for common player actions (purchases, sign-ups, progression, wishlist actions, and more) that give you typed properties and autocomplete. You can also pass any custom event string.Identify users
Links anonymous activity back to a known player. Call when a player logs in or connects an account like Steam or Google. Requires
'full' consent.Complete Example
Verify the Integration
Initialize withdebug: true to see SDK activity in the browser console:
- Console: Look for log entries showing
session_start,page, and anytrack()calls - Network tab: Look for POST requests to
https://api.immutable.com(orhttps://api.sandbox.immutable.comif you’re using a test key) — events flush every 5 seconds or when 20 events accumulate
Remove
debug: true before deploying to production.API Reference
Audience.init(config)
Audience.init(config)
Creates and returns an
Audience instance. Call once when your app loads to set up tracking.| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
publishableKey | string | Yes | — | API key from Hub (starts with pk_imapik-) |
consent | 'none' | 'anonymous' | 'full' | No | 'none' | Initial consent level |
debug | boolean | No | false | Log SDK activity to the browser console |
cookieDomain | string | No | Current domain | Share cookies across subdomains (e.g. '.studio.com'). The Tracking Pixel uses domain for this same setting. |
flushInterval | number | No | 5000 | How often the queue flushes, in milliseconds |
flushSize | number | No | 20 | Number of queued messages that triggers a flush |
setConsent(level)
setConsent(level)
Controls what the SDK is allowed to collect. Call when the user accepts or changes their cookie preferences — takes effect immediately, no page reload needed. See the Data Dictionary for what each level enables.
page(properties?)
page(properties?)
Records a page view. Call on every route change to track which pages players visit and in what order. The first call in each session includes attribution parameters (UTMs, click IDs, referrer).
Requires:
| Parameter | Type | Description |
|---|---|---|
properties | Record<string, unknown> | Optional custom properties |
'anonymous' or 'full' consent. Calls at 'none' are silently dropped.track(event, properties?)
track(event, properties?)
Records a player action. Call when a player does something you want to measure — a purchase, sign-up, level completion, or any custom action. Predefined events give you typed properties with autocomplete.
Requires:
| Parameter | Type | Description |
|---|---|---|
event | string | An AudienceEvents value (e.g. AudienceEvents.PURCHASE) or any custom string |
properties | Record<string, unknown> | Event properties. Required for predefined events that have required fields (e.g. purchase), optional otherwise. |
'anonymous' or 'full' consent. Calls at 'none' are silently dropped.identify(id, identityType, traits?)
identify(id, identityType, traits?)
Links anonymous activity back to a known player. Call when a player logs in or connects an account like Steam or Google.
Requires: Identity types:
You can also call
| Parameter | Type | Description |
|---|---|---|
id | string | The player’s identifier in that provider |
identityType | IdentityType | Which provider the ID comes from (see table below) |
traits | object | Optional — email, name, or custom key-value pairs |
'full' consent.| Value | Provider |
|---|---|
'passport' | Immutable Passport |
'steam' | Steam |
'epic' | Epic Games |
'google' | |
'apple' | Apple |
'discord' | Discord |
'email' | Email address |
'custom' | Custom identity system |
identify(traits) with traits only to attach extra info (like an email) to the anonymous visitor without identifying them as a specific player. Also requires 'full' consent.| Parameter | Type | Description |
|---|---|---|
traits | object | email, name, or custom key-value pairs |
alias(from, to)
alias(from, to)
Connects two accounts that belong to the same player. Call when a player links a second account (e.g. signs up with email, later connects Steam).
Requires:
| Parameter | Type | Description |
|---|---|---|
from | { id: string, identityType: IdentityType } | The account being linked |
to | { id: string, identityType: IdentityType } | The player’s main account |
'full' consent.reset()
reset()
Wipes the current player’s identity and starts a fresh anonymous session. Call when a player logs out so the next player on the same device isn’t mixed up.
flush()
flush()
Sends all queued events to the server immediately. Call when you need events delivered right now instead of waiting for the next automatic flush. Returns a
Promise that resolves when the batch is sent.shutdown()
shutdown()
Sends any remaining events and shuts down the SDK. Call when the app unmounts or the page is about to unload. Fires a
session_end event if consent is above 'none'.Next Steps
Data Dictionary
Full reference of collected data at each consent level
Tracking Pixel
No-code snippet for marketing sites
Attribution
Learn how tracking data powers player attribution
API Keys
Manage your publishable and secret keys