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

# Identify contacts

> Link anonymous activity to a known contact with identify and alias from the JavaScript SDK.

`identify` connects your external ID to a Spotzee contact and updates its traits. Until you call it, `BrowserClient` sends activity with the anonymous ID held by that client instance.

## Identify a known contact

```typescript Browser / Spotzee global theme={null}
import { BrowserClient } from '@spotzee/js-sdk'

const spotzee = new BrowserClient({ apiKey: 'pk_…' })

await spotzee.identify({
  externalId: 'u_42',
  email: 'sam@example.com',
  phone: '+61491570006',
  timezone: 'Australia/Sydney',
  locale: 'en-AU',
  traits: {
    firstName: 'Sam',
    lastName: 'Patel',
    plan: 'starter',
    lifetimeValue: 199.50,
  },
})
```

```typescript Node theme={null}
import { Client } from '@spotzee/js-sdk'

const spotzee = new Client({ apiKey: process.env.SPOTZEE_API_KEY })

await spotzee.identify({
  anonymousId: 'anon_xyz',  // Optional. Pass a previously tracked ID to join its activity.
  externalId: 'u_42',
  email: 'sam@example.com',
  traits: {
    firstName: 'Sam',
    plan: 'starter',
  },
})
```

`BrowserClient` reuses its anonymous ID, so you don't need to pass `anonymousId` to each call. The Node `Client` requires an external ID for `identify`; its anonymous ID is optional. Pass a previously tracked anonymous ID when you need to join that activity.

## How traits flow

The SDK sends `traits` as the contact's `data` fields. Read [Define custom contact attributes](https://spotzee.com/docs/guides/data-schema.md) to review discovered attribute paths; project admins can set their visibility there.

A few traits map to specific behaviour:

* **`email`** and **`phone`**: top-level fields the email and SMS channels read from. Pass them through `identify` arguments rather than nesting them in `traits` so the SDK puts them in the right place.
* **`timezone`** and **`locale`**: drive personalisation and send-time logic. Pass them through `identify` arguments. The browser SDK does not infer them; if you want browser locale, read `navigator.language` and pass it in.

## Anonymous to known: automatic alias

The first `identify` call after an anonymous session aliases the anonymous ID to your `external_id`. All prior anonymous activity now belongs to the known contact. The browser SDK caches the `external_id` after this call, so subsequent `track` and `identify` calls carry both IDs automatically.

For server contexts where you already know the anonymous ID separately (for example, a user signed up server-side with a session you tracked earlier), call `alias` directly:

```typescript theme={null}
await spotzee.alias({
  anonymousId: 'anon_xyz',
  externalId: 'u_42',
})
```

## When to call identify

* **On sign-up.** First call after the user creates an account.
* **On sign-in.** So a user switching devices or browsers gets joined back to their record.
* **When traits change.** Updating profile data, plan, lifetime value, billing state. Identify is upsert: pass only the traits that changed.

Avoid calling `identify` on every page load with the same data. The platform deduplicates server-side, but the network call is wasted.

## Worked example: link anonymous browse to checkout

```typescript theme={null}
const spotzee = new BrowserClient({ apiKey: 'pk_…' })

// User browses anonymously. Track fires against the auto-minted anonymous ID.
await spotzee.track({
  event: 'Product viewed',
  properties: { sku: 'SHIRT-AU-12' },
})

// User signs in. Identify joins the anonymous session to the known account.
await spotzee.identify({
  externalId: 'u_42',
  email: 'sam@example.com',
  traits: { plan: 'starter' },
})

// Subsequent track calls automatically include both IDs. The "Product viewed"
// event from above is now part of u_42's history.
await spotzee.track({
  event: 'Checkout started',
  properties: { cartTotal: 89.95 },
})
```

## Reset on sign-out

`BrowserClient` caches `externalId` for the lifetime of its instance. To clear it on sign-out, replace that instance:

```typescript theme={null}
let spotzee = new BrowserClient({ apiKey: 'pk_…' })

function signOut() {
  spotzee = new BrowserClient({ apiKey: 'pk_…' })
}
```

A fresh `BrowserClient` mints a new anonymous ID. Subsequent activity is anonymous until the next `identify`.

## Next steps

> [card] [Track events](https://spotzee.com/docs/guides/sdks/javascript/track.md)
>
> Trigger journeys and feed segments with custom events.

> [card] [Define custom contact attributes](https://spotzee.com/docs/guides/data-schema.md)
>
> Review discovered attributes and their visibility.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.