What is user identification?
By default, every event tracked by Analytiq is anonymous — you can see that a button was clicked, but not who clicked it.identify() links all future events to a specific user. After you call it, every track() event is automatically tagged with that user’s ID — so on the dashboard you can filter events by user, see a single user’s journey, and understand your users individually.
When to call identify()
Callidentify() in exactly one place: right after login or signup succeeds.
Basic usage
- A database UUID or integer ID:
identify('550e8400-e29b-41d4-a716-446655440000') - An email address:
identify('john@example.com')(only if emails are unique) - Any unique string your system uses
After signup
- React / Next.js
- Vue / Vanilla JS
If you used the
analytics.jsx “One-File Setup” from the Quickstart, you don’t need to call identify manually.When your user signs up successfully, your app’s authentication state changes.
The useEffect inside your analytics.jsx file detects the new user and calls identify() for you automatically.components/Signup.jsx
After login
- React / Next.js
- Vue / Vanilla JS
Just like signup, you don’t need to call identify manually.When the login succeeds and you update your user state, the
useEffect in your analytics.jsx file automatically fires identify().components/Login.jsx
When the user is already logged in (page refresh)
If your app keeps users logged in, you need to re-identify them when the app loads after a page refresh — otherwise events after a refresh won’t be linked to their identity.- React / Next.js
- Vue / Vanilla JS (manual)
This is handled automatically. When your app loads, your
useAuth hook automatically fetches the user from local storage or cookies. Because that variable updates, the useEffect inside analytics.jsx runs again and successfully calls identify() automatically.Resetting on logout
When a user logs out, their identity must be cleared so the next person using the device doesn’t inherit it.- React / Next.js
- Vue / Vanilla JS
This is handled automatically. When you clear your user state, your auth hook becomes empty. The
useEffect inside analytics.jsx detects this and automatically calls reset().You do not need to call reset() manually inside your Logout button if you have the analytics.jsx file installed perfectly.How identity flows through events
Afteridentify() is called, all subsequent track() calls are automatically linked:
What NOT to do
| Don’t | Why |
|---|---|
identify(user.email) if emails can change | User gets new email, resulting in their history being split |
identify(user.name) | Names aren’t always unique |
Call identify() before login succeeds | You might identify the wrong user |
Skip reset() on logout | Next user inherits previous user’s identity |
Anonymous events before identify()
Any events tracked beforeidentify() is called are stored anonymously. Once you call identify(), future events are linked — but past anonymous events remain anonymous. This is expected behavior.
Tracking anonymous visitors (no login required)
If your app or website has users who never log in (a marketing landing page, a blog, a documentation site),identify() is never called naturally — and all events will have userId = null, meaning they won’t appear in your Unique Users, DAU, or MAU counts.
The fix is to generate a stable visitor ID using localStorage. This creates a unique ID the first time someone visits, stores it in their browser, and reuses it on every future visit — all without requiring any login.
- React / Next.js
- Vue 3
- Vanilla HTML / JS
Add this to your
analytics.jsx provider file, before or alongside the useAuth identify logic:src/analytics.jsx
How this works:
crypto.randomUUID() generates a unique ID (like "f47ac10b-58cc-4372-a567-0e02b2c3d479") the very first time someone visits. It is saved in localStorage so future visits by the same person reuse the same ID — giving you accurate repeat visitor counts.| Scenario | What happens |
|---|---|
| First visit, no login | New visitor ID generated → DAU and Unique Users count this visitor |
| Return visit, no login | Same visitor ID reused → recognized as the same visitor |
| User logs in after browsing | identify(user) overrides the visitor ID → events now linked to their real account |
| User logs out | Back to visitor ID → browsing continues tracked anonymously |