# User Identifier & Properties

{% hint style="info" %}
User Identifier Management

User identifiers are used to uniquely identify users. For information on the meaning and importance of user identifiers and criteria for choosing them, refer to the [Managing User Identifiers](/en/getting-started/user-identifier.md) documentation.
{% endhint %}

## User Identifier

### Default Identifiers Provided by Hackle

The JavaScript SDK includes functionality to manage device identifiers. Therefore, users can be automatically identified without separately providing a user identifier.

To retrieve the identifier managed by the SDK, use the following:

```javascript
// 사용자 정보 가지고 오기
const user = hackleClient.getUser();

// 디바이스 식별자 가지고 오기
const deviceId = user.deviceId;

// 내부적으로 관리되는 세션 식별자 가져오기
const sessionId = hackleClient.getSessionId();
```

#### Modifying Device ID

You can inject your own device ID instead of using the device ID provided by Hackle.

```javascript
// 디바이스 식별자 변경
hackleClient.setDeviceId("CUSTOM_DEVICE_ID");
```

#### Setting User Identifier (User ID)

You can set the identifier for a logged-in user.

```javascript
// 로그인 한 사용자 식별자 추가
hackleClient.setUserId("LOGIN_ID");
```

### Additional Identifiers

To add identifier types other than the default identifiers (deviceId, userId), configure as follows:

{% hint style="info" %}
Additional identifiers are not unified into the [Hackle ID](/en/getting-started/user-identifier/hackle-id.md).
{% endhint %}

{% hint style="danger" %}
Using `setUser` overwrites the user information of the current device.

* If you are currently using userId A and do not pass userId A when calling setUser, the userId changes from A to null.
* If you are currently using a custom deviceId and do not pass the current deviceId when calling setUser, the custom deviceId changes to the Hackle deviceId.
* If you are using 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, the cached properties are retained.
  * If either the userId or deviceId changes before and after setUser, the cached properties are deleted.
    {% endhint %}

```javascript
const user = {
  userId: "LOGIN_ID",           // 사용자 ID (핵클 통합 식별자 사용가능)
  deviceId: "CUSTOM_DEVICE_ID", // 디바이스 ID (핵클 통합 식별자 사용가능)
  identifiers: {
    myCustomId: "CUSTOM_IDENTIFIER" // Custom ID
  }
};

hackleClient.setUser(user);
```

## User Property

The Hackle SDK supports adding user properties.

* Properties must be sent as key-value pairs (Property Key and Property Value).
* The maximum number of properties that can be added is 128.

<table><thead><tr><th width="133.04296875">Category</th><th width="127.60546875">Type</th><th>Constraints</th></tr></thead><tbody><tr><td>Property Key</td><td><code>string</code></td><td><ul><li>Character limit is 128 characters.</li><li>Case-insensitive.</li><li>For example, AGE and age are recognized as the same Property Key.</li></ul></td></tr><tr><td>Property Value</td><td><code>boolean</code>, <code>string</code>, <code>number</code>, <code>array</code></td><td><ul><li>For string type, the character limit is 1024 characters.</li><li>String type is case-sensitive.</li><li>For example, APPLE and apple are recognized as different Property Values.</li><li>For number type, up to 15 integer digits and up to 6 decimal places are supported.</li></ul></td></tr></tbody></table>

### Adding User Properties

You can easily add user properties. Calling the function below works the same as adding a property using `set` in a PropertyOperations object.

```javascript
hackleClient.setUserProperty("gender", "female");
```

### Configuring User Properties

You can add or remove user properties.

<table><thead><tr><th width="150">Supported Functions</th><th>Description</th></tr></thead><tbody><tr><td><code>set</code></td><td>Sets a User Property. If a Property Value already exists for the Property Key, it is overwritten.</td></tr><tr><td><code>setOnce</code></td><td><p>Sets a User Property value only once. If a property already exists for the Property Key, it is ignored.</p><p>For example, you can use this to set a user's registration date or initial sign-up location.</p></td></tr><tr><td><code>unset</code></td><td>Removes a User Property.</td></tr><tr><td><code>clearAll</code></td><td>Removes all User Properties.</td></tr></tbody></table>

Instantiate a `PropertyOperationsBuilder` object with the user properties you want to configure. Then call `updateUserProperties` to update the user properties. You can also configure multiple properties at once.

```javascript
import { PropertyOperationsBuilder } from "@hackler/javascript-sdk"

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

hackleClient.updateUserProperties(operations);
```

## Resetting User

You need to reset previously configured information. Resetting clears all previously configured identifiers and properties.

{% hint style="danger" %}
Resetting a user also resets all user properties stored on the server. If you want to handle logout, use `hackleClient.setUserId(undefined);` instead.

Assigning undefined to userId handles logout on the client side.
{% endhint %}

```javascript
hackleClient.resetUser();
```

Calling `resetUser()` clears all previously configured identifiers and properties.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/en/development-guide/react/user-identifier.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
