Skip to content

Custom User Identity

The SDK generates an identity for anonymous users. After a user logs in, you can call setUser() to write stable business user information, enabling cross-session queries for the same user's Views, Actions, Resources, and Errors.

Attribute Type Required Description
id String No Recommended to use a stable business user ID that does not directly expose sensitive information
name String No User nickname or display name
email String No User email
Other fields Unknown No Business-specific user attributes, e.g., membership level

It is recommended to provide at least id. Do not use frequently changing nicknames or email addresses in place of a stable user ID.

NPM Example

import { datafluxRum } from "@cloudcare/browser-rum"

datafluxRum.setUser({
  id: "user-1234",
  name: "John Doe",
  email: "john@example.com",
  membership_level: "gold"
})

CDN Example

window.DATAFLUX_RUM &&
  window.DATAFLUX_RUM.setUser({
    id: "user-1234",
    name: "John Doe",
    email: "john@example.com"
  })
window.DATAFLUX_RUM.onReady(function () {
  window.DATAFLUX_RUM.setUser({
    id: "user-1234",
    name: "John Doe",
    email: "john@example.com"
  })
})

Logout or Switch User

When logging out, call clearUser() to prevent subsequent events from continuing to be associated with the original user:

datafluxRum.clearUser()

Starting from SDK 3.3.6, after login, logout, or account switching, you can update the user information first, then call startSession() to immediately create a new session boundary:

datafluxRum.setUser({ id: "user-5678" })
datafluxRum.startSession()

For CDN integration, use window.DATAFLUX_RUM.clearUser() and window.DATAFLUX_RUM.startSession().

Notes

  1. Do not write sensitive information such as passwords, access tokens, or ID numbers.
  2. User information only affects events generated after the setting; it does not modify previously reported data.
  3. After a user switch, update the user information and session synchronously to prevent data from two accounts from falling into the same session.

Verification

After setting the user, trigger a page action and confirm in the View or Action Explorer that the event contains user.id. After logging out and calling clearUser(), newly generated events should no longer be associated with the original user.

Feedback

Is this page helpful?