# User context

Pass optional user and subscription fields to identify users and enrich observability.

User context is how you **track the users and subscriptions** using your agent, with built-in and custom attributes. Calling `foldspace.identify()` ties each session to a real user (and their account or subscription) so conversations, [Product analytics](/user-guides/analytics/product-analytics/), and [Segments](/user-guides/analytics/segments/) carry real identity and attributes instead of anonymous sessions.

It's optional — the agent runs without it — but in production it's what makes users and subscriptions trackable. Pair it with [Custom events](/reference/track-api/) to also track what those users *do* (usage).

Create custom user and subscription attributes under **Settings → [Attribute Settings](/user-guides/settings/attributes/)**, then send their values with `identify()` using each attribute's API Name.

## Identify a user

Pass a context object to `foldspace.identify()` once the SDK is ready.

```javascript
const context = {
    user: {
        id: '7d8da9a5-53f3-4bc0-8921-1cceecb8107',
    },
    subscription: {
        id: 'subscription-12345'
         // add custom attributes here after creating them in Attribute Settings
    }
}

foldspace('when', 'ready', () => {
    foldspace.identify(context);
});
```

## Add custom user attributes (optional)

Add any of the optional attributes below to enrich the user record.

```javascript
const context = {
    user: {
        id: '7d8da9a5-53f3-4bc0-8921-1cceecb8107',
        email: 'user12345@example.com',
        name: 'John Doe',
        role: 'admin',
        image: 'https://example.com/images/user12345.jpg',
        phone: '+1234567890',
        timezone: 'America/New_York',
        signUpDate: 1707164462000,
        location: {
            country: "USA",
            region: "Northeast",
            state: "New York",
            city: "New York City",
            postalCode: "10001"
        }
        // add custom attributes here after creating them in Attribute Settings

    },
    subscription: {
        id: 'subscription-12345'
         // add custom attributes here after creating them in Attribute Settings
    }
}

foldspace('when', 'ready', () => {
    foldspace.identify(context);
});
```
