User Identity APIs in Mobile SDKs

Learn about the different user identity APIs available in the Android (Kotlin) and iOS (Swift) SDKs.

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)

iOS (Swift)

The above snippets return the following information:

Property nameReturn typeDescription
userIdString?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 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)

iOS (Swift)

The above snippets return the following information:

Property nameReturn typeDescription
anonymousIdString?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)

iOS (Swift)

The above snippets return the following information:

Property nameReturn typeDescription
traitsJsonObject? / [String: Any]?A structured object containing the user’s traits.

Note that:

  • The SDK returns null if the Analytics instance is shut down.
  • The traits return type in Java is Map<String, Object>.
  • The traits return type in iOS (Swift) is [String: Any]?.

Questions? Contact us by Email or on Slack