User Identity APIs in Mobile SDKs
2 minute read
This guide covers the user identity APIs that help you retrieve the following parameters persisted by the RudderStack Android (Kotlin) and iOS (Swift) SDKs:
Fetch user ID
The Android (Kotlin) and iOS (Swift) SDKs assign a unique userId when an identify event is triggered. This parameter uniquely identifies a user within the database after they log in or sign up.
The following sections highlight how to obtain the user’s userId in Android (Kotlin) and iOS (Swift) SDKs.
Android (Kotlin)
val userId = analytics.userIdString userId = analytics.getUserId();iOS (Swift)
let userId = analytics.userIdNSString* userId = self.analytics.userId;The above snippets return the following information:
| Property name | Return type | Description |
|---|---|---|
userId | String? | The stored userId for the user.Note: The SDK returns null if the Analytics instance is shut down. |
Fetch anonymous ID
anonymousId is a unique identifier automatically generated by the SDK as a random UUID (Universally Unique Identifier) to track unidentified users, for example, users before they log in or sign up. This ID persists across sessions and allows tracking user behavior before they are identified explicitly.
The following sections highlight how to obtain the user’s anonymousId in Android (Kotlin) and iOS (Swift) SDKs.
Android (Kotlin)
val anonymousId = analytics.anonymousIdString anonymousId = analytics.getAnonymousId();iOS (Swift)
let anonymousId = analytics.anonymousIdNSString* anonymousId = self.analytics.anonymousId;The above snippets return the following information:
| Property name | Return type | Description |
|---|---|---|
anonymousId | String? | The stored anonymousId for the user.Note: The SDK returns null if the Analytics instance is shut down. |
Fetch user traits
The Android (Kotlin) and iOS (Swift) SDKs use the traits object to store any additional user attributes, for example, name, email, custom properties, etc. associated with an identify event. These traits allow for richer user profiling and segmentation.
The following sections highlight how to obtain the user traits in Android (Kotlin) and iOS (Swift) SDKs.
Android (Kotlin)
val traits = analytics.traitsMap<String, Object> traits = analytics.getTraits();iOS (Swift)
let traits = analytics.traitsNSDictionary *traits = self.analytics.traits;The above snippets return the following information:
| Property name | Return type | Description |
|---|---|---|
traits | JsonObject? / [String: Any]? | A structured object containing the user’s traits. Note that:
|