Mobile
Unity package
This page is assembled from
sdks/unity/README.mdin the repository. See the SDK overview for the choice between native SDKs and wrappers.
Formerly
com.dtrackier.unity. Until 2.0 the deprecatedDTrackierSDKclass forwards every member toMetrixedSDK; pre-rename scripts only needusing DTrackier;replaced byusing Metrixed;.
UPM package com.metrixed.unity (Unity 2021.3+, Android min API 21, iOS 13). A thin bridge over the native
Android and iOS SDKs: all tracking logic (offline queue, request signing,
attribution, SKAdNetwork, consent enforcement) is native. Method names mirror the native SDKs. In the Editor and on
other platforms calls are logged and dropped, so game code runs unchanged.
Install
Package Manager > Add package from git URL:
https://github.com/apwapi/DTrackier.git?path=/sdks/unity#unity-v1.0.0 (or "from disk" on sdks/unity).
On build, the Editor post-processor (settings: Window > Metrixed > Build Settings, stored in
Assets/Editor/MetrixedSettings.asset):
- Android: adds
com.metrixed:metrixed-android:<version>to the exportedunityLibrary/build.gradle(Maven Central; set Android Maven Repo to themake sdk-android-buildoutput until it is published) and patches the manifest:INTERNET,ACCESS_NETWORK_STATE, a VIEW intent filter for your URL scheme and verified App Link filters for each link host. Kids mode removescom.google.android.gms.permission.AD_ID. Use a custom main/launcher manifest as usual. - iOS: Info.plist
NSUserTrackingUsageDescription,SKAdNetworkItems(a starter list merged with yours; keep it current from each network's documentation),NSAdvertisingAttributionReportEndpoint/AdAttributionKitReportEndpoint, URL scheme, Associated Domainsapplinks:<host>, a Podfile with theMetrixedpod (andpod installwhen CocoaPods is available, else run it yourself and open the.xcworkspace), Swift build settings for the shim inPlugins/iOS. Kids mode writes no ATT text or SKAN keys.
Initialise
using Metrixed;
MetrixedSDK.Initialize(new DTConfig("APP_TOKEN", DTEnvironment.Production) // Sandbox: flagged, excluded from billing
{
BaseUrl = "https://ingest.example.com",
Secret = "SDK_SECRET", // request signing
});
Call it early (a script in the first scene). Unity starts after the first Android activity is visible: the install is reported
immediately but the very first session starts at the next foreground.
Platform-specific options are ignored on the other platform: SecretId, ConsentRequired, CollectGaid,
CollectAppSetId, CollectAndroidId, Oaid, PreloadKey, ReferrerTimeoutMs (Android); TrackingBaseUrl,
AttWaitInterval, ReadIdfa, ReadIdfv, LinkMe*, SkanEnabled, StoreKitForwarding (iOS). KidsMode maps to
setKidsMode / coppaCompliant.
Events
MetrixedSDK.TrackEvent("level_up");
MetrixedSDK.TrackEvent(new DTEvent("purchase") { DedupeId = orderId, PartnerParams = new() { { "af_content", "x" } } }.SetRevenue(9.99, "USD"));
MetrixedSDK.SetCustomerUserId("user-42");
Revenue is a number plus an ISO currency (required together), formatted by the native SDK as a 6-decimal string. Invalid
arguments throw ArgumentException before reaching native code.
Ad revenue adapters (AppLovin MAX, AdMob, LevelPlay / ironSource)
DTAdRevenueAdapters accepts the objects the mediation SDKs pass to their revenue callbacks and reads the fields by
reflection, so there is no dependency on those SDKs:
// AppLovin MAX (revenue is USD)
MaxSdkCallbacks.Interstitial.OnAdRevenuePaidEvent += (adUnitId, adInfo) =>
MetrixedSDK.TrackAdRevenue(DTAdRevenueAdapters.FromMax(adInfo));
// Google Mobile Ads: AdValue.Value is in micro-units of CurrencyCode and is converted exactly
rewardedAd.OnAdPaid += value => MetrixedSDK.TrackAdRevenue(DTAdRevenueAdapters.FromAdMob(value, rewardedAd.GetAdUnitID()));
// LevelPlay / ironSource impression data (snake_case fields or PascalCase properties)
IronSourceEvents.onImpressionDataReadyEvent += d => MetrixedSDK.TrackAdRevenue(DTAdRevenueAdapters.FromLevelPlay(d));
// still reported as ironSource: DTAdRevenueAdapters.FromLevelPlay(d, DTAdRevenueAdapters.SourceIronSource)
The source values are applovin_max, admob, unity_levelplay and ironsource. With IL2CPP managed code stripping
set to Medium/High, add a link.xml preserving the mediation SDK's impression-data type (fields are read reflectively).
FromAdMobMicros(long, string, ...) is available when you already have the numbers.
Deep links
MetrixedSDK.OnDeeplink += link => Route(link.DeepLinkValue ?? link.Url, link.Params); // main thread
Direct (scheme / App Link / Universal Link) and deferred links arrive as DTDeeplink { Url, Source, ClickId, DeepLinkValue, Params }. The package subscribes to Application.deepLinkActivated (and Application.absoluteURL on an iOS
cold start) and forwards to the SDK; Android also passes the launching intent. ProcessDeeplink(url) is there for links
you receive yourself.
Consent and privacy
MetrixedSDK.SetConsent(new DTConsent { ThirdPartySharing = false, Measurement = true, AdPersonalization = false, GdprApplies = true, Tcf = tcString });
MetrixedSDK.SetThirdPartySharing(false);
MetrixedSDK.GdprForgetMe(); // server erase + local wipe; the SDK stays off afterwards
Tcf, Gpp, GoogleDma, MetaLdu are honoured on iOS; Android carries ThirdPartySharing, Measurement,
AdPersonalization, GdprApplies. SetPushToken takes the FCM token (Android) or the hex APNs token (iOS).
SetCustomerUserId(null) clears the id.
Platform differences
| Call | Android | iOS |
|---|---|---|
SetExternalDeviceId | yes | set ExternalDeviceId in DTConfig (call is a no-op) |
SetEnabled, SetOfflineMode, SetSecret | yes | no-op |
GetAttribution, OnAttribution | yes | null / never fires |
Layout, tests, CI
Runtime/Core and Editor/Logic contain no Unity types (C# 9) and are unit tested with NUnit on the pinned .NET image;
Runtime/Platform and Editor/*.cs are the thin Unity glue (AndroidJavaObject over AndroidMapper, [DllImport("__Internal")]
over the Swift shim in Plugins/iOS, build post-processors).
make sdk-unity-test(not part ofmake test):dotnet testofTests~(shared wire vectorssdks/test-vectors/wrapper-api.json, Android JNI call mapping, ad-revenue adapters with duck-typed fakes, Gradle/Podfile/manifest/Info.plist patch logic,.metafiles), the Swift shim compiled against the iOS SDK on Linux, and the.metacheck (python3 -I sdks/unity/scripts/gen_meta.pycreates missing ones).- Compiling the package in the Unity Editor, building the sample for Android/iOS and the post-processors need a Unity
licence and (iOS) macOS: the
unityandunity-iosjobs of.github/workflows/sdk-wrappers.yml.
Sample: Samples~/Basic. Changelog: CHANGELOG.md.