User Identity
Identifying users allows the SDK to deliver personalized content, target specific audiences, and tie analytics data to real user profiles rather than anonymous sessions.
Identifying a User
Call DAP('identify', payload) with the user's unique ID and optional traits:
DAP("identify", {
userId: "user-42",
traits: {
role: "admin",
plan: "enterprise",
signupDate: "2025-01-15",
department: "Engineering",
},
});
After identification, the SDK re-fetches flows, content, and experiment assignments targeted to that user.
When to Call Identify
- After login -- Once your application confirms the user's identity.
- On page load -- If the user is already authenticated (e.g., session restored from a cookie), call
identifyas early as possible afterinit. - After signup -- Identify the new user so onboarding content can be delivered immediately.
DAP("init", { tenantKey: "YOUR_TENANT_KEY" });
// After your app confirms the user is logged in
DAP("identify", {
userId: currentUser.id,
traits: { role: currentUser.role, plan: currentUser.plan },
});
Traits
Traits are key-value pairs that describe the user. Use them for audience segmentation and targeting rules in the dashboard.
| Example trait | Type | Purpose |
|---|---|---|
role | string | Target content by user role (admin, viewer, editor) |
plan | string | Gate features or content by subscription tier |
signupDate | string | Segment users by tenure |
department | string | Deliver department-specific guidance |
city | string | Target content by user city (pass from your app) |
onboardingComplete | boolean | Show different content to new vs. returning users |
Trait values can be strings, numbers, or booleans. You can update traits at any time by calling identify again with the same userId and new trait values.
Anonymous Users
Before identify is called, the SDK assigns an anonymous ID and tracks the session without a known user. This means:
- Flows and content with no audience restrictions are still displayed.
- Analytics events are recorded under the anonymous ID.
- Once
identifyis called, the anonymous session is linked to the identified user.
If a user logs out, call DAP('destroy') to tear down the SDK and stop tracking. Re-initialize and identify the next user when they log in.
// On logout
DAP("destroy");
// On next login
DAP("init", { tenantKey: "YOUR_TENANT_KEY" });
DAP("identify", { userId: "user-99", traits: { role: "viewer" } });