# How to add analytics to a Unity game

> Add analytics to a Unity game: install the SDK package, start it in Awake(), send level events, set the build number, check the data and fix common errors.

By Yos Riady. Updated 2026-11-19. Published 2026-11-18. Canonical URL: https://manalens.dev/blog/unity-analytics-without-gameanalytics

Install the Manalens Unity SDK with the Package Manager, then call Manalens.Init() once in Awake() with your Publishable key. The SDK needs Unity 2021.3 or later and runs on Windows, macOS, Linux, Android, iOS and WebGL (Manalens documentation). It sends launches, sessions, errors and crashes for you. During early access, the package is available on request.

## Key points

- The Manalens Unity SDK needs Unity 2021.3 or later, and during early access the package is available on request.
- Call Manalens.Init() once in Awake(), and the SDK sends launches, sessions, errors and crashes while your code sends level, resource and purchase events.
- Set Enabled = !Application.isEditor and test in a development build, because by default the SDK sends events from every run.

## Which analytics options does a Unity game have?

Three common options are Manalens, Unity Analytics and GameAnalytics. Each one is an SDK that you add to the project. The table shows what each vendor documents on its public pages.

The rest of this guide uses the Manalens SDK. The order of the work is the same for any SDK: install, start, send events, set versions, check the data.

- [Best Unity analytics tools in 2026](https://manalens.dev/blog/best-unity-analytics-tools)

*Unity analytics options, from each vendor's public documentation and pricing page.*

| Option | Install | Unity version | Public price |
| --- | --- | --- | --- |
| Manalens | Unity Package Manager package, on request during early access. No dependencies. | 2021.3 or later | From $79 a month for up to 10K MAU. No free plan. 7-day trial. |
| Unity Analytics (Unity Gaming Services) | Unity Gaming Services setup. gameStarted, gameRunning and gameEnded are automatic. | Not stated on the pages we read | Free up to 50,000 active users a month, then from $0.00360 per MAU |
| GameAnalytics | OpenUPM or a .unitypackage. One GameAnalytics object in the scene, then GameAnalytics.Initialize(). | 2022.3 or later | Free plan with no MAU cap. Paid plans add features. |

Sources: Manalens Unity SDK documentation and pricing; Unity Analytics documentation and Unity Gaming Services pricing; GameAnalytics Unity SDK documentation and pricing.

## What do I need before I start?

You need four things. Get them before you open the Package Manager.

Never put a Secret key or an API key in a build. Init() refuses them and returns false.

- Unity 2021.3 or later. The package is plain C# with no native code and no dependencies.
- The SDK package. During early access, it is available on request from the contact page. The source will be published at launch.
- The Publishable key of your Manalens project. It starts with mana_pk_. It is safe to ship in a build, because it can send events and cannot read data.
- Your collector endpoint: the collector URL without /v0/events.

- [Request the Unity SDK](https://manalens.dev/contact)

Sources: Manalens Unity SDK documentation.

## How do I install the SDK package?

Use the Package Manager. Unity can install a package from a folder on your disk or from a .tgz file, so you do not need a registry. The Unity Manual gives the steps for each case.

1. Request the Unity SDK from the contact page, and save the package on your computer.
2. In Unity, open Window, Package Manager, and click the install (+) button in the toolbar.
3. If you received a folder, select Install package from disk, go to the root of the package folder and open its package.json file.
4. If you received a .tgz file, select Install package from tarball and open the file. The file dialog recognizes a tarball only when it has the .tgz extension.
5. Check that Manalens (dev.manalens.sdk) is in the package list.
6. Optional: import the Basic setup sample from the package. It has a ready AnalyticsBootstrap component.

Sources: Manalens Unity SDK documentation; Unity Manual, Install a UPM package from a local folder and from a local tarball file.

## How do I start the SDK?

Call Manalens.Init() once, on the main thread, in the Awake() of a component in your first scene. Init() sends session_start and game_open, with is_first_open and first_open_at. It returns false and logs the reason when an option is wrong. The SDK then stays off.

Unity calls Awake() once in the lifetime of a script instance, and again when the scene loads again. A second Init() call returns false and logs a warning, so the component below checks IsInitialized first.

Enabled = !Application.isEditor turns the SDK off in Play mode. Application.isEditor says whether the game runs inside the Unity Editor. With Enabled set to false, every call does nothing: no events, no files and no stored ID.

``` C#
using UnityEngine;
using ManalensSdk;

// Add this component to one GameObject in your first scene.
public class AnalyticsBootstrap : MonoBehaviour
{
    void Awake()
    {
        if (Manalens.IsInitialized) return; // the first scene loaded again

        Manalens.SendFailed += (status, dropped) =>
            Debug.LogWarning($"Analytics dropped {dropped} events (HTTP {status})");

        bool started = Manalens.Init(new ManalensOptions
        {
            PublishableKey = "YOUR_PUBLISHABLE_KEY",
            Endpoint = "https://YOUR_COLLECTOR_ENDPOINT", // without /v0/events
            Build = BuildInfo.Build, // the BuildInfo class is in a later section
            Storefront = "steam",
            Enabled = !Application.isEditor,
        });
        if (!started) Debug.LogWarning("Analytics did not start. The log line before this one has the reason.");
        else BuildInfo.ReportUpdate();
    }
}
```

Sources: Manalens Unity SDK documentation; Unity Scripting API, MonoBehaviour.Awake and Application.isEditor.

## How do I send my first events?

Call Track() with a snake_case name and a dictionary of flat properties. Values are strings, numbers, booleans or null. An enum value is sent as its name. The SDK drops lists, dictionaries and objects, and logs a warning. Track() can be called from any thread.

Use the event conventions in the table, so that the Game KPIs board reads your events without setup. Put the level number in a property, not in the event name. Keep all calls in one static class, as below, so that every name is written in one place.

- [Game tracking plan generator](https://manalens.dev/tools/game-tracking-plan-generator)
- [What events to track first in your game](https://manalens.dev/blog/game-tracking-plan-first-events)
- [Event](https://manalens.dev/glossary/event)

*The first events for a Unity game, their properties and who sends them.*

| Event | Properties | Sent by |
| --- | --- | --- |
| game_open | is_first_open, first_open_at | The SDK, each launch |
| session_start | none | The SDK |
| session_end | duration_s | The SDK |
| level_start | level, attempt | Your code |
| level_complete, level_fail | level, attempt, score | Your code |
| resource | flow (source or sink), currency, amount, item | Your code |
| purchase | amount_cents, currency, store | Your code |
| error | severity, message, error_type, handled, fingerprint | The SDK and TrackError() |
| app_unclean_exit | previous_session_id, previous_build | The SDK, at the next launch after a crash |
| game_updated | previous_version, previous_build | Your code |

``` C#
using System;
using System.Collections.Generic;
using ManalensSdk;

public static class GameEvents
{
    public static void LevelStart(int level, int attempt) =>
        Manalens.Track("level_start", new Dictionary<string, object> { ["level"] = level, ["attempt"] = attempt });

    public static void LevelComplete(int level, int attempt, int score) =>
        Manalens.Track("level_complete", new Dictionary<string, object> { ["level"] = level, ["attempt"] = attempt, ["score"] = score });

    public static void LevelFail(int level, int attempt, int score) =>
        Manalens.Track("level_fail", new Dictionary<string, object> { ["level"] = level, ["attempt"] = attempt, ["score"] = score });

    public static void Spend(string currency, int amount, string item) =>
        Manalens.Track("resource", new Dictionary<string, object> { ["flow"] = "sink", ["currency"] = currency, ["amount"] = amount, ["item"] = item });

    // A caught exception: the SDK sends its type, message, stack and place in the code.
    public static void Caught(Exception exception) => Manalens.TrackError(exception);
}
```

Sources: Manalens Unity SDK and app events documentation.

## How are sessions counted?

The SDK counts them, and you write no session code. A session continues while the game has focus. After 30 minutes without focus or events, the next activity ends the old session with session_end (duration_s) and starts a new one. A session is also at most 24 hours old, so a game that stays open gets a new session every 24 hours.

If the game crashes or is killed while it has focus, the next launch ends the old session at its last activity and sends app_unclean_exit. A mobile game that the operating system closes in the background is not a crash.

Manalens.SessionId is the current session ID, and Manalens.AnonymousId is the player ID. Send the two to your backend when a server event, for example a purchase check, must be in the session of the player.

- [Session](https://manalens.dev/glossary/session)

Sources: Manalens Unity SDK documentation.

## How do I set the version and the build number?

Set them once, in Init(). AppVersion defaults to Application.version, which Unity reads from the Version field in Edit, Project Settings, Player. Build has no default: pass your build number, up to 64 characters. Storefront takes steam, itch, epic, gog, app_store, play or other.

The values go on every event in context.app, with the platform and the engine unity. They are filters and breakdowns in every report, for example Build is 571. So you can compare retention, crashes and funnels between two builds without an extra property.

To see which players moved to a new build, send game_updated on the first launch after an update. The SDK does not send this event. Keep the last build in PlayerPrefs, as below, and call ReportUpdate() after Init().

``` C#
using System.Collections.Generic;
using UnityEngine;
using ManalensSdk;

public static class BuildInfo
{
    public const string Build = "571"; // write this value from your build script

    // Call once, after Manalens.Init().
    public static void ReportUpdate()
    {
        string lastBuild = PlayerPrefs.GetString("analytics_last_build", "");
        string lastVersion = PlayerPrefs.GetString("analytics_last_version", "");
        if (lastBuild != "" && lastBuild != Build)
        {
            Manalens.Track("game_updated", new Dictionary<string, object>
            {
                ["previous_version"] = lastVersion,
                ["previous_build"] = lastBuild,
            });
        }
        PlayerPrefs.SetString("analytics_last_build", Build);
        PlayerPrefs.SetString("analytics_last_version", Application.version);
        PlayerPrefs.Save();
    }
}
```

Sources: Manalens Unity SDK and app events documentation; Unity Scripting API, Application.version and PlayerPrefs.

## What changes on each platform?

The code stays the same. The quit, the storage and the network rules change. The table lists what the SDK documentation and the Unity Scripting API say for each platform.

If your game shows its own quit dialog on desktop, set HandleQuit to false and run the coroutine below before Application.Quit().

- [Track an itch.io game](https://manalens.dev/integrations/itch-io)
- [Steamworks.NET in Unity: a Steam integration guide](https://manalens.dev/blog/steamworks-net-unity)

*Platform notes for the Unity SDK.*

| Platform | Platform value on events | What to know |
| --- | --- | --- |
| Windows, macOS, Linux | windows, macos, linux | The SDK handles the quit request (Application.wantsToQuit), sends session_end and flushes for at most 2 seconds. Events are saved in Application.persistentDataPath. |
| Android, iOS | android, ios | These platforms do not report a quit, so the SDK saves everything and sends the queue when the game loses focus or is paused. Unity says that wantsToQuit cannot prevent termination on iOS and is not always raised on Android. |
| WebGL | web | The queue is kept in PlayerPrefs. The browser sends an Origin header, so the build must run on your project domain, a subdomain, or a host in Allowed origins. *.itch.zone is allowed by default. |
| Consoles, tvOS, visionOS | other | Events have the platform value other. No other behaviour is documented for these platforms. |

``` C#
using System.Collections;
using UnityEngine;
using ManalensSdk;

public class QuitDialog : MonoBehaviour
{
    // Call this from the "Quit" button of your own dialog.
    public void OnQuitConfirmed() => StartCoroutine(QuitGame());

    IEnumerator QuitGame()
    {
        yield return Manalens.Shutdown(); // session_end, then a flush of at most QuitTimeoutSeconds
        Application.Quit();
    }
}
```

Sources: Manalens Unity SDK and app events documentation; Unity Scripting API, Application.wantsToQuit and Application.persistentDataPath.

## How do I ask for consent, and what data is sent?

Set ConsentRequired to true, then call SetConsent() from your consent screen. Before consent, the SDK records no events and writes no ID. It saves the choice, so the next launch uses it. SetConsent(false) deletes the ID, the session and the queue.

Each event has a random anonymous ID, the session ID, your user ID after Identify(), the locale and the app context. The SDK sends no device ID, no hardware details and no IP address. The collector derives the country from the request IP and does not store the IP. Whether your game needs consent is a decision for you and your legal advisers.

- [GDPR consent in games](https://manalens.dev/glossary/gdpr-consent-games)

``` C#
Manalens.Init(new ManalensOptions { PublishableKey = "mana_pk_...", Endpoint = "https://...", ConsentRequired = true });

// Later, from your consent screen:
Manalens.SetConsent(true);   // starts tracking; sends game_open
Manalens.SetConsent(false);  // deletes the ID, the session and the queue
```

Sources: Manalens Unity SDK documentation.

## How do I check that the data arrives?

Run a development build with the Debug option on, and read the activity feed. The SDK sends events every 10 seconds, at 20 queued events, on focus loss or pause, and on quit. So the first events appear some seconds after the launch.

The Flushed event tells you the result of each send. Add the line below while you test.

1. Create a test project in Manalens and use its Publishable key, so that test data stays out of the real project.
2. Set Debug = true in the options. The SDK then logs each queued event and each failed send.
3. Make a development build and run it. With Enabled = !Application.isEditor, Play mode in the editor sends nothing.
4. Open the activity feed. Check that session_start and game_open arrive, and that the event detail shows platform, storefront, app version, build and engine.
5. Play one level and quit. Check level_start, level_complete and session_end with duration_s.
6. Switch off the network, play for a minute, switch it on, and check that the queued events arrive once.
7. Replace the test key with the production Publishable key, and set Debug to false.

- [Offline event queue](https://manalens.dev/glossary/offline-event-queue)

``` C#
Manalens.Flushed += (sent, ok) => Debug.Log($"Analytics sent {sent} events, ok: {ok}");
```

Sources: Manalens Unity SDK documentation.

## Which errors are common, and how do I fix them?

Most problems are a wrong key, a wrong host or the editor switch. The SendFailed event gives the HTTP status of a refused batch, or 0 when the SDK dropped the events itself.

*Common errors with the Unity SDK, the cause and the fix.*

| Symptom | Cause | Fix |
| --- | --- | --- |
| Init() returns false | An option is wrong, for example no endpoint, or a Secret key in PublishableKey | Read the reason in the log. Use the Publishable key and the collector URL without /v0/events. |
| "Init() was already called" in the log | Awake() ran again because the first scene loaded again | Check Manalens.IsInitialized before Init(). |
| No events from the editor | Enabled = !Application.isEditor turns the SDK off in Play mode | Test in a build, or send from the editor with the key of a test project. |
| Editor sessions in real reports | By default the SDK sends events from every run | Set Enabled = !Application.isEditor. |
| SendFailed with status 401 | The key is missing or is not a Publishable key | Copy the Publishable key again from the project Settings. |
| SendFailed with status 403 in a WebGL build | The page host is not the project domain, a subdomain or an allowed origin | Add the host under Project settings, Allowed origins. |
| SendFailed with status 400 | The collector refused the batch (INVALID_EVENT) | Read the reason in the warning. The SDK does not send the batch again. |
| SendFailed with status 0 | The queue was over MaxQueue, or events were older than 7 days | These events cannot be sent. Check the network of the test device. |
| Flushed with ok false | A network error, or a 5xx, 408 or 429 response | No action. The events stay queued, and the SDK waits longer before each retry, at most 5 minutes. |
| A property is not on the event | The value was a list, a dictionary or an object | Send strings, numbers, booleans or null. |

Sources: Manalens Unity SDK, events API and app events documentation.

## What will I see in the reports?

Create the Game KPIs board from the dashboard templates. It shows D1, D7 and D30 retention, DAU, MAU, stickiness, sessions per DAU, session length, ARPDAU, ARPPU, install cohorts, a level funnel, a levels table and currency sources and sinks. The Game health board shows crash-free sessions and players, errors per session by build and the top errors.

To connect play to marketing, set Storefront and link the game to your website. Install attribution links a first launch to a recent website visit on the same network. For a certain link, open your website from the game with LinkUrl(), or call Identify() with the same user ID on both sides.

- [D1 retention](https://manalens.dev/glossary/d1-retention)
- [What is crash-free rate?](https://manalens.dev/glossary/crash-free-rate)

``` C#
Application.OpenURL(Manalens.LinkUrl("https://example.com/wiki"));
```

Sources: Manalens dashboards, error tracking and install attribution documentation.

## How do I start?

Manalens is the analytics and growth engine built for games. Install the Unity SDK, create the Game KPIs board, and see your players next to the channels that brought them.

- [Install game analytics in Unity](https://manalens.dev/integrations/unity)

Sources: Manalens product documentation.

## Frequently asked questions

### Which Unity versions does the Manalens SDK support?

Unity 2021.3 or later. The SDK is a Unity Package Manager package in plain C#, with no dependencies and no native code. It runs on Windows, macOS, Linux, Android, iOS and WebGL. On consoles, tvOS and visionOS, events have the platform value other.

### Is the Unity SDK in a public package registry?

Not yet. During early access, the package is available on request from the contact page, and the source will be published at launch. You install it with the Package Manager from a folder or from a .tgz file, so the project needs no scoped registry.

### Does the SDK send events from the Unity editor?

Yes, by default it sends from every run, also from Play mode. Test sessions and errors then mix into retention and crash-free reports. Set Enabled = !Application.isEditor in the options. To test the SDK in the editor, use a separate test project and its own Publishable key.

### Does the SDK work offline?

Yes. The SDK saves events on disk, sends them in batches and retries them. The collector accepts app events up to 7 days old. So a player who plays offline for a few days still sends those events later, when the device is online again.

## Sources

- [Unity Manual 6000.6: Install a UPM package from a local folder (read 19 November 2026)](https://docs.unity.com/en-us/engine/6000.6/manual/packages-list/managing-packages-window/upm-ui-actions/upm-ui-local)
- [Unity Manual 6000.6: Install a UPM package from a local tarball file (read 19 November 2026)](https://docs.unity.com/en-us/engine/6000.6/manual/packages-list/managing-packages-window/upm-ui-actions/upm-ui-tarball)
- [Unity Scripting API 6000.6: MonoBehaviour.Awake (read 19 November 2026)](https://docs.unity.com/en-us/engine/6000.6/script-reference/unityengine/monobehaviour/awake)
- [Unity Scripting API 6000.6: Application.isEditor (read 19 November 2026)](https://docs.unity.com/en-us/engine/6000.6/script-reference/unityengine/application/iseditor)
- [Unity Scripting API 6000.6: Application.version (read 19 November 2026)](https://docs.unity.com/en-us/engine/6000.6/script-reference/unityengine/application/version)
- [Unity Scripting API 6000.6: Application.wantsToQuit (read 19 November 2026)](https://docs.unity.com/en-us/engine/6000.6/script-reference/unityengine/application/wantstoquit)
- [Unity Scripting API 6000.6: Application.persistentDataPath (read 19 November 2026)](https://docs.unity.com/en-us/engine/6000.6/script-reference/unityengine/application/persistentdatapath)
- [Unity Scripting API 6000.6: PlayerPrefs (read 19 November 2026)](https://docs.unity.com/en-us/engine/6000.6/script-reference/unityengine/playerprefs)
- [Unity documentation: Unity Analytics (read 19 November 2026)](https://docs.unity.com/en-us/analytics)
- [Unity documentation: Analytics standard events (read 19 November 2026)](https://docs.unity.com/en-us/analytics/events/standard-events)
- [Unity: Unity Gaming Services pricing (read 19 November 2026)](https://unity.com/products/gaming-services/pricing)
- [GameAnalytics documentation: Unity SDK (read 19 November 2026)](https://docs.gameanalytics.com/event-tracking-and-integrations/sdks-and-collection-api/game-engine-sdks/unity/)
- [GameAnalytics: Pricing (read 19 November 2026)](https://www.gameanalytics.com/pricing)

## Related guides

- [Game marketing measurement guide](https://manalens.dev/blog/game-marketing-measurement-guide)
- [What events to track first in your game](https://manalens.dev/blog/game-tracking-plan-first-events)
- [Best Unity analytics tools in 2026](https://manalens.dev/blog/best-unity-analytics-tools)
- [How to move from Unity Analytics to Manalens](https://manalens.dev/blog/migrate-from-unity-analytics)
- [How to move from GameAnalytics to Manalens](https://manalens.dev/blog/migrate-from-gameanalytics)
- [Game tracking plan generator](https://manalens.dev/tools/game-tracking-plan-generator)
- [Player analytics guides](https://manalens.dev/blog/topic/player-analytics)
- [Game metrics every indie developer should track](https://manalens.dev/blog/game-metrics-indie-developers)
- [PostHog, Mixpanel or Amplitude for games?](https://manalens.dev/blog/posthog-mixpanel-amplitude-for-games)
- [Game analytics dashboards: which charts matter](https://manalens.dev/blog/game-analytics-dashboard-charts)
- [How to add analytics to a Godot game](https://manalens.dev/blog/godot-analytics)
