> For the complete documentation index, see [llms.txt](https://docs.contextsdk.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.contextsdk.com/context-decision/advanced/tracking-the-user-id.md).

# Tracking the User ID

## What is the user ID?

The user ID is the identifier you already use to recognise a user in your own systems. By passing it to ContextSDK, every context event is tagged with that same identifier, so you can match a user between your platform and ContextSDK.

## Why track the user ID?

Sharing a common user identifier lets you join ContextSDK's analytics with your own data, making it easier to reason about a single user across both systems.

## How to track the user ID

Call `setUserId(_:)` with the identifier of the currently signed-in user. The value is stored on the device, so it's reapplied automatically on the next app start, and it's attached to every event from that point on. The same user ID is shared across all ContextSDK products, so this single call also associates the user with your push notifications.

{% tabs %}
{% tab title="iOS" %}

```swift
ContextManager.setUserId("your-user-id")
```

{% endtab %}
{% endtabs %}

Call this again whenever the signed-in user changes to overwrite the previous value.

## Clearing the user ID

Pass `nil` to clear a previously set user ID, for example when the user signs out. This removes the stored identifier from the device and stops attaching it to events.

{% tabs %}
{% tab title="iOS" %}

```swift
ContextManager.setUserId(nil)
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.contextsdk.com/context-decision/advanced/tracking-the-user-id.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
