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

# Identify Users Across Sessions and Devices

> Attach your own stable user ID to visits so tinyanalytics can follow a person across devices and sessions — cookielessly and exactly.

Call `identify()` with your own user ID to tie a visitor's activity to a known person. This makes people-level reports exact across devices and sessions. A signed-in user on a phone and a laptop counts as **one** user, instead of the two you'd get from cookieless estimation. You choose the ID, and tinyanalytics keys every people report on it.

```js theme={null}
window.tinyanalytics.identify('user_12345')
```

## Why identify users?

Without identification, tinyanalytics counts visitors with a cookieless hash, which is a close estimate that can split one person across devices or merge several people on one network (see [how tinyanalytics works](/docs/how-tinyanalytics-works#its-an-estimate-and-tinyanalytics-says-so)). When you know who someone is — because they signed in — `identify()` replaces that estimate with your exact ID, so **Users**, **Retention**, and **Cohorts** all agree and follow the real person.

## Identify a signed-in user

Call `identify()` once you know who the visitor is, typically right after they log in:

```js theme={null}
// ID only
window.tinyanalytics.identify('user_12345')

// An ID plus traits describing the person
window.tinyanalytics.identify('user_12345', {
  plan: 'pro',
  signupDate: '2026-01-15'
})
```

When you call `identify()`, tinyanalytics:

* Attaches your ID to the visitor's **recent activity** — it backfills the last 30 days of that visitor's events, so their earlier anonymous visits are credited to the person.
* Remembers the ID in the browser (`localStorage`), so the visitor stays identified across page loads and future sessions on that device.
* Merges any `traits` you pass onto the person's profile.

## Which identity methods are available?

tinyanalytics exposes four identity methods on `window.tinyanalytics`:

| Method                      | What it does                                                                                                                                |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `identify(userId, traits?)` | Tie the visitor to your `userId`, backfill their recent events, and save the ID on the device.                                              |
| `setTraits(traits)`         | Update the identified person's traits without re-identifying. Pass `null` for a key to delete it. Does nothing if no one is identified yet. |
| `clearUserId()`             | Forget the identified user on this device — call it when a user logs out.                                                                   |
| `getUserId()`               | Return the current user ID, or `null`. Survives page reloads.                                                                               |

```js theme={null}
// Update traits later
window.tinyanalytics.setTraits({ plan: 'enterprise' })

// On logout
window.tinyanalytics.clearUserId()
```

## What does tinyanalytics store when you identify a user?

The cookieless hash tinyanalytics uses for anonymous visitors is never stored on the device and contains no personal data. **Identification is different: the user ID and traits you pass are stored** so they can describe a person over time. Choose what you send accordingly:

* Use a **stable, internal ID** — your database user ID, for example — not something that changes.
* Avoid putting personal data you don't want to keep into the ID or traits. If you don't want to store email addresses, don't pass them.

<Note>
  An `identify()` call fired in the same instant as a pageview may not tag that exact pageview — the backfill applies to events that are already saved. In practice this is a single event at the very start of a visit; all subsequent activity is attributed correctly.
</Note>

## Verify it's working

<Steps>
  <Step title="Sign in and identify">
    Trigger your `identify()` call in the browser — usually by logging into your app.
  </Step>

  <Step title="Find the person in Users">
    Open the **Users** report in tinyanalytics. The visitor now appears under your ID, with their traits and their earlier activity attributed to them.
  </Step>
</Steps>

<Check>
  Identification is working when the visitor appears in the **Users** report under your own ID, with their traits and their earlier activity attributed to them.
</Check>

## Frequently asked questions

<AccordionGroup>
  <Accordion title="Does identify() apply to activity from before the call?">
    Yes. When you call `identify()`, tinyanalytics backfills the last **30 days** of that visitor's events, so their earlier anonymous visits are credited to the person. One exception: an `identify()` call fired in the same instant as a pageview may not tag that exact pageview, because the backfill applies to events that are already saved.
  </Accordion>

  <Accordion title="How do I stop identifying a user when they log out?">
    Call `window.tinyanalytics.clearUserId()`. It forgets the identified user on that device. tinyanalytics otherwise remembers the ID in the browser's `localStorage`, so the visitor stays identified across page loads and future sessions.
  </Accordion>

  <Accordion title="Does tinyanalytics store the user ID on the visitor's device?">
    Yes. The user ID and any traits you pass to `identify()` are stored so they can describe a person over time, and the ID is kept in the browser's `localStorage`. This differs from the cookieless hash used for anonymous visitors, which is never stored on the device and contains no personal data.
  </Accordion>

  <Accordion title="Do I need identify() to count visitors in tinyanalytics?">
    No. tinyanalytics counts visitors with a cookieless hash without any code from you. That count is a close estimate that can split one person across devices or merge several people on one network. Call `identify()` when you know who someone is to replace the estimate with your exact ID.
  </Accordion>
</AccordionGroup>

## Related

<Columns cols={2}>
  <Card title="Track custom events" icon="hand-pointer" href="/docs/custom-event-tracking">
    Send named events that tie to the identified person.
  </Card>

  <Card title="How tinyanalytics works" icon="diagram-project" href="/docs/how-tinyanalytics-works">
    Cookieless identity and how identify makes counts exact.
  </Card>

  <Card title="Configure the script" icon="sliders" href="/docs/configure-tinyanalytics-tracking-script">
    Control what the script tracks.
  </Card>

  <Card title="Verify your setup" icon="circle-check" href="/docs/verify-tinyanalytics-installation">
    Confirm identification is arriving.
  </Card>
</Columns>


## Related topics

- [User Analytics](/docs/user-analytics.md)
- [User Acquisition Analytics](/docs/user-acquisition-analytics.md)
- [How Cookieless Analytics Identifies Visitors](/docs/resources/cookieless-analytics-identity.md)
