User Identifier and Properties

๐Ÿ“˜

Managing User Identifiers

User identifiers are used to uniquely identify users. For information on the meaning, importance, and criteria for choosing user identifiers, please refer to the Managing User Identifiers documentation.

Using Managed Identifiers in the SDK

The Flutter SDK includes functionality to manage device identifiers. Therefore, you can automatically identify users without explicitly providing user identifiers.

You can obtain managed identifiers in the SDK as follows:

import "package:hackle/hackle.dart";

// Get the internally managed device identifier
String deviceId = await HackleApp.getDeviceId();

// Get the all of indentifiers has been set
HackleUser user = await HackleApp.getUser();

Adding User Identifiers

You can set the identifier of a logged-in user. If you manage the device identifier separately, you can set it separately.

Example

import "package:hackle/hackle.dart";
// 1. Set the identifier of the logged-in user
await HackleApp.setUserId("LOGIN_ID");

// 2. Change the device identifier
await HackleApp.setDeviceId("CUSTOM_DEVICE_ID");

Additional Identifiers

You can send additional identifiers other than the default identifiers using the example code below.

import "package:hackle/hackle.dart";

HackleUser user = HackleUser.builder()
	.userId("LOGIN_ID") // User ID (Hackle unified identifier can be used)
	.deviceId("CUSTOM_DEVICE_ID") // Device ID (Hackle unified identifier can be used)
	.identifier("myCustomId", "CUSTOM_IDENTIFIER") // Custom ID
	.build();

await HackleApp.setUser(user);

Properties

Hackle SDK supports adding properties to a User object.

  • Properties must be sent as a pair with both property name (key) and a property value (value).
  • The maximum number of properties that can be added to a User object is 64.

Property Key (Name)

  • The key should be set as a general name, but easily identifiable.
  • The character limit is 64 characters.
  • It is not case sensitive. For example, AGE and age are recognized as the same key.

Property Value

  • The value supports boolean, string, and number types.
  • In the case of string type, the character limit is 64 characters.
  • The string type is case-sensitive. For example, APPLE and apple are recognized as different property values.
  • In the case of number type, up to 15 integers and up to 6 decimal places are supported.

Setting User Properties

You can add or remove user properties.

To set user properties, instantiate a PropertyOperations object with the properties you want to set. Then, call updateUserProperties to update the user properties. You can set multiple properties at once.

PropertyOperations operations = PropertyOperations.builder()
  .set("age", 42)
  .set("grade", "GOLD")
  .setOnce("sign_up_date", "2020-07-03")
  .build();

await HackleApp.updateUserProperties(operations);

set

Set user properties. It overrides the existing property value with the specified value.

PropertyOperations operations = PropertyOperations.builder()
    .set("age", 42)
    .set("grade", "GOLD")
    .build();

await HackleApp.updateUserProperties(operations);

setOnce

Set user properties with a value that can be set only once. If a property key already exists, setOnce is ignored. For example, you can set properties like the signup date and initial location for a user.

PropertyOperations operations = PropertyOperations.builder()
    .setOnce("sign_up_date", "2020-07-03")
    .setOnce("initial_location", "Seoul")
    .build();

await HackleApp.updateUserProperties(operations);

unset

Remove the specified user properties.

PropertyOperations operations = PropertyOperations.builder()
    .unset("membership_type")
    .build();

await HackleApp.updateUserProperties(operations);

clearAll

Remove all user properties.

PropertyOperations operations = PropertyOperations.clearAll();

await HackleApp.updateUserProperties(operations);

Resetting User Properties

When a user logs out, you need to reset the previously set information. You can do this by calling the following method:

import "package:hackle/hackle.dart";

await HackleApp.resetUser();

When you call resetUser(), all previously set identifiers and properties are reset.