Identify API in Mobile SDKs

Learn about the identify API call in the Android (Kotlin) and iOS (Swift) SDKs.

This guide explains how to use the identify API in the RudderStack Android (Kotlin) and iOS (Swift) SDKs.

Overview

The RudderStack Android (Kotlin) and iOS (Swift) SDKs provide an identify API that lets you identify a user and associate them to their actions. It also lets you record any traits about them like their name, email, etc.

info
Once you make the identify call, the SDK persists the user information and passes it to the subsequent calls.

Android (Kotlin)

The identify method definition in the Android (Kotlin) SDK is as follows:

Method signature

The below table describes the identify method signature in detail:

FieldData type
Description
userId
Required, if traits is not present
StringUnique user identifier. When provided, RudderStack prefers this field over anonymousId while sending data to the destinations.
traits
Required, if userId is not present
TraitsContains the user traits or the properties associated with userId such as email, address, etc. See Identify traits for more information.

Note that:

  • RudderStack stores the traits as context.traits in the final event object.
  • The traits type in Java is Map<String, Object>.
optionsRudderOptionAdditional event options.

Example

A sample identify event sent from the Android (Kotlin) SDK is shown below:

iOS (Swift)

The identify method definition in the iOS (Swift) SDK is as follows:

Method signature

The below table describes the identify method signature in detail:

FieldData type
Description
userId
Required, if traits is not present
StringUnique user identifier. When provided, RudderStack prefers this field over anonymousId while sending data to the destinations.
traits
Required, if userId is not present
PropertiesContains the user traits or the properties associated with userId such as email, address, etc. See Identify traits for more information.
optionsRudderOptionAdditional event options.

Example

A sample identify event sent from the Swift SDK is shown below:

Implicit reset when existing userId changes

When you call identify with a userId that differs from the currently persisted userId, the SDK internally calls reset() before updating the user identity — this clears the previous user data and refreshes the session.

Calling identify on an anonymous user (no prior userId) does not trigger a reset.

See the reset API documentation for more information on the implicit reset behavior and how you can preserve specific data during a user switch.


Questions? We're here to help.

Join the RudderStack Slack community or email us for support