> ## Documentation Index
> Fetch the complete documentation index at: https://docs.immutable.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Track with the Unity SDK

> Install the Unity SDK to track players, sessions and purchases in your Unity game.

Install the Unity SDK to send events and player identity from your Unity game to Audience. It also tracks launches, sessions and scene loads by itself.

## 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

1. In Unity, open **Window** > **Package Manager**.
2. Select **+** > **Add package from git URL...** and paste:

```text theme={null}
https://github.com/immutable/unity-immutable-sdk.git?path=src/Packages/Audience#audience/v0.7.3
```

## Set up with the install wizard

The install wizard opens the first time Unity loads the package without an `ImmutableAudience.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

```csharp theme={null}
using Immutable.Audience;
using UnityEngine;

public static class Analytics
{
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    private static void Init()
    {
        ImmutableAudience.Init(new AudienceConfig
        {
            PublishableKey = "YOUR_PUBLISHABLE_KEY",
            Consent = ConsentLevel.Anonymous,
            DistributionPlatform = DistributionPlatforms.Steam,
        });
    }
}
```

`Consent` defaults to `ConsentLevel.None`, which sends nothing. This example starts at `Anonymous`, so events flow straight away without identifying the player.

## Track events

```csharp theme={null}
// A predefined event, with typed properties
ImmutableAudience.Track(new Purchase { Currency = "USD", Value = "9.99" });

// A custom event
ImmutableAudience.Track("tutorial_complete", new Dictionary<string, object>
{
    ["stepCount"] = 5,
});
```

The predefined events are `Progression`, `Resource`, `Purchase`, `AchievementUnlocked` and `MilestoneReached`. For a custom event, add `using System.Collections.Generic;`.

## Identify players

```csharp theme={null}
ImmutableAudience.SetConsent(ConsentLevel.Full);
ImmutableAudience.Identify(
    userId: "76561190000000000",
    identityType: IdentityType.Steam,
    traits: new Dictionary<string, object> { ["personaName"] = "Player1" });
```

Call `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 sends `game_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, set `TestMode = 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](https://docs.immutable.com/audience/track/check-events.md).

## Related

* [Consent](https://docs.immutable.com/audience/track/consent.md)
* [Check your events arrive](https://docs.immutable.com/audience/track/check-events.md)
* [Unity SDK reference](https://docs.immutable.com/docs/products/audience/analytics/unity-sdk.md): every option, mobile attribution and error handling


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.