Skip to main content
Install the Web SDK to send page views, events and player identity from your website, game page or web game to Audience.

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 and yarn work too: 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

Call 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

Call 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

Call 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:
For a marketing site or landing page where you only need page views, clicks and form sign-ups, the tracking pixel needs no code beyond this snippet in your page’s <head>:
The pixel can also read consent from your consent manager. See Consent.

Test your setup

While you build, pass testMode: 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.