Integrating Mixpanel analytics into a mobile application
Mixpanel builds analytics around users, not sessions. Each event is tied to distinct_id — a unique identifier of a person. When an anonymous user registers, all their previous events merge with the new profile through alias. For conversion funnels and retention, this is fundamental: user history doesn't break at the moment of authorization.
Connection and initialization
iOS via Swift Package Manager — repository mixpanel/mixpanel-swift:
import Mixpanel
// AppDelegate
Mixpanel.initialize(token: "YOUR_PROJECT_TOKEN", trackAutomaticEvents: true)
trackAutomaticEvents: true enables automatic tracking: App Session, App Updated, App Crashed. For iOS 14+ on first launch, Mixpanel doesn't use IDFA without explicit request — this complies with ATT.
Android:
MixpanelAPI.getInstance(context, "YOUR_PROJECT_TOKEN", true)
User identification — the most important part
Typical mistake: call identify right upon registration without alias for anonymous history.
Correct scenario:
let mixpanel = Mixpanel.mainInstance()
// Before authorization — anonymous distinct_id is generated automatically
// mixpanel.distinctId contains UUID
// After successful registration:
mixpanel.alias(newId: "user_\(userId)", distinctId: mixpanel.distinctId)
mixpanel.identify(distinctId: "user_\(userId)")
// After login to existing account (no alias!):
mixpanel.identify(distinctId: "user_\(userId)")
alias creates a permanent link between anonymous and authorized ID — this is a one-time operation. Calling alias again for an already-linked ID will cause duplication in the dashboard.
Events and Super Properties
Super Properties — attributes automatically added to each subsequent event:
mixpanel.registerSuperProperties([
"app_version": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "",
"platform": "ios",
"subscription_status": "free"
])
// Update when subscription changes:
mixpanel.registerSuperPropertiesOnce(["subscription_status": "premium"])
Custom event:
mixpanel.track(event: "Product Viewed", properties: [
"product_id": "sku_789",
"category": "electronics",
"price": 29990
])
People Analytics — user profiles
Mixpanel People allows building segments and sending push directly from the console:
let people = Mixpanel.mainInstance().people
people.set(["$name": "Ivan Petrov", "$email": "[email protected]"])
people.set(["plan": "premium", "total_orders": 5])
people.increment("total_orders", by: 1) // atomic increment
Profiles sync with events by distinct_id — in the dashboard you can click on a profile and see full action history.
Typical problems
Mixpanel buffers events in NSUserDefaults on iOS. On crash before batch sending, data persists and goes on next launch. This is good. The problem is different: if distinct_id isn't set explicitly (e.g., calling reset() on logout), subsequent events go under a new anonymous ID — and the funnel breaks. Use reset() only on account switch, not on every logout.
What's included in the work
- SDK connection for iOS/Android
- Identification setup: anonymous flow → alias → identify
- Super Properties for cross-cutting context
- Tracking key events by plan
- People Analytics with profiles
- Event verification through Mixpanel Live View
Timeline
Integration with correct identification and events: 1–2 days. Cost calculated individually.







