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) |
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.
Using Traits for Custom Events
While the track method is the standard way to record behavioral data, you can also include "custom events" directly within the traits object during identification. This is a common pattern for including historical event counts or milestone flags that you want to be immediately available for audience targeting.
Any data included in the traits object is available for audience segmentation in the Dashboard using dot-notation.
DAP("identify", {
userId: "user_123",
traits: {
role: "premium",
// Custom events defined within traits
signup_completed: true,
purchase_count: 5,
last_login: "2025-01-15T12:00:00Z",
},
});
Targeting in the Dashboard
When building an audience, you can target these custom event traits by using the Custom Field option in the Audience Builder.
[!TIP] Use this pattern for high-level user milestones and aggregate counts. For granular, high-frequency event tracking, use the
DAP('track')method instead.
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" } });