User Identification
Know who your users are. Link their journey from first visit to loyal customer.
User Identification
Link anonymous visitors to known users. See complete journeys from first visit to conversion.
The Identity Flow
Anonymous Visitor → Identified User → Account Member
│ │ │
anonymousId userId accountIdAnonymous Visitor
Every visitor gets a unique anonymousId automatically. No code needed. They're now a trackable (if mysterious) entity.
Identified User
When they sign up or log in, call identify(). This links their userId to their anonymousId, connecting all their past activity.
Account Member
If they're part of a workspace/team, call group(). Now you can analyze behavior at the company level.
Identifying Users
Call identify() when you know who someone is. Usually at signup or login.
import { useIdentify } from '@thisbefine/analytics/react';
const LoginPage = () => {
const identify = useIdentify();
const handleLogin = async (credentials) => {
const user = await login(credentials);
identify(user.id, {
email: user.email,
name: user.name,
createdAt: user.createdAt,
});
};
return <form>{/* your form */}</form>;
};import { getAnalytics } from '@thisbefine/analytics';
getAnalytics()?.identify('user_123', {
email: 'jane@example.com',
name: 'Jane Doe',
plan: 'pro',
});User Traits
| Trait | Type |
|---|---|
email | string |
name | string |
avatar | string |
plan | string |
createdAt | string/Date |
[custom] | any |
identify(user.id, {
email: user.email,
name: user.name,
plan: 'enterprise',
role: 'admin',
mfaEnabled: true,
});Calling identify() multiple times merges traits. New values override old ones.
When to Call identify()
- On signup, after creating the account
- On login, after authentication
- On profile update, with changed traits
Grouping Users by Account
For B2B apps, group users by company/workspace to analyze behavior at the account level.
import { useGroup } from '@thisbefine/analytics/react';
const WorkspaceSelector = () => {
const group = useGroup();
const handleSelectWorkspace = (workspace) => {
group(workspace.id, {
name: workspace.name,
plan: workspace.plan,
memberCount: workspace.members.length,
});
};
return <div>{/* selector */}</div>;
};getAnalytics()?.group('workspace_456', {
name: 'Acme Corp',
plan: 'enterprise',
mrr: 5000,
});Account Traits
| Trait | Type |
|---|---|
name | string |
plan | string |
mrr | number |
industry | string |
employeeCount | number |
createdAt | string/Date |
[custom] | any |
Call group() when users switch workspaces, create new ones, or change plans.
Resetting on Logout
Always reset when users log out. Otherwise the next user's events get attributed to the previous user.
import { useReset } from '@thisbefine/analytics/react';
const LogoutButton = () => {
const reset = useReset();
const handleLogout = async () => {
await logout();
reset();
window.location.href = '/login';
};
return <button onClick={handleLogout}>Logout</button>;
};reset() flushes pending events, clears user/account data, generates a fresh anonymousId, and starts a new session.
Getting Current User State
import { useGetUser } from '@thisbefine/analytics/react';
const user = useGetUser()();
// { anonymousId, userId?, traits?, accountId?, accountTraits? }How Anonymous → Identified Works
track('feature_viewed', { feature: 'pricing' });
track('button_clicked', { button: 'start_trial' });
identify('user_789', { email: 'jane@example.com' });All previous anonymous events are now linked to user_789. You see the complete journey: how they found you, what they did before signup, and after.
Multiple Devices
Each device gets its own anonymousId. When the user logs in, all anonymous IDs link to their userId. You can see cross-device behavior.
Best Practices
Use stable IDs: Use database primary key, not email (emails change).
Identify early: Call identify() immediately after login, not later.
Keep traits updated: When plan/profile changes, call identify() again with new traits.