Before you start
- Your project’s publishable key, from Game Analytics > Connect your game or Settings > General in Audience. It starts with
pk_imapik-. - A consent prompt, if your players need one. The SDK has no consent UI of its own. See Consent.
Install
pnpm add @imtbl/audience or yarn add @imtbl/audience.
Start the SDK
consent defaults to none, which sends nothing. This example starts at anonymous, so events flow straight away without identifying the player.
Track page views and events
page() on every page view. In a single-page app, call it on each route change. Use a predefined event name, such as purchase, or your own.
Identify players
identify() when a player signs in or gives you their email. Raise consent to full first, and only after the player agrees: at anonymous the SDK drops the call and logs a warning.
When your app closes
shutdown() when your app unmounts, so queued events are sent.
What the SDK captures by itself
To turn one off, pass
autocapture to init:
Without a bundler
Load the SDK from Immutable’s CDN with a script tag instead:<head>:
Test your setup
While you build, passtestMode: true to init. Test events show in the event log but stay out of your boards. Pass debug: true to log every event to the browser console. Remove both before you go live.
Check it’s working
In Audience, open Connections and select the Event log tab: your events show there as they land. Game Analytics counts only events from a game, so website events don’t show on its boards. See Check your events arrive.Related
- Consent
- Check your events arrive
- Web SDK reference: every option and method