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

> ## Agent Instructions
> CrispStats is a hosted, privacy-first web analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing, no mobile SDKs and no data import except a site's history from a Plausible export (Settings, Import and export).
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> There is no npm package to install. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Identify signed-in users

> Tie a visitor to your own user id with crispstats.identify(userId, traits) so their visits, events and traits appear on one identified profile in CrispStats.

Call `crispstats.identify(userId, traits)` when you know who is signed in. CrispStats sends an `identify` event with your user id and traits, then attaches the user id to every later event from that page. In the dashboard the visitor gets one identified profile under **Visitors** that shows their `email` trait and user id, and gathers their sessions and events from every device.

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
crispstats.identify("user_42", { email: "ada@example.com", plan: "team" });
```

Without `identify`, a visitor is anonymous: a hash that changes every day (unless [persistent visitors](https://docs.crispstats.com/privacy/persistent-visitors.md) are on) and a generated name. CrispStats sets no cookie either way. Identifying users changes that privacy picture: read [what changes under GDPR](#what-changes-for-privacy) before you ship it.

## Identify a user

**1. Call identify on each page where the user is signed in**

The user id lives in memory for the current page only. Call `identify` on every page load where you know the user, for example from your layout or after your session check:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script>
  // Values rendered by your server for the signed-in user.
  crispstats.identify("user_42", { email: "ada@example.com", plan: "team" });
</script>
```

The script loads with `defer`, so put the [queue stub](https://docs.crispstats.com/tracking/script-attributes.md#call-the-global-before-the-script-loads) above the script tag. Without it, `crispstats.identify` does not exist yet when inline code runs. In TypeScript, use the stub and types from [TypeScript](https://docs.crispstats.com/install/typescript.md).

**2. Call it again after sign-in**

In a single-page app, call `identify` as soon as sign-in succeeds. Events sent after the call carry the user id. Sessions recorded earlier under the same anonymous visitor id are linked to the user when the identify event is stored.

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
// Call this from your sign-in success handler with the signed-in user.
function onSignedIn(user) {
  crispstats.identify(user.id, { email: user.email, plan: user.plan });
}
```

**3. Check the visitor profile**

Open **Visitors** in the dashboard and pick the **Identified** segment. Select the visitor to open their profile.

## What identify does

| Step | Detail |
| - | - |
| Sends an event | One event of type `identify`, with the user id and the traits as its properties. It is not a custom event, so it does not appear in the **Events** table. |
| Keeps the id in memory | The user id is held in a variable for the current page. It is not written to cookies, `localStorage` or anywhere else on the device. |
| Attaches the id to later events | Every pageview, custom event, revenue event and engagement ping sent after the call carries the user id, until the page unloads. |
| Forgets on unload | A full page load starts with no user id. Single-page navigation keeps it, because the page does not unload. |

Calling `identify` with an empty id does nothing. A second call with a different id replaces the first for the rest of the page.

There is no call to clear the id. After a user signs out in a single-page app, the id stays on events from that page until it reloads, so reload or navigate with a full page load on sign-out if that matters to you.

## Arguments

**userId** `string` *required*

Your own stable id for the user, such as a database id. Numbers are converted to strings. Up to 200 characters.

**traits** `object`

Flat properties to store on the profile, such as `email`, `plan` or `company`. They follow the same rules as [custom event properties](https://docs.crispstats.com/track/custom-events.md#event-and-property-rules): strings are cut at 500 characters, keys are up to 60 characters, and at most 40 are kept.

> [!WARNING]
>
> Keep user ids at 200 characters or fewer. The id is sent with every event after `identify`, and the collector drops browser events with a longer id without an error, so an oversized id stops all tracking on that page.

## How identified visitors appear

On the visitor's profile:

* **Identity.** The heading is a generated name, as for every visitor. Under it, the `email` trait is shown with the user id next to it. Without an `email` trait, the user id is shown. Anonymous visitors show "Anonymous visitor" instead.
* **Traits.** Traits from each `identify` call are merged and stored with the profile. When a key is sent again, the newest value wins. The dashboard shows only the `email` trait; the `identify` event itself, with all its traits, appears in the visitor's journey.
* **History.** Once a visitor id is tied to a user id, sessions recorded earlier under that visitor id belong to the same person. Because anonymous visitor ids change daily, this links the visits from the same day, not from earlier days. With [persistent visitors](https://docs.crispstats.com/privacy/persistent-visitors.md) on, the anonymous profile is folded into the identified one.
* **One profile per user id.** Visits from different devices or days that identify with the same user id add up on one profile: first seen, last seen, sessions, pageviews, events and lifetime revenue.

In the **Visitors** list, the **Identified** segment shows only visitors with a user id, and search matches their user ids and email traits.

The user id and traits you send are stored with the profile. Send only what you need to recognise the user, and see [data collected](https://docs.crispstats.com/privacy/data-collected.md) for what CrispStats stores on its own.

## What changes for privacy

Anonymous CrispStats data is built so that it does not identify anyone: no cookies, a visitor id that changes every day, no IP address stored. `identify` deliberately breaks that for the visitors you call it for.

* **The data becomes personal data.** Your user id ties events to a person in your own database, so under the GDPR and the UK GDPR the identified visitor's events, profile and traits are personal data, even without an email address. An `email` trait makes it directly identifying.
* **Visits are linked over time.** One profile gathers a user's sessions from every device and day, which anonymous visitors never are.
* **You need a legal basis, and to say so.** Name analytics of signed-in users in your privacy policy, and list CrispStats among the services that process it. Whether you need consent depends on your basis: many teams rely on legitimate interest for product analytics of their own signed-in users, others ask for consent. `identify` itself stores nothing on the device: the questions it raises are about the data collected, not about cookies.
* **Honour requests.** When a user asks you to delete their data or stops consenting, stop calling `identify` for them. To remove what was stored, write to [hello@crispstats.com](mailto:hello@crispstats.com) with the site and the user id: the dashboard and API have no delete for a single visitor yet.
* **Send less.** Prefer an opaque id over an email address as the user id, and send only the traits you use.

This describes what the feature does with data, not legal advice. See [compliance](https://docs.crispstats.com/privacy/compliance.md) for the rest of the picture.

## Does identify count toward your plan

No. Only pageviews and custom events count toward your plan's monthly events. An `identify` call sends an `identify` event, which is not counted, and neither are `revenue`, engagement pings, web vitals or errors. See [what counts as an event](https://docs.crispstats.com/account/plans-and-limits.md#what-counts-as-an-event).

## Identify from your server

From your server, send an `identify` event over HTTP with a secret API key, with your user id in `i`, the visitor id you saved from `crispstats.id()` in `vid`, and the traits in `p`:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST https://in.crispstats.com/e \
  -H "Authorization: Bearer $CRISPSTATS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"k":"cs_pk_xxxxxxxx","t":"identify","u":"","i":"user_42","p":{"plan":"team"},"vid":"0123456789abcdef0123456789abcdef"}'
```

Send `i` with any server-side event to attribute it to the same user. See [server-side events](https://docs.crispstats.com/track/server-side-events.md).

## Next steps

> [card] [Visitors](https://docs.crispstats.com/dashboard/visitors.md)
>
> Browse visitor profiles, segments and journeys.

> [card] [Server-side events](https://docs.crispstats.com/track/server-side-events.md)
>
> Send events for a user from a webhook, a cron or a background job.

> [card] [Visitor id at checkout](https://docs.crispstats.com/revenue/visitor-id-at-checkout.md)
>
> Attribute payments to the visit that led to them.


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