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

# identify

> Associate the current visitor with a known user.

```javascript theme={null}
Hacktionbase.identify(user)
```

Links the current anonymous session to a known user. Call this after the user logs in or when you know who they are.

## Parameters

<ParamField body="user" type="UserData" required>
  User identity data.

  <Expandable>
    <ParamField body="id" type="string" required>
      Your application's unique user ID (external ID).
    </ParamField>

    <ParamField body="email" type="string">
      User's email address.
    </ParamField>

    <ParamField body="name" type="string">
      User's display name.
    </ParamField>

    <ParamField body="account" type="object">
      Account/company the user belongs to. Must include an `id` field.

      <Expandable>
        <ParamField body="id" type="string" required>
          Your application's unique account ID (external ID).
        </ParamField>

        <ParamField body="plans" type="PlanItem[]">
          Reserved structured attribute — the account's commercial plans.
          Sending `plans` replaces the account's plan list; an empty array
          clears it; omitting it leaves plans unchanged. See
          [Plans](/concepts/plans) for the full contract.
        </ParamField>

        <ParamField body="[key]" type="any">
          Any additional keys are stored as account custom attributes.
        </ParamField>
      </Expandable>
    </ParamField>

    <ParamField body="userHash" type="string">
      HMAC hash for identity verification (prevents impersonation).
    </ParamField>

    <ParamField body="[key]" type="any">
      Any additional custom attributes are stored on the user profile.
    </ParamField>
  </Expandable>
</ParamField>

## Example

```javascript theme={null}
Hacktionbase.identify({
  id: 'user_123',
  email: 'jane@example.com',
  name: 'Jane Doe',
  account: {
    id: 'org_456',
    name: 'Acme Inc',
    plans: [
      { key: 'pro', label: 'Pro Monthly', period: 'monthly', price: 49, currency: 'USD' },
    ],
  },
  signedUpAt: '2024-01-15'
});
```

## Behavior

* On first call (anonymous → identified), the SDK re-authenticates with the widget to get a user-scoped JWT.
* If the user switches accounts (different `account.id`), the session is rotated and replay restarts.
* Custom attributes (any key beyond `id`, `email`, `name`, `account`, `userHash`) are stored as user properties and can be used in segments and campaigns.

## Logout

To clear the user identity and return to anonymous mode:

```javascript theme={null}
Hacktionbase.logout();
```

This rotates the session, clears stored identity, and re-authenticates anonymously.
