Dynatrace allows you to identify users across sessions and devices, manage session lifecycle, and attach properties that apply to all events in a session.
Use identifyUser() to tag the current session with a user identifier. This enables you to track individual users across different sessions, browsers, and devices.
// After user logs inDynatrace.identifyUser("user@example.com")// Or use an internal user IDDynatrace.identifyUser("user-12345")
To remove the user tag (for example, on logout), pass nil or an empty string:
func logout() {// Clear user identificationDynatrace.identifyUser(nil)}
identifyUser() for every new session.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 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.
Dynatrace.sendSessionPropertyEvent(DTXSessionPropertyEventData().addSessionProperty("session_properties.product_tier", value: "premium").addSessionProperty("session_properties.loyalty_status", value: "gold").addSessionProperty("session_properties.onboarding_complete", value: true))
session_properties..String, Int, Double, Bool).Valid examples:
session_properties.product_tiersession_properties.loyalty_statussession_properties.onboarding_completeSession properties require server-side configuration in Dynatrace. Properties that are not configured are dropped during ingest.
session_properties. prefix)._, and dot ..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 propertiesDynatrace.sendSessionPropertyEvent(DTXSessionPropertyEventData().addSessionProperty("session_properties.cart_value", value: 0))// Update after user adds itemsDynatrace.sendSessionPropertyEvent(DTXSessionPropertyEventData().addSessionProperty("session_properties.cart_value", value: 149.99))
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 identificationDynatrace.identifyUser(nil)// End the current sessionDynatrace.endVisit()}
Sessions also end automatically based on idle timeout and maximum session duration configured in your Dynatrace environment.