# 세션 관리

세션(Session)은 사용자의 연속된 앱 사용 구간을 의미하며, 특정 조건에 따라 시작되고 만료됩니다.

### 세션 시작 조건

세션은 기본적으로 아래 조건으로 시작됩니다.

* 식별자가 변경된 경우
* 세션 만료 시간이 지난 후 이벤트가 발생한 경우

### 세션 만료 조건

새로운 세션이 시작될 때 이전 세션은 만료됩니다.

* 세션 만료 시각은 마지막 이벤트 발생 시간과 동일합니다.

### 세션 정책 (Session Policy)

세션 정책은 세션의 유지 조건과 만료 조건을 세밀하게 제어할 수 있는 기능입니다. 세션 정책은 두 가지 조건으로 구성됩니다.

#### 세션 유지 조건 (Persist Condition)

식별자가 변경될 때 기존 세션을 유지할지, 새로운 세션을 시작할지 결정합니다.

| 구분               | 기본값     | 설명                                                                             |
| ---------------- | ------- | ------------------------------------------------------------------------------ |
| alwaysNewSession | default | 식별자가 변경되면 항상 새로운 세션을 시작합니다.                                                    |
| nullToUserId     |         | userId가 null에서 특정 값으로 변경될 때 (로그인 시) 기존 세션을 유지합니다. 그 외의 식별자 변경 시 새로운 세션을 시작합니다. |

#### 세션 만료 조건 (Timeout Condition)

세션이 만료되는 조건을 설정합니다.

| 설정                       | 기본값         | 설명                                                   |
| ------------------------ | ----------- | ---------------------------------------------------- |
| timeout                  | 1800초 (30분) | 세션 만료 시간입니다.                                         |
| onForeground             | false       | foreground에서 이벤트 발생 시 타임아웃 체크 여부입니다.                 |
| onBackground             | true        | background에서 이벤트 발생 시 타임아웃 체크 여부입니다.                 |
| onApplicationStateChange | true        | 앱 상태 변경 (`foreground <-> background`) 시 타임아웃을 체크합니다. |

{% hint style="info" %}
세션 정책의 구체적인 설정 코드는 각 SDK의 SDK 연동 문서를 참고하세요.
{% endhint %}


---

# 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/getting-started/user-identifier/session-management.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.
