User Identity APIs in Kotlin SDK
Alpha
Learn about the different user identity APIs available in the Kotlin SDK.
This guide covers the user identity APIs that help you retrieve the following parameters persisted by the Kotlin SDK:
Fetch user ID
The SDK assigns 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 snippet highlights how to obtain the user’s userId
:
val userId = analytics.userId
The above snippet returns 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 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 snippet highlights how to obtain the user’s anonymousId
:
val anonymousId = analytics.anonymousId
The above snippet returns 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 SDK uses 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 snippet highlights how to obtain the user’s userId
:
val traits = analytics.traits
The above snippet returns the following information:
Property name | Return type | Description |
---|
traits | JsonObject? | A structured object containing the user’s traits.
Note: The SDK returns null if the Analytics instance is shut down. |
Questions? Contact us by email or on
Slack