Superwall

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

public func identify(
  userId: String,
  options: IdentityOptions? = nil
)

Parameters

NameTypeDescription
userIdStringYour user's unique identifier, as defined by your backend system.
optionsIdentityOptions?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 nil.

appAccountToken must be a UUID to be accepted by StoreKit.

If the userId you pass to identify is not a valid UUID string, StoreKit will not accept it for appAccountToken and the SDK will fall back to the anonymous alias UUID. This can cause the identifier in App Store Server Notifications to differ from the userId you passed. See Apple's docs: appAccountToken.

Returns / State

This function returns Void. After calling, isLoggedIn will return true and userId will return the provided user ID.

Usage

Basic identification:

Superwall.shared.identify(userId: "user_12345")

With options for account switching scenarios:

let options = IdentityOptions()
options.restorePaywallAssignments = true

Superwall.shared.identify(
  userId: "returning_user_67890",
  options: options
)

Call as soon as you have a user ID:

func userDidLogin(user: User) {
  Superwall.shared.identify(userId: user.id)
  
  // Set additional user attributes
  Superwall.shared.setUserAttributes([
    "email": user.email,
    "plan": user.subscriptionPlan,
    "signUpDate": user.createdAt
  ])
}

How is this guide?