User and session management

  • Latest Dynatrace
  • How-to guide

Dynatrace allows you to identify users across sessions and devices, manage session lifecycle, and attach properties that apply to all events in a session.

Identify users

Use identifyUser() to tag the current session with a user identifier. This enables you to track individual users across different sessions, browsers, and devices.

Important considerations

  • Not persisted—the user tag is not stored. You must call identifyUser() for every new session.
  • Automatic re-tagging—when a session splits due to idle or duration timeout, the subsequent session is automatically re-tagged with the same user identifier.
  • Privacy—consider privacy regulations when choosing what identifier to use. Hashed or anonymized IDs may be preferable.

When the user closes the app or when privacy settings change, sessions are not automatically re-tagged. You must call identifyUser() again after the new session starts.

Consider basic usage

// After user logs in
Dynatrace.identifyUser("user@example.com")
// Or use an internal user ID
Dynatrace.identifyUser("user-12345")

Remove user identification

To remove the user tag (for example, on logout), pass null or an empty string:

fun logout() {
// Clear user identification
Dynatrace.identifyUser(null)
}

Use session properties

Session properties are key-value pairs that apply to all events in the current session. Use them to add context that characterizes the user's session.

Event and session properties must be configured before they can be used. Incoming event and session properties that are not configured are dropped during event ingest.

Send session properties

Dynatrace.sendSessionPropertyEvent(
SessionPropertyEventData()
.addSessionProperty("session_properties.product_tier", "premium")
.addSessionProperty("session_properties.loyalty_status", "gold")
.addSessionProperty("session_properties.onboarding_complete", true)
)

Property naming rules

Keys must be prefixed with session_properties. and must follow the rules specified in Event and session properties.

Session properties require server-side configuration in Dynatrace. Properties that are not configured are dropped during ingest.

Update session properties

You can send session properties multiple times during a session. However, if you send the same property multiple times, session aggregation keeps only one value (first or last, depending on configuration).

// Initial properties
Dynatrace.sendSessionPropertyEvent(
SessionPropertyEventData()
.addSessionProperty("session_properties.cart_value", 0)
)
// Update after user adds items
Dynatrace.sendSessionPropertyEvent(
SessionPropertyEventData()
.addSessionProperty("session_properties.cart_value", 149.99)
)
Related tags
Digital Experience