User Identity APIs in Mobile SDKs

Learn about the different user identity APIs available in the Kotlin and Swift SDKs.

This guide covers the user identity APIs that help you retrieve the following parameters persisted by the Kotlin and Swift SDKs:

Fetch user ID

The Kotlin and 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 the Kotlin and Swift SDKs.

Kotlin

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 the Kotlin and Swift SDKs.

Kotlin

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 Kotlin and 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 the Kotlin and Swift SDKs.

Kotlin

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 Swift is [String: Any]?.

Questions? Contact us by email or on Slack