User Management

Identify users and set attributes from shared Kotlin code.

Beta

The KMP SDK is in beta and its API may change between releases.

It is necessary to uniquely identify users to track their journey within Superwall.

Anonymous users

Superwall automatically generates a random user ID that persists until the user deletes or reinstalls your app. You do not have to do anything to get one.

Superwall.userId      // the generated alias, or your ID once identified
Superwall.isLoggedIn  // false until identify() is called

Identified users

If you have your own user management system, call identify as soon as you have an ID, right after log in or sign up. This aliases your ID with the anonymous Superwall ID, which is what lets us load that user's assigned paywalls.

// After retrieving a user's ID, e.g. from logging in or creating an account
Superwall.identify(userId = user.id)

// When the user signs out
Superwall.reset()

reset() returns the user to a fresh random ID and clears on-device paywall assignments and stored data.

Waiting for assignments

If your users switch accounts often, or delete and reinstall frequently, you can make the SDK hold paywalls back until assignments have been restored from the server:

import com.superwall.sdk.kmp.models.identity.IdentityOptions

Superwall.identify(
    userId = user.id,
    options = IdentityOptions(restorePaywallAssignments = true),
)

This is an advanced option and defaults to false. Turning it on delays paywall presentation until assignments arrive, so only reach for it when logging a user into an existing account.

User attributes

Attributes are usable in audience filters and can be templated onto paywalls.

Superwall.setUserAttributes(
    mapOf(
        "firstName" to "Jack",
        "plan" to "trial",
        "workoutCount" to 12L,
    ),
)

Values may be String, Boolean, Long, Double, List, Map, or Set. Anything else is stringified.

setUserAttributes merges rather than replaces. Keys you pass are merged into the existing attributes, a null value removes that key, and keys you leave out are untouched.

That asymmetry is deliberate, and it is why this is a method rather than a settable property: reading Superwall.userAttributes after setting will not give you back only what you set.

// Remove a single attribute
Superwall.setUserAttributes(mapOf("plan" to null))

// Read the current snapshot
val attributes = Superwall.userAttributes

Third-party integration attributes

To line Superwall up with your analytics and attribution providers, set integration attributes:

import com.superwall.sdk.kmp.models.events.IntegrationAttribute

Superwall.setIntegrationAttribute(IntegrationAttribute.AMPLITUDE_DEVICE_ID, "device-123")

Superwall.setIntegrationAttributes(
    mapOf(
        IntegrationAttribute.AMPLITUDE_USER_ID to "user-abc",
        IntegrationAttribute.MIXPANEL_DISTINCT_ID to "distinct-xyz",
    ),
)

// Passing null removes an attribute
Superwall.setIntegrationAttribute(IntegrationAttribute.AMPLITUDE_USER_ID, null)

Read them back with Superwall.integrationAttributes.

Device attributes

The device attributes Superwall tracks are also available for audience filters:

val deviceAttributes = Superwall.getDeviceAttributes()

Google Play account identifiers

By default the SDK SHA-256 hashes your userId before forwarding it to Google Play. If you need the raw appUserId to appear in Play Console and downstream server events, set passIdentifiersToPlayStore = true when configuring:

Superwall.configure(
    apiKey = "pk_your_api_key",
    options = SuperwallOptions(passIdentifiersToPlayStore = true),
)

This option is Android only and is ignored on iOS. Make sure the value complies with Google's policies, and note that it must not contain personally identifiable information.

Setting the locale

Override the locale used to evaluate audience filters, or pass null to follow the device:

Superwall.localeIdentifier = "en_GB"
Superwall.localeIdentifier = null // back to the device locale

Next, gate your features.

How is this guide?

On this page