Skip to main content
Version: SDK 4.5.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 a Future resolving to this ID by using the getUserId method on the justtrack SDK:

const userId: string = await JustTrackSdk.getUserId();
console.log('My user id is ' + userId);

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.

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 as an ID multiple times, the justtrack SDK takes care about sending it to the justtrack backend as needed.

You can supply the 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:

await new JustTrackSdk.JusttrackSdkBuilder(apiKey)
.withCustomUserId('new_id')
.initialize();

await JustTrackSdk.setCustomUserId('new_id'); /* new user ID for some reason */

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