User Identification
Link anonymous devices to logged-in users.
Overview
Identity management is critical for accurate funnels and retention analysis. The JS SDK automatically tracks anonymous users using a distinct_id stored in localStorage. When a user logs into your app, you must link their anonymous ID to their permanent database ID.
1. Identify (Login)
Call identify() immediately after a user successfully logs into your application.
EmpMix.identify('db_user_89012');| Parameter | Type | Required | Description |
|---|---|---|---|
| userId | string | Yes | The permanent, unique ID for this user in your database. |
| profile | object | No | Optional properties to immediately set on the user's profile in the database (e.g., name, email). |
2. Alias (Sign Up)
The alias() method is used exactly once per user: at the exact moment they create an account. It tells the backend to link their past anonymous activity to their new permanent ID.
Alias vs Identify
alias() only during the sign-up event. Use identify() for all subsequent logins.// User fills out registration form and hits submit
const newUserId = response.data.id; // e.g., 'usr_abc123'
// 1. Alias the current anonymous ID to the new user ID
EmpMix.alias(newUserId);
// 2. Identify as the new user going forward
EmpMix.identify(newUserId);
// 3. Track the signup event (this will be attached to the new ID)
EmpMix.track('Signed Up');3. Reset (Logout)
When a user logs out, you must clear their session data. Otherwise, subsequent events triggered by a different user on the same shared computer will be attributed to the logged-out user.
// Call this when the user clicks 'Logout'
EmpMix.reset();reset() clears all Emp-Mix cookies and localStorage, generating a brand new anonymous distinct_id for the next session.
User Profiles (People API)
You can update a user's profile metadata without firing a specific event.
// Update or set properties
EmpMix.setUserProperties({
last_login_date: new Date().toISOString(),
plan: 'Pro'
});
// Increment numeric properties
EmpMix.increment('logins_count', 1);