3. User Creation

After initializing the SDK, the next crucial step is to create a Sentiance user, as this is essential for activating the various SDK features. To achieve this, you'll need to follow the user creation steps below.

1. Obtain an Authentication Code

This step requires server-side development.

To create a Sentiance user, you need to associate them with a user in your system. This process involves providing a unique user identifier from your system to Sentiance. In return, Sentiance generates a temporary authentication code, specifically linked to this user, through secure server-to-server communication. You can then use this authentication code with the Sentiance SDK to create the Sentiance user associated with the provided user identifier. This ensures proper linkage between Sentiance users and users in your system, enabling seamless integration and personalized user experiences while maintaining security and privacy measures. The Sentiance SDK can then deliver valuable insights based on the user's behavior and preferences.

Here are the user creation steps:

  1. When you decide to create a Sentiance user in your app, contact your backend and request a Sentiance authentication code.

  2. On your backend, create a corresponding request towards the Sentiance backend, including your user identifier. This request will be authenticated using a Sentiance API Key, which you can obtain from the Sentiance Insights Dashboard. Please remember that this API Key must never be transmitted to your app to maintain security.

  3. Retrieve the authentication code provided by Sentiance from your backend and forward it to your app.

  4. In your app, use this authentication code to create the Sentiance user as shown below.

2. Create a Sentiance User

After obtaining the authentication code in the step above, create a user by passing the code to the SDK's createUser method.

val options = UserCreationOptions.Builder(authenticationCode).build()

Sentiance.getInstance(context).createUser(options).addOnCompleteListener { operation ->
    if (operation.isSuccessful) {
        val userInfo = operation.result.userInfo
        Log.d(TAG, "Created a user with ID: ${userInfo.userId}")
    } else {
        val error = operation.error
        Log.e(TAG, "User creation failed with reason ${error.reason.name}. Details: ${error.details}")
    }
}

The provided code demonstrates how to create a Sentiance user using the authentication code received earlier. Upon successful user creation, you'll receive the user's information, including the unique user ID.

It's important to note that the SDK supports the presence of only one Sentiance user on the device at a time. If your app supports multiple users, such as through a login flow, you can utilize the SDK's reset functionality to remove the existing user from the device before creating a new one.

For more information on user creation, check out this page.

Last updated