# User and session identifiers
> Track user and session identifiers, including domain_userid, network_userid, session IDs, business user IDs, and the Snowplow ID, with session timeouts.
> Source: https://docs.snowplow.io/docs/events/identifiers/
> Documentation index: https://docs.snowplow.io/llms.txt

Snowplow tracks several identifiers to help you understand user behavior across sessions and devices. These include tracker-generated IDs stored on the client, server-generated IDs from the Collector, and business user IDs you set in your app.

Understanding how these identifiers work enables you to build a complete picture of user journeys, whether through real-time identity resolution with [Snowplow Identities](/docs/identities/), or identity stitching in your data models.

This page also covers which identifiers each tracker lets you set, session timeouts, and the client session entity.

## User identifiers

For identifiers in cookies, consider using the [Cookie Lifetime Extension service](/docs/sources/web-trackers/cookies-and-local-storage/cookie-extension/) to prevent identifier loss due to browser restrictions.

### Tracker-generated

This on-device user identifier is **generated by the tracker**. It takes the form of a UUID, and is [tracked differently](#set-identifiers-in-your-tracking-code) on web or mobile.

It's the default identifier used in our [dbt packages](/docs/modeling-your-data/modeling-your-data-with-dbt/dbt-models/) to identify users. The [Unified Digital](/docs/modeling-your-data/modeling-your-data-with-dbt/dbt-models/dbt-unified-data-model/) package coalesces the `domain_userid` and the `userId` property into a single `user_identifier` field, to make it easier to work with. The value can come from either place.

|                       | Web                                                          | Mobile                    |
| --------------------- | ------------------------------------------------------------ | ------------------------- |
| Event field           | `domain_userid`                                              | `userId`                  |
| Location in event     | [Atomic event property](/docs/fundamentals/canonical-event/) | Client session entity     |
| Persistance mechanism | Browser cookies                                              | App user settings storage |
| Unified Digital field | `user_identifier`                                            | `user_identifier`         |

> **Note: Mobile-specific identifiers**
>
> In mobile apps, there are additional on-device identifiers provided by the platform: advertising ID (IDFA) and vendor ID (IDFV, app set ID). These can be tracked in the [mobile entity](/docs/events/ootb-data/device-and-browser/#mobile-entity).

### Server-generated

The Snowplow Collector generates the `network_userid` user identifier. It's a UUID that's returned in the Collector's HTTP response to the tracker, as the `sp` cookie in a `Set-Cookie` header.

Whether the `network_userid` persists between events or sessions depends on the tracker:

| Tracker                                                                      | Persists within session | Persists across sessions | Mechanism                                                                                                     |
| ---------------------------------------------------------------------------- | ----------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------- |
| [Web](/docs/sources/web-trackers/tracking-events/#business-user-id)          | ✅                       | ✅                        | Stored in `sp` cookie                                                                                         |
| [iOS](/docs/sources/mobile-trackers/client-side-properties/)                 | ✅                       | ✅                        | Stored using `HTTPCookieStorage`                                                                              |
| [Android](/docs/sources/mobile-trackers/client-side-properties/)             | ✅                       | ✅                        | Stored using `SharedPreferences`                                                                              |
| [React Native](/docs/sources/react-native-tracker/client-side-properties/)   | ✅                       | ✅                        | Depends on platform used                                                                                      |
| [Flutter](/docs/sources/flutter-tracker/initialization-and-configuration/)   | ✅                       | ✅                        | Depends on platform used                                                                                      |
| [Roku](/docs/sources/roku-tracker/adding-data/)                              | ❌                       | ❌                        |                                                                                                               |
| [Node.js](/docs/sources/node-js-tracker/configuration/)                      | ❌                       | ❌                        |                                                                                                               |
| [Golang](/docs/sources/golang-tracker/adding-extra-data-the-subject-class/)  | ❌                       | ❌                        |                                                                                                               |
| [.NET](/docs/sources/net-tracker/subject/)                                   | ❌                       | ❌                        |                                                                                                               |
| [Java](/docs/sources/java-tracker/tracking-specific-client-side-properties/) | ✅                       | ❌/✅                      | Stored in memory by default; configure a `CollectorCookieJar` to persist the `network_userid` across sessions |
| [Python](/docs/sources/python-tracker/subject/)                              | ❌                       | ❌                        |                                                                                                               |
| [Scala](/docs/sources/scala-tracker/subject-methods/)                        | ❌                       | ❌                        |                                                                                                               |
| [Ruby](/docs/sources/ruby-tracker/adding-data-events/)                       | ❌                       | ❌                        |                                                                                                               |
| [Rust](/docs/sources/rust-tracker/initialization-and-configuration/)         | ❌                       | ❌                        |                                                                                                               |
| [PHP](/docs/sources/php-tracker/subjects/)                                   | ❌                       | ❌                        |                                                                                                               |
| [C++](/docs/sources/c-tracker/adding-extra-data-the-subject-class/)          | ✅                       | ❌/✅                      | Stored in memory by default; configure a `cookie_file` to persist the `network_userid` across sessions        |
| [Unity](/docs/sources/unity-tracker/subject/)                                | ❌                       | ❌                        | Set all properties.                                                                                           |
| [Lua](/docs/sources/lua-tracker/tracking-specific-events/)                   | ❌                       | ❌                        | Set `user_id` only.                                                                                           |
| Google Tag Manager                                                           | ✅                       | ✅                        | Same as for the web tracker: stored in `sp` cookie                                                            |

Some trackers also allow you to [set your own](#set-identifiers-in-your-tracking-code) `network_userid` value.

### Business-generated

The business-generated user identifier is an external identifier given to the tracker by the application. Most commonly it's the username or email address of the logged in user e.g. `jane.doe@email.com`.

It's tracked as the atomic `user_id` field. All Snowplow trackers have an API to [set this identifier](#set-identifiers-in-your-tracking-code).

### Set identifiers in your tracking code

These [properties](/docs/fundamentals/canonical-event/#user-fields) can be assigned using most Snowplow trackers: `user_id`, `domain_userid`, `network_userid`, `domain_sessionid`, `domain_sessionidx`, and `user_ipaddress`.

Some trackers set certain user properties automatically, while others require you to set them manually using the tracker's API.

If you don't manually set an IP address or `network_userid`, the event [Collector](/docs/pipeline/collector/) will automatically add them to the event based on the request HTTP headers and the Collector cookie. You can turn this feature off using [server-side anonymization](/docs/events/anonymous-tracking/).

Values set in your tracking code will take precedence over values added by the Collector or enrichments.

| Tracker                                                                      | Supported | Since version | Notes                                                                                                                                                                                                    |
| ---------------------------------------------------------------------------- | --------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Web](/docs/sources/web-trackers/tracking-events/#business-user-id)          | ✅         | 0.1.0         | Set `user_id` only. Tracker sets the `domain_userid`, `network_userid`, `domain_sessionid`, and `domain_sessionidx` automatically from [cookies](/docs/sources/web-trackers/cookies-and-local-storage/). |
| [iOS](/docs/sources/mobile-trackers/client-side-properties/)                 | ✅         | 0.5.0         | Set all properties except `domain_sessionid` and `domain_sessionidx`.                                                                                                                                    |
| [Android](/docs/sources/mobile-trackers/client-side-properties/)             | ✅         | 0.1.0         | Set all properties except `domain_sessionid` and `domain_sessionidx`.                                                                                                                                    |
| [React Native](/docs/sources/react-native-tracker/client-side-properties/)   | ✅         | 0.1.0         | Set all properties.                                                                                                                                                                                      |
| [Flutter](/docs/sources/flutter-tracker/initialization-and-configuration/)   | ✅         | 0.1.0         | Set `user_id` only on web. Set `user_id`, `domain_userid`, `network_userid`, and `user_ipaddress` on mobile.                                                                                             |
| [Roku](/docs/sources/roku-tracker/adding-data/)                              | ✅         | 0.2.0         | Set `user_id` and `network_userid` only. You can automatically populate `domain_userid`, `domain_sessionid`, and `domain_sessionidx` by configuring `sessionAsCookies`.                                  |
| [Node.js](/docs/sources/node-js-tracker/configuration/)                      | ✅         | 0.8.0         | Set all properties.                                                                                                                                                                                      |
| [Golang](/docs/sources/golang-tracker/adding-extra-data-the-subject-class/)  | ✅         | 1.0.0         | Set all properties.                                                                                                                                                                                      |
| [.NET](/docs/sources/net-tracker/subject/)                                   | ✅         | 0.1.0         | Set all properties.                                                                                                                                                                                      |
| [Java](/docs/sources/java-tracker/tracking-specific-client-side-properties/) | ✅         | 0.10.0        | Set all properties except `domain_sessionidx`.                                                                                                                                                           |
| [Python](/docs/sources/python-tracker/subject/)                              | ✅         | 0.13.0        | Set all properties.                                                                                                                                                                                      |
| [Scala](/docs/sources/scala-tracker/subject-methods/)                        | ✅         | 0.6.0         | Set all properties except `domain_sessionid` and `domain_sessionidx`.                                                                                                                                    |
| [Ruby](/docs/sources/ruby-tracker/adding-data-events/)                       | ✅         | 0.3.0         | Set all properties.                                                                                                                                                                                      |
| [Rust](/docs/sources/rust-tracker/initialization-and-configuration/)         | ✅         | 0.1.0         | Set all properties except `domain_sessionidx`.                                                                                                                                                           |
| [PHP](/docs/sources/php-tracker/subjects/)                                   | ✅         | 0.1.0         | Set all properties.                                                                                                                                                                                      |
| [C++](/docs/sources/c-tracker/adding-extra-data-the-subject-class/)          | ✅         | 0.1.0         | Set `user_id` and `user_ipaddress` only.                                                                                                                                                                 |
| [Unity](/docs/sources/unity-tracker/subject/)                                | ✅         | 0.1.0         | Set all properties.                                                                                                                                                                                      |
| [Lua](/docs/sources/lua-tracker/tracking-specific-events/)                   | ✅         | 0.1.0         | Set `user_id` only.                                                                                                                                                                                      |
| Google Tag Manager                                                           | ❌         |               | Set using custom configuration.                                                                                                                                                                          |

### Snowplow ID

If you use [Snowplow Identities](/docs/identities/), each event will receive a Snowplow ID from the resolved user profile. The ID is added in an [identity entity](/docs/identities/concepts/#identity-entity). You can configure Identities to stitch together any identifiers for identity resolution.

### IP address

Snowplow events also contain the IP address of the user. The value is stored in the [atomic](/docs/fundamentals/canonical-event/) `user_ipaddress` property.

We don't recommend using the IP address as a primary identifier: multiple users can share an IP address, and a user's IP address can change frequently. However, it can be useful for certain use cases such as bot detection or geolocation.

## Session identifiers

The main Snowplow session identifiers are the session ID and session index:

- Session ID: a UUID generated by the tracker at the start of the session
- Session index: the index of the session for the current user, based on the `domain_userid` or `userId` tracker-generated user identifier

They're tracked differently depending on the tracker. On web, they're tracked as the `domain_sessionid` and `domain_sessionidx` [atomic event](/docs/fundamentals/canonical-event/) fields. In other trackers, they're part of the client session entity, which also includes other session-related information. Note that the web trackers can also track the client session entity, but not all trackers support [session tracking](#session-entity).

### Session timeouts

A session is a period of time in which a user interacts with your application. A new session starts the first time an event is tracked after the previous session's timeout has elapsed.

There's no maximum session duration, but sessions do have a configurable inactivity timeout. If there's no user activity for the specified time, the session ends. A new one will start when the user returns.

For most trackers, the timeout is based on the gap between the last tracked event and the current event. Mobile trackers have two session timeout settings, allowing you to specify different timeouts if the app is in the foreground or background.

| Tracker                                                                              | Foreground timeout, min | Background timeout, min | Notes                                                                                                         |
| ------------------------------------------------------------------------------------ | ----------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------- |
| [Web](/docs/sources/web-trackers/tracking-events/session/)                           | 30                      | -                       | Page pings from [activity tracking](/docs/events/ootb-data/page-activity-tracking/) will keep a session alive |
| [iOS](/docs/sources/mobile-trackers/tracking-events/session-tracking/)               | 30                      | 30                      |                                                                                                               |
| [Android](/docs/sources/mobile-trackers/tracking-events/session-tracking/)           | 30                      | 30                      |                                                                                                               |
| [React Native](/docs/sources/react-native-tracker/tracking-events/session-tracking/) | 30                      | 30                      |                                                                                                               |
| [Flutter](/docs/sources/flutter-tracker/sessions-and-data-model/)                    | 30                      | 30                      |                                                                                                               |
| [Roku](/docs/sources/roku-tracker/adding-data/)                                      | 30                      | -                       |                                                                                                               |
| [.NET](/docs/sources/net-tracker/setup/)                                             | 10                      | 5                       | Uses a timer so it can expire a session independently of a new tracked event                                  |
| [C++](/docs/sources/c-tracker/client-sessions/)                                      | 30                      | 30                      |                                                                                                               |
| [Google Tag Manager](/docs/sources/google-tag-manager/settings-template/)            | 30                      | -                       |                                                                                                               |

### Session entity

Some trackers can track an entity containing information about the current session.

This table shows the support for `client_session` entity tracking across the main [Snowplow tracker SDKs](/docs/sources/):

| Tracker                                                                              | Supported | Since version | Auto-tracking |
| ------------------------------------------------------------------------------------ | --------- | ------------- | ------------- |
| [Web](/docs/sources/web-trackers/tracking-events/session/)                           | ✅         | 3.5.0         | ✅             |
| [iOS](/docs/sources/mobile-trackers/tracking-events/session-tracking/)               | ✅         | 0.5.0         | ✅             |
| [Android](/docs/sources/mobile-trackers/tracking-events/session-tracking/)           | ✅         | 0.5.0         | ✅             |
| [React Native](/docs/sources/react-native-tracker/tracking-events/session-tracking/) | ✅         | 1.0.0         | ✅             |
| [Flutter](/docs/sources/flutter-tracker/sessions-and-data-model/)                    | ✅         | 0.2.0         | ✅             |
| [Roku](/docs/sources/roku-tracker/adding-data/)                                      | ✅         | 0.3.0         | ✅             |
| Node.js                                                                              | ❌         |               |               |
| Golang                                                                               | ❌         |               |               |
| [.NET](/docs/sources/net-tracker/setup/)                                             | ✅         | 1.0.0         | ✅             |
| Java                                                                                 | ❌         |               |               |
| Python                                                                               | ❌         |               |               |
| Scala                                                                                | ❌         |               |               |
| Ruby                                                                                 | ❌         |               |               |
| Rust                                                                                 | ❌         |               |               |
| PHP                                                                                  | ❌         |               |               |
| [C++](/docs/sources/c-tracker/client-sessions/)                                      | ✅         | 1.0.0         | ✅             |
| Unity                                                                                | ❌         |               |               |
| Lua                                                                                  | ❌         |               |               |
| [Google Tag Manager](/docs/sources/google-tag-manager/settings-template/)            | ✅         | v4            | ✅             |

The `client_session` entity contains data such as the session identifier and session index, as well as information about the previous session to help analysis.

The `userId` property is the device ID.

### `client_session`

**Type:** Event

Schema for a client-generated user session

**Properties:**

| Property                     | Description                                                                                                                                                         |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `userId` _string_            | _Required._ An identifier for the user of the session. It is set on app install.                                                                                    |
| `sessionId` _string_         | _Required._ An identifier for the session                                                                                                                           |
| `sessionIndex` _integer_     | _Required._ The index of the current session for this user                                                                                                          |
| `eventIndex` _null_          | _Optional._ Optional index of the current event in the session                                                                                                      |
| `previousSessionId` _null_   | _Required._ The previous session identifier for this user                                                                                                           |
| `storageMechanism` _string_  | _Required._ The mechanism that the session information has been stored on the device Must be one of: `SQLITE`, `COOKIE_1`, `COOKIE_3`, `LOCAL_STORAGE`, `FLASH_LSO` |
| `firstEventId` _null_        | _Optional._ The optional identifier of the first event for this session                                                                                             |
| `firstEventTimestamp` _null_ | _Optional._ Optional date-time timestamp of when the first event in the session was tracked                                                                         |

**Example warehouse query (Snowflake):**

```sql
select
unstruct_event_com_snowplowanalytics_snowplow_client_session_1 client_session_1
from
atomic.events
where
events.collector_tstamp > getdate() - interval '1 hour'
and events.event = 'unstruct'
and events.event_name = 'client_session'
and events.event_vendor = 'com.snowplowanalytics.snowplow'
```

## Identity resolution

Identity resolution is the process of taking various user identifiers and combining them into a single user identifier, to better identify and track users throughout their journey on your site or app. It allows you to attribute logged-in and non-logged-in sessions back to a single user.

Snowplow offers two approaches to identity resolution:

- **[Snowplow Identities](/docs/identities/)** resolves identity in real time during enrichment, attaching a unified Snowplow ID to each event. The [Identities dbt package](/docs/identities/data-models/) then builds mapping tables for use in downstream models.
- **[Identity stitching in the Unified Digital dbt package](/docs/modeling-your-data/modeling-your-data-with-dbt/package-features/identity-stitching/)** resolves identity at modeling time by stitching the business user ID with tracker-generated user identifiers. This is available to all customers.

We recommend setting the business user identifier, where possible, when using either approach.

### Reset generated identifiers on web

If you're not using Identities, there's a risk of attributing sessions to the wrong user when multiple users share the same browser or device.

If this is a problem for you, the JavaScript tracker allows you to [clear all user data](/docs/sources/web-trackers/anonymous-tracking/#clear-user-data). If you call this function when a user logs out, the tracker will generate new user and session identifiers for subsequent events. This feature is only available for the JavaScript tracker.

## Anonymous tracking

The user and session identifiers, along with the IP address, are considered personal identifiable information (PII). Snowplow also allows you to track data without these identifiers: check out the [anonymous tracking](/docs/events/anonymous-tracking/) overview page.
