Before you start
- Your project’s publishable key, from Game Analytics > Connect your game or Settings > General in Audience. It starts with
pk_imapik-. - Unity 2021.3 or later, with Mono or IL2CPP.
- A supported platform: Android, iOS, Windows 10 or later (64-bit), macOS or Linux (64-bit).
Install
- In Unity, open Window > Package Manager.
- Select + > Add package from git URL… and paste:
Set up with the install wizard
The install wizard opens the first time Unity loads the package without anImmutableAudience.Init call in your scripts. To open it any time, go to Tools > Immutable > Audience > Install Wizard.
It checks your publishable key, sends one test message, and gives you the Init code for your consent level. Copy the code, or select Create script for me to save it as Assets/AudienceSetup.cs.
Start the SDK
Consent defaults to ConsentLevel.None, which sends nothing. This example starts at Anonymous, so events flow straight away without identifying the player.
Track events
Progression, Resource, Purchase, AchievementUnlocked and MilestoneReached. For a custom event, add using System.Collections.Generic;.
Identify players
Identify when a player signs in. It needs Full consent: raise it only after the player agrees.
What the SDK captures by itself
The SDK sendsgame_launch, first_launch, app_updated, session_start, session_heartbeat, session_end, scene_loaded and scene_unloaded. Turn each on or off in AudienceConfig.Autocapture.
The SDK sends queued events and shuts down when the game quits.
Test your setup
While you build, setTestMode = true in AudienceConfig. Test events show in the event log but stay out of your boards. Set Debug = true to log every event to the Unity Console. Remove both before you release: the install wizard warns about a leftover TestMode.
Check it’s working
Press Play.ImmutableAudience.Initialized returns true, and in Audience Game Analytics > Connect your game shows First event received within a few minutes. See Check your events arrive.
Related
- Consent
- Check your events arrive
- Unity SDK reference: every option, mobile attribution and error handling