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.
class AuthActivity : AppCompatActivity() { private val permutive by lazy { (application as MyApplication).permutive } fun onLoginSuccess(userId: String, email: String) { val emailHash = hashEmail(email) val aliases = listOf( Alias.create("email_sha256", emailHash, priority = 0), Alias.create("internal_id", userId, priority = 1) ) permutive.setIdentity(aliases) navigateToHome() } private fun hashEmail(email: String): String { val normalized = email.trim().lowercase() val bytes = MessageDigest.getInstance("SHA-256") .digest(normalized.toByteArray()) return bytes.joinToString("") { "%02x".format(it) } }}
Logout Flow
fun onLogout() { // Clear all persistent data lifecycleScope.launch(Dispatchers.IO) { permutive.clearPersistentData() .onSuccess { withContext(Dispatchers.Main) { navigateToLogin() } } .onFailure { error -> Log.e("Permutive", "Failed to clear data", error) } }}
Guest to Logged-In Transition
class UserManager(private val permutive: Permutive) { // User starts as guest (anonymous) fun onAppLaunch() { // SDK automatically creates anonymous ID } // User logs in or signs up fun onUserAuthenticated(userId: String, email: String) { val emailHash = hashEmail(email) // Permutive merges guest data with authenticated profile permutive.setIdentity( listOf( Alias.create("email_sha256", emailHash, priority = 0), Alias.create("internal_id", userId, priority = 1) ) ) }}
Problem: Same user appears as two different users.Solution: Use consistent alias tags and values. When user logs in on multiple devices, use the same alias (e.g., hashed email).
PII concerns
Problem: Worried about sending personally identifiable information.Solution:
Always hash emails and other PII with SHA-256
Normalize data before hashing (lowercase, trim whitespace)
Never send raw email addresses, phone numbers, or names