User Identifier & Properties
For functions that change user information (setUser, setUserId, setDeviceId, updateUserProperties, resetUser, and so on), we recommend using the variants that take a callback.
The callback is invoked after the changed user information has been applied to the SDK.
User Identifier
Default Identifiers Provided by Hackle
The Android SDK includes functionality to manage the device's identifier. Therefore, users can be automatically identified without separately providing a User Identifier.
You can query the identifiers managed by the SDK as follows.
// Get the device ID
val deviceId = hackleApp.deviceId
// Get the session ID
val sessionId = hackleApp.sessionId
// Get all user information
val user = hackleApp.user// Get the device ID
String deviceId = hackleApp.getDeviceId();
// Get the session ID
String sessionId = hackleApp.getSessionId();
// Get all user information
User user = hackleApp.getUser();Modify Device ID
You can inject a custom device ID instead of using the device ID provided by Hackle.
Set User Identifier (User ID)
You can set the identifier for a logged-in user.
Additional Identifiers
You can add identifier types other than the default identifiers (deviceId, userId) as follows.
Calling setUser overwrites the current device's user information.
If you are currently using userId A and call
setUserwithout passing userId A, the userId changes from A to null.If you are currently using a custom deviceId and call
setUserwithout passing the current deviceId, the custom deviceId reverts to the Hackle deviceId.If you use additional identifiers and do not pass them when calling
setUser, the additional identifiers are reset.For properties, the cached properties on the device may be retained or reset in the following cases:
If the userId and deviceId are the same before and after
setUser, cached properties are retained.If the userId or deviceId changes before and after
setUser, cached properties are deleted.
User Property
The Hackle SDK supports adding user properties.
Properties must be sent as key-value pairs (Property Key and Property Value).
A maximum of 128 properties can be added.
Property Key
string
Character limit is 128 characters.
Case-insensitive.
For example, AGE and age are recognized as the same Property Key.
Property Value
boolean, string, number, array
For string type, the character limit is 1024 characters.
String type is case-sensitive.
For example, APPLE and apple are recognized as different Property Values.
For number type, up to 15 integer digits and up to 6 decimal places are supported.
Add User Property
You can add a user property simply by adding it with set on a PropertyOperations object and then calling updateUserProperties.
The setUserProperty function is deprecated as of Android SDK 4.0.0. Use updateUserProperties instead.
Configure User Properties
You can add or remove user properties.
set
Sets a User Property. If a Property Value already exists for the Property Key, it is overwritten.
setOnce
Sets a User Property value only once. If a property already exists for the Property Key, it is ignored.
For example, you can use this to set a user's registration date or initial sign-up location.
unset
Removes a User Property.
clearAll
Removes all User Properties.
Instantiate a PropertyOperations object with the user properties you want to configure. Then call updateUserProperties to update the user properties. You can configure multiple properties at once.
Reset User
You need to reset the previously configured information. When reset, all previously configured identifiers and properties are cleared.
Resetting the user also clears all user properties stored on the server. If you want to handle logout, use hackleApp.setUserId(null).
Setting null to userId handles logout on the client side.
Last updated