# Unity SDK

URL: https://traqio.app/docs/sdks/unity
Last updated: 2026-10-19

Add Traqio to a Unity game: the app.traqio.sdk package reads the Play Install Referrer on Android, registers with SKAdNetwork on iOS and handles deep links.

`app.traqio.sdk` is the Traqio SDK for Unity (namespace `Traqio`, class `TraqioSdk`). On Android it reads the **Google Play Install Referrer** through `AndroidJavaProxy`; on iOS a small native plugin registers installs with **SKAdNetwork**. Events are queued in `PlayerPrefs` and flushed by a coroutine; deep links arrive through `Application.deepLinkActivated` with no extra code.

## Requirements

- Unity 2021.3 or later.

## Set up

### Add the package

Packages/manifest.json:
```json
// Packages/manifest.json — once the package is published (git URL / OpenUPM)
"dependencies": {
  "app.traqio.sdk": "0.1.0"
}
```

The package is not on OpenUPM or a public git URL yet. Until it is, use Window → Package Manager → + → Add package from disk, and pick the `package.json` of the folder we send you.

### Initialise once

```csharp
using Traqio;
using UnityEngine;

public class Bootstrap : MonoBehaviour
{
    void Awake()
    {
        // Creates its own "Traqio" GameObject (DontDestroyOnLoad); call it once.
        TraqioSdk.Init("YOUR_SDK_KEY", "https://api.traqio.app");
    }
}
```

Startup runs as a coroutine on the SDK's own GameObject: the install is reported, the deferred link resolved, the app open recorded, and the queue flushed on a timer and whenever the game is paused.

### Track events

```csharp
TraqioSdk.SetUserId(player.Id);           // same id as RevenueCat's app_user_id
TraqioSdk.Track("tutorial_complete");
TraqioSdk.Track("purchase", 4.99f, "EUR");
```

Names: [Event names](https://traqio.app/docs/concepts/events-and-revenue#names). Consent: `TraqioSdk.SetConsent(bool)`.

## Deep links

```csharp
var unsubscribe = TraqioSdk.OnDeepLink(link =>
{
    if (link.DeepLink != null) Router.Open(link.DeepLink);
});

TraqioSdk.GetDeferredDeepLink(link => { /* null when the install came from no link */ });
```

## Not in this SDK yet

On iOS, no conversion value is set and no Apple Ads token is reported. No purchase transaction id, no AdMob ad revenue, no in-app erasure — use [RevenueCat](https://traqio.app/docs/integrations/revenuecat) and the [server-side erasure](https://traqio.app/docs/concepts/privacy#erasure).

> **Proof so far** The SDK logic has been tested against a mock server, but Unity is the one SDK with no automated build: compiling against UnityEngine requires a Unity licence in CI, which is not set up yet. Only the Editor script that patches the Android Gradle project is unit-tested in CI, on plain .NET.

## Frequently asked questions

**Do I need to add the Install Referrer library to my Unity project?**
No. When Unity generates the Android Gradle project, the package's Editor script adds com.android.installreferrer:installreferrer:2.2, the Play Store <queries> entry Android 11 and later require, and a keep rule for minified builds. No custom Gradle template or manifest is needed; one that already declares them is left as it is.

**Does the Traqio Unity SDK work in the Editor?**
The C# runs in the Editor and sends events, but the Install Referrer and SKAdNetwork calls are compiled only for Android and iOS device builds. Attribution can only be observed on a device build installed from a store.
