User Identifier and Properties

Managing User Identifiers

User identifiers are used to uniquely identify different users.
Refer to the Managing User Identifiers document for an in-depth definition and understanding of why user identifiers are so important during experimentation.

Use SDK-managed identifiers

The Android SDK includes features to automatically manage device identifiers. Therefore, the user can be automatically identified without having to manually pass the user identifier separately as a parameter.

Here's how to obtain the identifiers managed internally by the SDK:

// Retrieve the internally managed device ID
let deviceId: String = hackleApp.deviceId
// Retrieve the internally managed device ID
NSString *deviceId = [hackleApp deviceId];

Use custom user identifiers you manage

This is a method of directly passing a user identifier as a parameter. The identifier to be delivered can be a directly managed primary key, device identifier, member ID, email, hash value, etc.

Example

The following is an example of sending a user event after distributing users to a test group.

// 1. Using SDK-managed identifiers - do not pass user identifiers in parameters
let variation: String = hackleApp.variation(experimentKey: 42)
hackleApp.track(event: event)

// 2. Using user identifiers managed manually yourself - pass user identifiers in parameters
let variation: String = hackleApp.variation(experimentKey: experimentKey, userId: "ae2182e0")
hackleApp.track(event: event, userId: "ae2182e0")
// 1. Using SDK-managed identifiers - do not pass user identifiers in parameters
NSString *variation = [hackleapp variationWithExperimentKey:experimentKey 
                                 defaultVariation:@"A"];
[hackleApp trackWithEvent:event];

// 2. Using user identifiers managed manually yourself - pass user identifiers in parameters
NSString *variation = [hackleApp variationWithExperimentKey:experimentKey 
                                 userId:@"ae2182e0"
                                 defaultVariation:@"A"];

[hackleApp trackWithEvent:event userId:@"ae2182e0"]

Property

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.

Example

User objects are used as parameters in distributing traffic into test groups, determining feature flags, and sending user events.

Refer to the example code and add the desired properties to each user. In the example below, you can see that three properties (age, grade, is_paying_user) have been added.

let properties = [
    "age": 30, 
    "grade": "GOLD", 
    "is_paying_user": false
]
let user: User = Hackle.user(id: "ae2182e0", properties: properties)
    
// Traffic distribution to test groups
let variation = hackleApp.variation(experimentKey: experimentKey, user: user)

// Feature flag determination
let isFeatureOn = hackleApp.isFeatureOn(featureKey: featureKey, user: user)

// Send user events 
hackleApp.track(event: event, user: user)
NSDictionary *properties = @{
    @"age": @30,
    @"grade": @"GOLD",
    @"is_paying_user": @false
};
User *user = [Hackle userWithId:@"ae2182e0" properties:properties];
    
// Traffic distribution to test groups
NSString *variation = [hackleApp variationWithExperimentKey:experimentKey 
                                 user:user 
                                 defaultVariation:@"A"];

// Feature flag determination
bool isFeatureOn = [hackleApp isFeatureOnFeatureKey:featureKey user:user];

// Send user events 
[hackleApp trackWithEvent:event user:user];

Did this page help you?