identify()
A function that creates an account with Superwall by linking a userId to the automatically generated alias.
Call this as soon as you have a user ID, typically after login or when the user's identity becomes available.
Purpose
Links a user ID to Superwall's automatically generated alias, creating an account for analytics and personalization.
Signature
fun Superwall.identify(
userId: String,
options: IdentityOptions? = null
)
// Java
public void identify(
String userId,
@Nullable IdentityOptions options
)
Parameters
Name | Type | Description |
---|---|---|
userId | String | Your user's unique identifier, as defined by your backend system. |
options | IdentityOptions? | Optional configuration for identity behavior. Set restorePaywallAssignments to true to wait for paywall assignments from the server. Use only in advanced cases where users frequently switch accounts. Defaults to null . |
Returns / State
This function returns Unit
. After calling, isLoggedIn
will return true
and userId
will return the provided user ID.
Usage
Basic identification:
Superwall.instance.identify("user_12345")
With options for account switching scenarios:
val options = IdentityOptions().apply {
restorePaywallAssignments = true
}
Superwall.instance.identify(
userId = "returning_user_67890",
options = options
)
Call as soon as you have a user ID:
fun userDidLogin(user: User) {
Superwall.instance.identify(user.id)
// Set additional user attributes
Superwall.instance.setUserAttributes(mapOf(
"email" to user.email,
"plan" to user.subscriptionPlan,
"signUpDate" to user.createdAt
))
}
Java usage:
// Basic identification
Superwall.getInstance().identify("user_12345");
// With options
IdentityOptions options = new IdentityOptions();
options.setRestorePaywallAssignments(true);
Superwall.getInstance().identify("returning_user_67890", options);
How is this guide?