Skip to main content
Version: SDK 4.7.x

Get the justtrack user ID

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 this ID by accessing the userId property on the justtrack SDK:

sdk.getUserId().observe { result in
switch result {
case let .success(userId):
print("My user ID is \(userId)")
case let .failure(error):
print("Something went wrong: \(error)")
}
}

Provide your own user ID

If you already have a mechanism to assign a unique ID to each user, you can share this information with the justtrack SDK. This then allows the backend of the justtrack SDK to associate events received from third parties via that user ID with the correct user on justtrack side. You can provide an ID multiple times, the justtrack SDK takes care about sending it to the justtrack backend as needed.

You can supply your own user ID when constructing the SDK as well as sending it later once your app is already running for some time. Should your own user ID change for some reason, you have to supply the new value to the justtrack SDK again:

var ownUserId = /* get your own user ID from your app */
let builder = /* create the builder somehow */ JustTrackSdkBuilder(apiToken: "prod-...")
let sdk = builder
.set(customUserId: ownUserId)
// other options...
.build()

ownUserId = /* new user ID for some reason */
sdk.set(customUserId: ownUserId)

A custom user ID must be shorter than 4096 characters and only consist of printable ASCII characters (U+0020 to U+007E).