Skip to Content
docs
SDKs

Unity

The Unity SDK for iOS and Android. Unity 2021.3 LTS and later, IL2CPP and Mono.

Early access

The Unity SDK is in early access. The API on this page is stable; package versions may still move quickly.

Install

Window ▸ Package Manager ▸ + ▸ Add package by name, then com.uncorrelate.sdk. Or add it to Packages/manifest.json:

Packages/manifest.json
{
  "dependencies": {
    "com.uncorrelate.sdk": "0.1.0"
  }
}

No Newtonsoft or other dependencies are pulled in.

Initialize

Call Init once, as early as possible, for example in a bootstrap scene:

using Uncorrelate;

public class Bootstrap : MonoBehaviour {
    void Awake() {
        UC.Init("uc_pub_prod_…", new UCOptions {
            Debug = Application.isEditor,   // logs every event to the console
        });
    }
}

You can also set the key in Project Settings ▸ Uncorrelate and call UC.Init() with no arguments.

Track

UC.Track("level_complete", new() {
    ["level"] = 42,
    ["stars"] = 2,
    ["boosters"] = new[] { "hammer" },
});

UC is safe to call from any thread and never throws into your game code.

Identify and reset

UC.Identify(account.Id, new() { ["cohort"] = "winter_26" });
// on logout, on shared devices
UC.Reset();

See Players and identity.

Purchases

With Unity IAP 4.x or 5.x, pass the purchased product. The SDK reads the store, SKU, transaction ids, price, currency and receipt:

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e) {
    UC.Purchase(e.purchasedProduct);
    return PurchaseProcessingResult.Complete;
}

The adapter is compiled only when UNITY_PURCHASING is defined. Without Unity IAP, use the explicit overload; see Purchases and receipts.

What the SDK does for you

Offline queueevents are appended to files under Application.persistentDataPath and survive restarts
Batchingup to 500 events or 10 seconds, gzip compressed
Retriesexponential backoff with the same insert_id, so nothing is counted twice
Sessions$session_start / $session_end from app pause and focus
Flushon background, so events are not lost when the OS kills the app

Options

Prop

Type

On this page