Try it free

User and session management

  • Latest Dynatrace
  • How-to guide
  • 1-min read

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

import { Dynatrace } from '@dynatrace/react-native-plugin';
// 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:

import { Dynatrace } from '@dynatrace/react-native-plugin';
function logout() {
// Clear user identification
Dynatrace.identifyUser(null);
}

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.
  • Character limit—the user identifier is limited to 250 characters and will be truncated if it exceeds this limit.

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

Session properties apply to all events within the current session. Use sendSessionPropertyEvent() to set properties using the SessionPropertyEventData class that should be available across the entire user session.

import { Dynatrace, SessionPropertyEventData } from '@dynatrace/react-native-plugin';
// Set session-wide properties
Dynatrace.sendSessionPropertyEvent(new SessionPropertyEventData()
.addSessionProperty("session_properties.user_tier", "premium")
.addSessionProperty("session_properties.app_version", "2.1.0")
.addSessionProperty("session_properties.feature_flag_enabled", true)
);

Property requirements

Allowed properties:

  • Properties prefixed with session_properties.*.

For property limits, see Capture event and session properties for mobile frontends.

Field naming rules:

  • Field names must contain only alphabetic characters, numbers, underscores, and dots.
  • Field name maximum length: 100 characters (including the session_properties. prefix).
  • 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, number, boolean).
  • Cannot contain functions, undefined, Infinity, or NaN as values (they're replaced with null).

Session property behavior:

  • Session properties persist throughout the entire session.
  • If you send the same property multiple times, only one value is kept (first or last).
  • Use session properties for data that applies to the entire user session.

Valid examples:

  • session_properties.user_tier
  • session_properties.app_version
  • session_properties.feature_flag_enabled

Update session properties

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

import { Dynatrace, SessionPropertyEventData } from '@dynatrace/react-native-plugin';
// Initial properties
Dynatrace.sendSessionPropertyEvent(new SessionPropertyEventData()
.addSessionProperty("session_properties.cart_value", 0)
);
// Update after user adds items
Dynatrace.sendSessionPropertyEvent(new SessionPropertyEventData()
.addSessionProperty("session_properties.cart_value", 149.99)
);

End session

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

import { Dynatrace } from '@dynatrace/react-native-plugin';
function logout() {
// Clear user identification
Dynatrace.identifyUser(null);
// End the current session
Dynatrace.endSession();
}
  • The user tagging will not carry over to the new user session that is started after using this API. If user tagging is desired in the new user session, ensure that you call the identifyUser() API again.
  • Sessions also end automatically based on idle timeout and maximum session duration configured in your Dynatrace environment.

Related topics

  • Privacy and data collection—data collection levels and user consent.
  • Custom events—event properties and modifiers.
  • Capture event and session properties for mobile frontends—limits, naming rules, and OpenPipeline enrichment.
  • Configuration—agent configuration.
Related tags
Digital Experience