Unity SDK does not currently support Simplified ID Merge.
Installation
Add to manifest
Add to ./Packages/manifest.json:{
"dependencies": {
"com.mixpanel.unity": "https://github.com/mixpanel/mixpanel-unity.git#master"
}
}
Or specify a version:"com.mixpanel.unity": "https://github.com/mixpanel/mixpanel-unity.git#v3.5.1"
Configure in Unity
- Open Edit → Project Settings → Mixpanel
- Enter your project token
- Click Save
Import and use
using mixpanel;
Mixpanel.Track("Game Started");
Supports Unity 2018.3+ with .NET 4.x or higher.
Track Events
var props = new Value();
props["level"] = 5;
props["character"] = "Warrior";
props["score"] = 1500;
Mixpanel.Track("Level Completed", props);
Timing Events
Mixpanel.StartTimedEvent("Level Duration");
// Player completes level
Mixpanel.Track("Level Duration");
// Duration property added automatically
Flush Events
// Flush immediately
Mixpanel.Flush();
Adjust flush interval in Edit → Project Settings → Mixpanel.
Identify Users
Mixpanel.Track("sign in");
Mixpanel.Identify("12345");
Reset on Logout
Mixpanel.Track("log out");
Mixpanel.Reset();
User Profiles
Mixpanel.Identify("12345");
Mixpanel.People.Set("Plan", "Premium");
// Set multiple properties
var props = new Dictionary<string, object> {
{ "level", 10 },
{ "class", "Warrior" },
{ "vip", true }
};
Mixpanel.People.Set(props);
SetOnce()
Increment()
Append()
Union()
Mixpanel.People.SetOnce("First Game", DateTime.Now.ToString());
Mixpanel.People.Increment("games_played", 1);
Mixpanel.People.Increment("total_score", 1500);
Mixpanel.People.Append("achievements", "First Victory");
Mixpanel.People.Union("classes_played", "Warrior");
Super Properties
Mixpanel.Register("game_version", "2.0.1");
Mixpanel.Register("platform", "Unity");
// Register without overwriting
Mixpanel.RegisterOnce("first_launch", DateTime.Now.ToString());
Group Analytics
// Set group
var props = new Value();
props["guild"] = "Warriors Guild";
Mixpanel.Track("Quest Completed", props);
// Add to user profile
Mixpanel.Identify("12345");
Mixpanel.People.Set("guild", "Warriors Guild");
Privacy Controls
Opt Out
Mixpanel.OptOutTracking();
// Opt back in
Mixpanel.OptInTracking();
// Initialize with opt-out
MixpanelStorage.IsTracking = false;
EU/India Data Residency
Configure in Edit → Project Settings → Mixpanel:
- EU: Set API Host Address to
https://api-eu.mixpanel.com/
- India: Set API Host Address to
https://api-in.mixpanel.com/
Debug Mode
Enable in Unity Project Settings → Mixpanel or:
// View logs in Unity console
- Works on all Unity platforms (iOS, Android, WebGL, Desktop)
- Events flush every 60 seconds (configurable)
- Super properties persist in local storage
- Supports both 2D and 3D games
- Compatible with Unity’s IL2CPP backend
For manual initialization, select “Manual Initialization” in settings and call Mixpanel.Init().
Resources