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

# Share page context and identify users

> Send context variables to the AI Agent and pass verified identity with the Chat SDK

Tell the AI Agent what the visitor is doing, such as the product they're viewing
or what's in their cart, and who they are once they sign in.

## Two kinds of variables

> **variables**
>
> Set in the browser, so a visitor can change them. Use them for page context:
> the current page, the selected product, the cart.

> **signedVariables**
>
> A JWT your backend signs, so Typewise trusts the values. Use them for
> identity, such as the customer's email.

> [!NOTE]
>
> Declare every variable you send in [Context
> Variables](https://docs.typewise.app/documentation/settings/context-variables.md). Typewise drops names
> you haven't declared.

## Send context when a conversation starts

Pass `variables` to `createClient`. Use a function so the SDK reads fresh values
each time a conversation starts, and the first message already carries them:

```javascript theme={null}
const chat = createClient({
  clientId: "YOUR_CLIENT_ID",
  variables: () => ({ page: location.pathname, cartValue: cart.total }),
});
```

Values can be strings, numbers, or booleans.

## Update context as the page changes

Call `setVariables` when something changes, for example when the visitor picks a
different product option. Before a conversation exists, the SDK holds the values
and applies them to the next one.

```javascript theme={null}
const { droppedVariableKeys, rejectedVariableKeys } = await chat.setVariables({
  variables: { productFinish: "Sage", productQuantity: 2 },
});
```

The result tells you which values weren't kept:

**droppedVariableKeys** `string[]`

Names not declared in Context Variables. Log this during development: a
non-empty list usually means a typo or a variable you forgot to declare.

**rejectedVariableKeys** `string[]`

Unsigned values that couldn't overwrite a value that arrived verified.

## Identify signed-in users

Pass `signedVariables` as a function. The SDK calls it every time it
authenticates, so tokens can stay short-lived:

```javascript theme={null}
const chat = createClient({
  clientId: "YOUR_CLIENT_ID",
  signedVariables: () =>
    fetch("/api/typewise-token").then((response) => response.text()),
});
```

To sign the token on your backend, see
[Chat identity verification](https://docs.typewise.app/guides/channels/chat-widget/identity-verification.md).

### When the visitor signs in or out

When the visitor signs in, pass a new token. When they sign out, forget the
session so the next person on the device starts fresh.

```javascript Sign in theme={null}
async function onLogin() {
  const token = await fetch("/api/typewise-token").then((r) => r.text());
  await chat.setVariables({ signedVariables: token });
}
```

```javascript Sign out theme={null}
async function onLogout() {
  await chat.resetSession();
}
```

## Related

* [Context Variables](https://docs.typewise.app/documentation/settings/context-variables.md): declare
  variables and use them in actions and lookups
* [Chat identity verification](https://docs.typewise.app/guides/channels/chat-widget/identity-verification.md):
  sign the token on your backend
* [Storefront concierge example](https://typewise.github.io/chat-sdk-examples/storefront-concierge/):
  sends the selected product finish as it changes


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