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

# identify()

> Attach your own stable user id to the Encore Web SDK session (replacing the auto-generated anonymous UUID), optionally setting attributes in the same call. Includes getCurrentUserId() and getAppAccountId().

Replaces the current user id (the auto-generated anonymous UUID, or a previous id) with your
application's stable id. Call it when you know who the user is: after login, signup, or
session restore.

## Signature

```typescript theme={null}
function identify(userId: string, attributes?: UserAttributes): void
```

<ParamField path="userId" type="string" required>
  Your application's unique id for this user. Use an opaque identifier (not an email or other
  personal data), and use the **same id across sessions and devices**; claims, subscription
  events, and measurement join on it.
</ParamField>

<ParamField path="attributes" type="UserAttributes">
  Optional attributes set in the same call, equivalent to a following
  [`setUserAttributes()`](/publishers/web/sdk-reference/set-user-attributes).
</ParamField>

Returns `void`. Fire-and-forget: the id is applied and persisted locally right away, and the
backend link (previous id → new id) is sent asynchronously.

## Example

```javascript theme={null}
import Encore from '@encorekit/web-sdk';

// After login
Encore.identify(user.id, {
  email: user.email,
  subscriptionTier: user.subscription.tier,
});
```

## Behavior

* The new id is persisted in `localStorage` and used for all subsequent SDK activity.
* Calling with the **same** id again is a no-op, so it is safe to call on every page load.
* Identify **as early as you reliably can**, ideally before the first offer presentation, so
  activity binds to the stable id rather than the anonymous one.
* When switching to a *different* user (account switch), call
  [`reset()`](/publishers/web/sdk-reference/reset) first, then `identify()` the new user.

## getCurrentUserId()

```typescript theme={null}
function getCurrentUserId(): string | null
```

Returns the id from `identify()`, the auto-generated anonymous UUID otherwise, or `null`
before `configure()`.

```javascript theme={null}
const userId = Encore.getCurrentUserId();
```

## getAppAccountId()

```typescript theme={null}
function getAppAccountId(): string | null
```

The persistent account identity that this user's claims, exposures, and subscription events
are bound to, the same value your server forwards as `app_account_id` on
[subscription webhooks](/publishers/web/guides/attribute-subscriptions). Currently resolves to
the same value as `getCurrentUserId()`.

## Related

* [User Management quickstart](/publishers/web/quickstart/user-management): the full identity model
* [`setUserAttributes()`](/publishers/web/sdk-reference/set-user-attributes): update attributes later
* [`reset()`](/publishers/web/sdk-reference/reset): clear identity on logout
