# Session Management

> Generate the userId and sessionId that every event must carry.

Every event must include both `userId` and `sessionId`.

These two fields are used together to uniquely identify:
- the user in your store
- the user’s current session during their visit

### Generating IDs with Segmentify

You can generate these IDs by sending a `GET` request to your account-specific data center URL using this endpoint:

```text
/get/key?count=
```

You can find your data center URL in `Account Settings -> Integrations`.

Example data center URL:

```text
https://xxx.segmentify.com
```

Use the `count` parameter based on what you need:
- `count=1` returns one key for `sessionId`
- `count=2` returns two keys for both `userId` and `sessionId`

### Example requests

```http
GET https://xxx.segmentify.com/get/key?count=1
```

Returns one key to use as `sessionId`.

```http
GET https://xxx.segmentify.com/get/key?count=2
```

Returns two keys to use as `userId` and `sessionId`.

### Example response

If you request two keys, the response will look like this:

```text
["XXXXXXXXXXXXXXXXXXXXXXX","YYYYYYYYYYYYYYYYYYYY"]
```

Recommended mapping:
- first value -> `userId`
- second value -> `sessionId`

### Alternative approach

You can also generate your own IDs instead of requesting them from Segmentify.

If you use your own IDs:
- they can be any string
- each `userId` must uniquely identify a user
- each `sessionId` must uniquely identify a session

### Recommended flow

1. Check whether the visitor already has a `userId`.
2. If not, request 2 keys and store them as `userId` and `sessionId`.
3. If the visitor already has a `userId` but starts a new visit, request 1 key for a new `sessionId`.
4. Include both `userId` and `sessionId` in every event.

## Request SessionId

`GET /get/key`

See this endpoint in the [Events API reference](/reference/events/).

## Request UserId and SessionId

`GET /get/key`

See this endpoint in the [Events API reference](/reference/events/).
