Track users across sessions, devices, and platforms with aliases
Identity management allows you to track users across different sessions, devices, and platforms by associating multiple identifiers (aliases) with a single user profile.
do { let alias = Alias(tag: "internal_id", identity: userId) try Permutive.shared.setIdentities(aliases: [alias])} catch { print("Failed to set identity: \(error)")}
For apps tracking multiple identifier types (email, user ID, etc.):
do { let aliases = [ // Highest priority: hashed email Alias(tag: "email_sha256", identity: emailHash), // Medium priority: internal user ID Alias(tag: "internal_id", identity: userId, priority: 1), // Lower priority: with expiry date Alias( tag: "session_id", identity: sessionId, priority: 2, expiry: Date().addingTimeInterval(86400 * 30) // 30 days ) ] try Permutive.shared.setIdentities(aliases: aliases)} catch { print("Failed to set identities: \(error)")}
Permutive recommends against using IDFA due to Apple’s App Tracking Transparency requirements. Consider using identifierForVendor or hashed email addresses instead.
From v2.6.0, the IDFA, IDFV, and IP address can be collected automatically when enabled in your workspace config — no manual code required. See the v2.6 Migration Guide. If you opt into automatic collection, you generally don’t need the manual setIdentityForIDFA flow below.
If you do need to set IDFA manually, use the dedicated setIdentityForIDFA method:
import AdSupportimport AppTrackingTransparencyimport Permutive_iOSfunc setIDFAIdentity() { if #available(iOS 14, *) { ATTrackingManager.requestTrackingAuthorization { status in guard status == .authorized else { return } let idfa = ASIdentifierManager.shared().advertisingIdentifier do { try Permutive.shared.setIdentityForIDFA(idfa) } catch { // IDFA may be all zeros (tracking denied) print("Failed to set IDFA: \(error)") } } }}
Use TriggerAction to react when the user ID changes:
var userIdTrigger: TriggerAction?func watchUserIdChanges() { userIdTrigger = Permutive.shared.triggerProvider?.actionUpdateForUserIdentity { userId in print("User ID changed to: \(userId)") }}// Release when donedeinit { userIdTrigger = nil}
Problem: Same user appears as two different users.Solution: Use consistent alias tags and values. When a user logs in on multiple devices, use the same alias (e.g., hashed email).
Reserved tag error
Problem: Alias with certain tags is ignored.Solution: Avoid reserved tags: appnexus, amp, gigya, sailthru, aaid. Use custom tags instead.