Try it free

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.

Basic usage

// After user logs in
Dynatrace.identifyUser("user@example.com")
// Or use an internal user ID
Dynatrace.identifyUser("user-12345")
// 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 nil or an empty string:

func logout() {
// Clear user identification
Dynatrace.identifyUser(nil)
}
- (void)logout {
// Clear user identification
[Dynatrace identifyUser:nil];
}

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.

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.

Allow session properties

Before you can send session properties from your application, you must first allow each property key in Dynatrace. Any properties that are not allowed will be dropped during ingest.

To allow a key, follow the steps in Allow API-reported properties.

Send session properties

Dynatrace.sendSessionPropertyEvent(
DTXSessionPropertyEventData()
.addSessionProperty("session_properties.product_tier", value: "premium")
.addSessionProperty("session_properties.loyalty_status", value: "gold")
.addSessionProperty("session_properties.onboarding_complete", value: true)
)
[Dynatrace sendSessionPropertyEvent:
[[[[DTXSessionPropertyEventData alloc] init]
addSessionProperty:@"session_properties.product_tier" value:@"premium"]
addSessionProperty:@"session_properties.loyalty_status" value:@"gold"]
addSessionProperty:@"session_properties.onboarding_complete" value:@YES]];

Property naming rules

  • Keys must be prefixed with session_properties..
  • Field names must contain only alphanumeric characters, underscores, and dots.
  • Each dot must be followed by an alphabetic character.
  • Each underscore must be followed by an alphabetic character or number.
  • Values must be primitive types (String, Int, Double, Bool).

Valid examples:

  • session_properties.product_tier
  • session_properties.loyalty_status
  • session_properties.onboarding_complete

Limits

For limits on property counts, key length, and value length, see Limits.

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(
DTXSessionPropertyEventData()
.addSessionProperty("session_properties.cart_value", value: 0)
)
// Update after user adds items
Dynatrace.sendSessionPropertyEvent(
DTXSessionPropertyEventData()
.addSessionProperty("session_properties.cart_value", value: 149.99)
)
// Initial properties
[Dynatrace sendSessionPropertyEvent:
[[DTXSessionPropertyEventData alloc] init]
addSessionProperty:@"session_properties.cart_value" value:@0]];
// Update after user adds items
[Dynatrace sendSessionPropertyEvent:
[[DTXSessionPropertyEventData alloc] init]
addSessionProperty:@"session_properties.cart_value" value:@149.99]];

End session

Use endVisit() to manually close the current session and start a new one. All open actions are closed and sent to the server.

func logout() {
// Clear user identification
Dynatrace.identifyUser(nil)
// End the current session
Dynatrace.endVisit()
}
- (void)logout {
// Clear user identification
[Dynatrace identifyUser:nil];
// End the current session
[Dynatrace endVisit];
}

Sessions also end automatically based on idle timeout and maximum session duration configured in your Dynatrace environment.

Related tags
Digital Experience