When using the AppCenter API for android Kotlin, Am I allowed to change my UserId multiple times in the same session

Issue

Sorry for the ambiguity in the question but it is actually quite a simple one.

When my android Application boots up I initialize AppCenter as follows:

   AppCenter.start(
        this, BuildConfig.APP_CENTER_SECRET,
        Analytics::class.java, Crashes::class.java, Distribute::class.java
    )
    if(BuildConfig.FLAVOR ! ApplicationVariants.ProductFlavors.PRODUCTION){
        AppCenter.setLogLevel(Log.VERBOSE)
    }
    AppCenter.setUserId(UUID.randomUUID().toString())
    Distribute.setUpdateTrack(UpdateTrack.PUBLIC)
    Distribute.checkForUpdate()

However, when the user logs into the application I would like to set the UserId to the users email as follows once the user logs in:

JwtUtils.getIdentityTokenModel(requireContext())?.let {
        AppCenter.setUserId(it.email)
    }

Lastly when the user logs out I reset the user Id to a random guid. The reason for this is visibility on which user has which crash logs. This is a requirement from business.

However, in the app center crash logs, it seems the UserId never changes to the email even if an error occurs while the user is logged in.

My question is simple. Is there a restriction on how many times I am allowed to change the AppCenter User Id? I cannot seem to find it anywhere in the docs.

Thanks in advance

Solution

Please see these docs about userId API:

The value for the user ID is limited to 256 characters. It will be shown with your crash reports but not used for aggregation or counts of affected users. In case you set user ID multiple times, only the last user ID will be used. You need to set the user ID yourself before each application launch, because this value isn’t stored by the SDK between launches.

Answered By – Anastasia

Leave a Comment