Get the justtrack user ID (Deprecated)
Each user is assigned a unique user ID by the justtrack SDK which you can access inside your app. You can use this ID to recognize returning users in your app again. Should you already assign a unique ID to your users, you can also link your ID to the justtrack user ID.
The justtrack SDK provides you with a unique ID for each user.
You can retrieve a AsyncFuture
resolving to this ID by using the method on the justtrack SDK:getJusttrackUserId
- Java
- Kotlin
AsyncFuture<String> userIdFuture = sdk.getJusttrackUserId();
String userId = userIdFuture.get();
log("My user ID is " + userId);
val userIdFuture = sdk.justtrackUserId
val userId = userIdFuture.await()
log("My user ID is $userId")
To wait for the returned AsyncFuture
to resolve to a value, you need to call get
on it. This will block the current thread until the future resolves or throws an exception.
You can not call get
on the main (UI) thread! This is a safeguard for you as a AsyncFuture
you get back from the SDK might actually depend on work the main/UI thread is expected to do. Blocking that thread could then deadlock your app. If you call get
on the main thread, an exception will be thrown. You can either call the method on another thread or use registerCallback
to schedule a callback when the future resolves:
- Java
- Kotlin
AsyncFuture<Attribution> responseFuture = sdk.getAttribution();
responseFuture.registerCallback(new Promise<Attribution, Exception>() {
@Override
public void resolve(Attribution response) {
UUID userId = response.getJusttrackUserId();
log("My user ID is " + userId);
}
@Override
public void reject(@NonNull Exception exception) {
log("An error occurred", exception);
}
});
val responseFuture = sdk.attribution
responseFuture.registerCallback(object : Promise<Attribution> {
override fun resolve(response: Attribution) {
val userId = response.justtrackUserId.toString()
log("My user ID is $userId")
}
override fun reject(throwable: Throwable) {
log("An error occurred", exception)
}
})
If you are using Kotlin coroutines, you can use await
instead to suspend your current coroutine until the AsyncFuture
resolves to a result like this:
- Kotlin
myScope.launch {
try {
val responseFuture = sdk.attribution.await()
val userId = responseFuture.justtrackUserId.toString()
log("My user ID is $userId")
} catch (exception: Exception) {
log("An error occurred", exception)
}
}
If the attribution can not be performed because the user is offline, it will eventually fail. The SDK will then wait for a new internet connection and retry the attribution. An attribution obtained after the returned AsyncFuture
resolved to a failure value won't update the future. You have to subscribe to updates of the attribution using registerAttributionListener()
to receive the attribution.