Skip to main content

Identifying Users

AppActor manages user identity to associate purchases with the correct user across devices and sessions.

How Identity Worksโ€‹

When you first configure the SDK in payment mode, AppActor automatically creates an anonymous user. You can then identify this user with your own user ID when they log in.

Identifyโ€‹

Call identify to associate the current device with a known user ID. This is typically called after your user logs in.

// After user logs into your app
try await AppActor.shared.identify(appUserId: "user_123")

The identify call sends the following to the backend:

{
"appUserId": "user_123",
"platform": "ios",
"appVersion": "2.1.0",
"sdkVersion": "1.0.0",
"deviceModel": "iPhone15,2",
"osVersion": "17.0"
}
tip

Call identify as early as possible after your user authenticates. This ensures purchases are correctly attributed to the user.

Loginโ€‹

Use logIn to switch from the current user to a new identified user.

// Switch from current user to a different user
try await AppActor.shared.logIn(newAppUserId: "user_456")

Logoutโ€‹

Call logOut when the user signs out of your app. This creates a new anonymous user.

// User signs out โ€” creates new anonymous user
try await AppActor.shared.logOut()

After logout, a new anonymous user is created. Any new purchases will be associated with this anonymous user until identify is called again.

Identity Flow Diagramโ€‹

Best Practicesโ€‹

  1. Call identify early โ€” As soon as you know the user's ID, call identify
  2. Use stable user IDs โ€” Use your backend's user ID, not email addresses
  3. Max 255 characters โ€” User IDs must be 255 characters or fewer
  4. Handle errors โ€” Identity calls can fail if the network is unavailable
do {
try await AppActor.shared.identify(appUserId: currentUser.id)
} catch {
// Handle error โ€” the SDK will continue with the anonymous user
print("Failed to identify user: \(error)")
}

Next Stepsโ€‹