> ## Documentation Index
> Fetch the complete documentation index at: https://docs.selektable.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Identity

> SDK methods for managing customer identity

# Identity methods

The SDK provides methods to manage customer identity for analytics and cross-session tracking. See [Identity Tracking](/guides/identity-tracking) for a conceptual overview.

## `identify(userId, traits?)`

Associates the current visitor with a known user identity. Call this after a user logs in.

```javascript theme={null}
Selektable.identify('user-123', {
  name: 'John Doe',
  email: 'john@example.com',
  plan: 'premium'
});
```

<ParamField path="userId" type="string" required>
  Your system's unique user identifier.
</ParamField>

<ParamField path="traits" type="Record<string, unknown>">
  Optional metadata about the user (name, email, etc.).
</ParamField>

**Behavior:**

* Persists `userId` and `traits` in the browser
* Updates the in-memory identity state
* Sends identity update to all currently open widgets
* Sends the identity data to the Selektable server in the background

***

## `reset()`

Clears the stored identity and generates new anonymous IDs. Call this when a user logs out.

```javascript theme={null}
Selektable.reset();
```

**No parameters.**

**Behavior:**

* Generates a new visitor ID, session ID, and anonymous ID
* Removes stored user ID and traits
* Updates all open widgets with the new identity

***

## `getIdentity()`

Returns the current identity object.

```javascript theme={null}
const identity = Selektable.getIdentity();
```

**Returns:**

```typescript theme={null}
{
  visitorId: string;      // Persistent browser ID
  sessionId: string;      // Current session ID
  anonymousId: string;    // Anonymous ID (initially same as visitorId)
  userId?: string;        // Set after identify() is called
  traits?: Record<string, unknown>;  // Set after identify() is called
}
```

***

## `setVisitorId(visitorId)`

Manually overrides the auto-generated visitor ID.

```javascript theme={null}
Selektable.setVisitorId('my-tracking-id-abc');
```

<ParamField path="visitorId" type="string" required>
  Custom visitor ID to use.
</ParamField>

**Behavior:**

* Overwrites the visitor ID
* If no user is identified, also updates the anonymous ID
* Updates the in-memory identity state

<Warning>
  Only use this if you manage your own visitor tracking. The auto-generated IDs work for most use cases.
</Warning>
