Add the package

During early access, the Unity SDK is available on request. Contact us to get the package. The source will be published at launch.

  1. Request the Unity SDK from the contact page.
  2. In Unity, open Window, Package Manager.
  3. Click + and add the package you received.

Start the SDK

Start the SDK once, on the main thread, in the Awake() of a component in your first scene. The package sample Basic setup has this component. Use the Publishable key from your project settings; it is safe to ship in a build. Init() refuses a Secret key or an API key, and returns false with a logged reason when an option is wrong.

C#

using UnityEngine;
using ManalensSdk;

public class AnalyticsBootstrap : MonoBehaviour
{
    void Awake()
    {
        Manalens.Init(new ManalensOptions
        {
            PublishableKey = "YOUR_PUBLISHABLE_KEY",
            Endpoint = "https://YOUR_COLLECTOR_ENDPOINT",
            Build = "571",
            Storefront = "steam",
            Enabled = !Application.isEditor,
        });
    }
}

Track game events

Use flat snake_case names: level_start, level_complete, level_fail, resource and purchase. Property values are strings, numbers, booleans or null. Track() can be called from any thread.

C#

Manalens.Track("level_complete", new Dictionary<string, object> { ["level"] = 3, ["attempt"] = 1, ["score"] = 1200 });
Manalens.Identify("player_42");
Manalens.TrackError("Save failed", new TrackErrorOptions { ErrorType = "SaveFailed", Severity = "critical" });

Verify the installation

Run a development build, not the editor, when Enabled is !Application.isEditor. Set Debug = true to log each queued event and each failed send. Check that game_open and session_start appear in the project activity feed. Events are sent every 10 seconds, at 20 queued events, on pause and on quit.

For WebGL, the collector accepts requests from your project domain, its subdomains and *.itch.zone. Add other game portals under Project settings, Allowed origins.

Frequently asked questions

Which Unity versions are supported?

The SDK needs Unity 2021.3 or later. It 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. During early access, the package is available on request from the contact page.

Does the SDK collect a device ID or the IP address?

No. The SDK sends a random anonymous ID, the session ID, and the app context. The collector derives the country and does not store the IP address. Use the Publishable key from your project settings, which is safe to ship in a build. Init() refuses a Secret key or an API key.

What happens offline?

Events are saved on disk and sent later with retries. The collector accepts app events up to 7 days old. The SDK sends events every 10 seconds, at 20 queued events, on pause, and on quit. Set Debug to true to log each queued event and each failed send.

Sources and implementation