Working with Users

User IDs can be used for reporting purposes and for storing the read status of users. By default, the Storyteller SDK creates an externalId for users when the SDK is first initialized. This is stored until the user uninstalls the app.

However, if you have a user account system then you may wish to set your own user IDs within the Storyteller SDK.

The externalId should be an identifier which is unique per user and does not change. Therefore, using something like the user's email address is not a good choice for an externalId as the user may change it at some point in the future. However, using a unique UUID/GUID would be a good choice as it is guaranteed to not change over time.

Setting a User ID

In order to supply a externalId to the Storyteller SDK, call the following method:

    Storyteller.initialize(
      apiKey = "[APIKEY]",
      useInput = UserInput("unique-externalId"),
      onSuccess = {
    // onSuccess action
    },
      onFailure = { error ->
    // onFailure action
    }
  )

This should be called as soon as the value for the externalId is known in your app. For example, this could be on app start or when a user logs in.

Current User Information

You can access the following information about the current user via the following properties:

Storyteller.currentUser       // Returns the current user info
Storyteller.currentApiKey       // Returns the current api key

Changing Users

If you use login in your app and wish to allow users to logout and log back in as a new user (or proceed as an anonymous user) then when a user logs out you should call initialize again, specifying a new externalId. Note that this will reset the local store of which Pages the user has viewed.

PREVIOUS
Forward Arrow