Browser telemetry SDK for monitoring page views, errors, web vitals, and HTTP requests with OpenTelemetry integration
The user identification API allows you to associate user information with telemetry signals, enabling user-centric analysis, debugging, and monitoring. User attributes follow OpenTelemetry semantic conventions.
Critical User Identification Behavior:
user.* prefixidentify() merge attributes; they do not replace all attributesAssociates user information with telemetry signals.
/**
* Associates user information with telemetry signals
* @param id - User identifier (optional)
* @param opts - Additional user information (optional)
* @throws No errors thrown; invalid values may be ignored
*/
function identify(id?: string, opts?: IdentifyOpts): void;
interface IdentifyOpts {
/** Short name or login/username of the user */
name?: string;
/** User's full name */
fullName?: string;
/** User email address */
email?: string;
/** Unique user hash for anonymized correlation */
hash?: string;
/** User roles */
roles?: string[];
}Usage Examples:
import { identify } from "@dash0/sdk-web";
// Basic user identification
identify("user-12345");
// Full user identification
identify("user-12345", {
name: "johndoe",
fullName: "John Doe",
email: "john@example.com",
roles: ["admin", "user"],
});
// Anonymized identification using hash
identify(undefined, {
hash: "a1b2c3d4e5f6",
});
// Update only specific user attributes
identify("user-12345", {
name: "johndoe",
email: "john.doe@example.com",
});For IIFE (script tag) usage:
dash0("identify", "user-12345");
dash0("identify", "user-12345", {
name: "johndoe",
fullName: "John Doe",
email: "john@example.com",
roles: ["admin", "user"],
});Critical Behavior:
identify() multiple times merges attributes (does not replace all)id is undefined, only opts attributes are setuser.* prefixundefined does not remove them; use removeSignalAttribute()The user information is mapped to OpenTelemetry semantic convention attributes:
| Parameter | Attribute Key | Description |
|---|---|---|
id | user.id | Unique user identifier |
opts.name | user.name | Short name or login/username |
opts.fullName | user.full_name | User's full name |
opts.email | user.email | User email address |
opts.hash | user.hash | Unique hash for anonymized correlation |
opts.roles | user.roles | Array of user roles |
Critical Behavior:
user.roles is stored as an array of stringsundefined does not remove it (use removeSignalAttribute)Call identify() when a user logs in:
import { identify } from "@dash0/sdk-web";
async function handleLogin(username, password) {
const user = await authenticateUser(username, password);
// Identify user after successful login
identify(user.id, {
name: user.username,
fullName: user.displayName,
email: user.email,
roles: user.roles,
});
}Identify newly registered users:
async function handleRegistration(userData) {
const newUser = await createUser(userData);
identify(newUser.id, {
name: newUser.username,
email: newUser.email,
roles: ["user"],
});
}For anonymous users, you can still track with a hash:
import { identify } from "@dash0/sdk-web";
// Generate or retrieve anonymous user hash
const anonymousHash = generateAnonymousHash();
identify(undefined, {
hash: anonymousHash,
});Update user attributes as they change:
// User updates their email
function handleEmailUpdate(newEmail) {
identify(currentUserId, {
email: newEmail,
});
}
// User gains a new role
function handleRoleUpdate(newRoles) {
identify(currentUserId, {
roles: newRoles,
});
}To clear user identification (e.g., on logout), you need to remove the attributes manually:
import { removeSignalAttribute } from "@dash0/sdk-web";
function handleLogout() {
// Remove user attributes
removeSignalAttribute("user.id");
removeSignalAttribute("user.name");
removeSignalAttribute("user.full_name");
removeSignalAttribute("user.email");
removeSignalAttribute("user.hash");
removeSignalAttribute("user.roles");
// Optionally terminate the session
// See session-management.md
}When using the user identification API:
hash parameter for anonymized user tracking when PII cannot be collectedidentify() multiple times merges attributes; later calls do not replace all attributesundefined in opts does not remove it; use removeSignalAttribute insteadroles must be an array of strings; other types may be ignoredidentify() is called before init(), attributes may be queued or lostinit() is called multiple times, user attributes persist across re-initializationInstall with Tessl CLI
npx tessl i tessl/npm-dash0hq--sdk-web