Sends a user event with the given fields to the Dynatrace Platform.
The provided fields must be a valid JSON object. Nested objects or arrays are not allowed. Any custom properties must be added in the event_properties.* namespace, otherwise they will be dropped. A maximum of 50 custom properties can be sent. Additionally only the duration property and the start_time property are allowed. String properties are limited to 5000 characters, exceeding characters are cut off.
Field names must contain only alphanumeric characters, underscores and dots. Each dot must be followed by an alphabetic character. Each underscore must followed by an alphabetic character or number.
The event will be filled with the provided fields and enriched with basic context information such as user session details and frontend metadata. After auto-enrichment, the event can be modified using an EventModifier.
Android
public static void sendEvent(JSONObject fields, Object[] eventContext)
iOS
For Swift:
public static sendEvent(fields: [String: Any]?, eventContext: Any?)
For Objective-C:
+ (void)sendEventWithFields:(NSDictionary<NSString*,id>* _Nullable)fields eventContext:(id _Nullable)eventContext
React Native
sendEvent(properties: JSONObject, context?: any): void
Flutter
public void sendEvent(Map<String, dynamic> json)
MAUI
public void SendEvent(Dictionary<string, object> properties);
Sends a session properties event.
With sendSessionPropertyEvent, you can report properties that apply to all events in the current session. Any custom properties must be added in the session_properties.* namespace, otherwise they will be dropped. A maximum of 50 custom properties can be sent. Additionally only the duration property and the start_time property are allowed. String properties are limited to 5000 characters, exceeding characters are cut off. Even though you can send multiple sessions properties at once, session aggregation will take only one of the values (first or last) if you report the same value multiple times.
Fields must contain only alphanumeric characters, underscores and dots. Each dot must be followed by an alphabetic character. Each underscore must followed by an alphabetic character or number.
Properties require a server-side configuration in the settings UI. Otherwise, they'll be dropped during ingest.
Android
public static void sendSessionPropertyEvent(JSONObject properties)
iOS
For Swift:
public static sendSessionPropertyEvent(_ properties: [String: Any]?)
For Objective-C:
+ (void)sendSessionPropertyEvent:(NSDictionary<NSString*,id>* _Nullable)properties;
React Native
sendSessionPropertyEvent(properties: JSONObject): void
Flutter
public void sendSessionPropertyEvent(Map<String, dynamic> json)
MAUI
public void SendSessionPropertyEvent(Dictionary<string, object> properties);
Sends exception event with a Throwable and additional custom fields. The provided fields must be a valid JSON object. Nested objects or arrays are not allowed. Any custom fields must be added in the event_properties.* namespace, otherwise they will be dropped. A maximum of 50 custom fields can be sent. Additionally only the duration field and the start_time fields are allowed. String fields are limited to 5000 characters, exceeding characters are cut off.
Field names must contain only alphanumeric characters, underscores and dots. Each dot must be followed by an alphabetic character. Each underscore must followed by an alphabetic character or number.
The event will be filled with the provided fields and enriched with basic context information such as user session details and frontend metadata. After auto-enrichment, the event can be modified using an EventModifier. At this stage, it's also possible to use the provided event context objects for further manual enrichment of the event.
The sendExceptionEvent function allows you to report an exception event. You can also add custom fields to the exception event.
For custom fields, the key should consist of only alphanumeric characters, underscores, or dots. A dot should be followed only by a lowercase character, and an underscore can be followed by either a lowercase character or a number.
Android
The EventFieldsProvider is a functional interface that returns a JSONObject containing custom fields that should be added to the event.
public static void sendExceptionEvent(Throwable throwable, EventFieldsProvider fieldsProvider)
iOS
For Swift:
public static sendExceptionEvent(with exception: NSException, fields: [String: Any]?)
For Objective-C:
+ (void)sendExceptionEventWithException:(NSException* _Nonnull)exception fields:(NSDictionary<NSString*,id>* _Nullable)fields;
React Native
sendExceptionEvent(error: Error, fields?: JSONObject): void
Flutter
public void sendExceptionEvent(dynamic throwable,{StackTrace? stacktrace, Map<String, dynamic> fields})
Adds an EventModifier that enriches future events by applying the modifier function to them. When adding a field, you must use the event property namespace.
Certain reserved fields and namespaces canât be modified (added, removed, or overridden) in any way, while others are open for modification.
Android
public static boolean addEventModifier(EventModifier eventModifier)
iOS
For Swift:
public static addEventModifier(eventModifier: (DTXModifyableEvent) -> DTXModifyableEvent?) -> DTXModifyEventSubscriber
For Objective-C:
+ (DTXModifyEventSubscriber* _Nonnull)addEventModifier:(DTXModifyableEvent* _Nullable (^ _Nonnull)(DTXModifyableEvent* _Nonnull event))eventModifier;
React Native
addEventModifier(eventModifier: IEventModifier): IEventModifier
Flutter
void addEventModifier(EventModifier eventModifier)
MAUI
public IEventModifier AddEventModifier(IEventModifier eventModifier);
Removes a previously added EventModifier.
Android
public static boolean removeEventModifier(EventModifier eventModifier)
iOS
For Swift:
public static removeEventModifier(_ subscriber: DTXModifyEventSubscriber)
For Objective-C:
+ (void)removeEventModifier:(DTXModifyEventSubscriber* _Nonnull)subscriber;
React Native
removeEventModifier(eventModifier: IEventModifier): boolean
Flutter
void removeEventModifier(EventModifier eventModifier)
MAUI
public bool RemoveEventModifier(IEventModifier eventModifier);
EventModifier is a functional interface that provides a modifier function that is used to enrich a given event as JSONObject. It receives context objects depending on the type of the event or null if no context is available. The returned event can be a modified version of the event JSON or null if the event should be dropped.
JSONObject modifyEvent(JSONObject event, Object[] eventContext)
It receives context objects depending on the type of the event or null if no context is available. The returned event can be a modified version of the event JSON or null if the event should be dropped.
The following context parameters are to be expected on Android:
Event
Context parameters
Description
OkHttp request monitoring (success)
[Request, Response, null]
Request and Response types from OkHttp framework
OkHttp request monitoring (failed)
[Request, null, Throwable]
Request type from OkHttp framework
HttpURLConnection request monitoring
null
No context provided because information can't be accessed afterwards
Dynatrace.sendEvent(JSONObject fields, Object[] eventContext)
eventContext
Value provided by parameter
Manual web request monitoring, identify user, (manual) error reporting
null
No context defined
Crash reporting
[Throwable, Thread]
Provides the Thread where the crash occurs
Cross-platform events
null
There is no data type conversion between different languages, so the context object is not defined
The eventModifier provides a closure that can be used to enrich an event as [String: Any].
eventModifier: (DTXModifyableEvent) -> DTXModifyableEvent?
The returned event can be a modified version of the event JSON or null if the event should be dropped.
EventModifier is a functional interface that provides a modifier function that is used to enrich a given event as JSONObject. It receives context objects depending on the type of the event or null if no context is available. The returned event can be a modified version of the event JSON or null if the event should be dropped.
modifyEvent(event: JSONObject | null, context?: any): JSONObject | null
It receives context objects depending on the type of the event or null if no context is available. The returned event can be a modified version of the event JSON or null if the event should be dropped.
The following context parameters are to be expected on Android:
Event
Context parameters
Description
Dynatrace.sendEvent(properties: JSONObject, context?: any)
context
Value provided by parameter
EventModifier is a functional interface that provides a modifier function that is used to enrich a given event as Map. The returned event can be a modified version of the event JSON or null if the event should be dropped.
Map<String, dynamic>? modifyEvent(Map<String, dynamic> event)
The returned event can be a modified version of the event JSON or null if the event should be dropped.
EventModifier is a functional interface that provides a modifier function to enrich a given event such as Dictionary<string, object>?.
Dictionary<string, object>? ModifyEvent(Dictionary<string, object>? properties)
The returned event can be a modified version of the JSON event or null if the event should be dropped.
A view refers to a view/screen/window which is presented to the user at any time. The view-context can be used to analyze a users' flow from one view to another or how much time was spent on a certain view. Itâs also useful to contextualize errors/crashes and other performance data, associate it with team ownership and more. Thatâs why Dynatrace offers this API to manually add the view context to captured user events.
Dynatrace plans to automatically detect views in one of the upcoming releases based on major mobile project setups.
Starts monitoring of a view.
On every opening of a view the startView method can be called to highlight the current view context of the user. All events captured thereafter can be evaluated in context of that view. When another view was started previously, then this method will stop view monitoring for the previous view and start it for the current view.
Android
public static void startView(String name)
iOS
For Swift:
public static startView(name: String)
For Objective-C:
+ (void)startViewWithName:(NSString* _Nonnull)name
MAUI
public void StartView(string name);
Stops monitoring of the view that was previously started via startView(String). It will remove the view context and all events captured afterwards will be reported without view information.
Android
public static void stopView()
iOS
For Swift:
public static stopView()
For Objective-C:
+ (void)stopView;
MAUI
public void StopView();
With the New RUM Experience, Dynatrace automatically captures “Application Not Responding”(ANR) errors. ANRs are critical to monitor as they cause frustration to the user. The main problem is that the app's main thread, which is responsible for updating the UI, can't process user input events or draw, forcing the app to be closed.
These events are sent only if the mobile app is restarted within a timeframe of 10 minutes by the user.
By default, this feature is turned on. To turn it off use the following configuration options:
OneAgent only reports ANR errors on devices with Android 11 or higher. On older Android versions, the ANR Error event is not available.
Using the ConfigurationBuilder when starting the agent manually:
public ConfigurationBuilder withAnrReporting(boolean enabled)
Using the DSL:
dynatrace {configurations {sampleConfig {anrReporting false...}}}
Using the dictionary configuration when starting the agent manually:
Dynatrace.startup(withConfig: ["DTXANRReportingEnabled": false, …])
Using the plist file:
<key>DTXANRReportingEnabled</key><false/>
Using the dynatrace.config.js file:
module.exports = {react: {...},android: {// Those configs are copied 1:1config: `dynatrace {configurations {defaultConfig {...anrReporting false}}}`},ios: {// Those configs are copied 1:1config: `...<key>DTXANRReportingEnabled</key><false/>`}
Using the dynatrace.config.yaml file:
android:config:"dynatrace {configurations {defaultConfig {...anrReporting false}}}"ios:config:"...<key>DTXANRReportingEnabled</key><false/>"
Using the dynatrace.config.json file:
{"android": {"autoStart": {"beaconUrl": "https://...","applicationId": "..."},"anrReporting": false},"ios": {"DTXBeaconUrl": "https://...","DTXApplicationId": "...","DTXANRReportingEnabled": false}}
Native crashes are crashes that originate in C/C++ code added via NDK. The official Android documentation lists examples and how to diagnose them.
With the New RUM Experience, Dynatrace automatically captures native crashes. Events are sent only if the mobile app is restarted within a timeframe of 10 minutes by the end user.
By default, this feature is turned on. To turn it off use the following configuration options:
On older Android versions, the ANR Error event is not available. OneAgent only reports ANR errors on devices with Android 11 or higher. For Android 11 or higher, using the ConfigurationBuilder when starting the agent manually:
public ConfigurationBuilder withNativeCrashReporting(boolean enabled)
Using the DSL:
dynatrace {configurations {sampleConfig {nativeCrashReporting false...}}}
Once new RUM is enabled for a mobile app monitored by Dynatrace, data is stored on Grail. On each end user device on which the mobile app is installed, the new configuration will be applied only after the first session is finished. Upon the very first app start OneAgent will initiate non-Grail communication and upgrade to Grail only if ordered by server configuration, and only on the next app start.
Hence, the first session will be captured only on RUM Classic, unless the following build-time configuration is additionally applied:
To avoid that and to start with Grail right away, the startupWithGrailEnabled flag must be set to true.
This can be done using the ConfigurationBuilder:
public ConfigurationBuilder withStartupWithGrailEnabled(boolean enabled)
Using the DSL:
dynatrace {configurations {sampleConfig {agentBehavior {startupWithGrailEnabled true}}}}
To avoid that and to start with Grail right away, the DTXStartupWithGrailEnabled flag must be set to true.
This can be done in the .plist file:
<key>DTXStartupWithGrailEnabled</key><true/>
If the Dynatrace.startup(withConfig:) method is used, it needs to be added there.
Dynatrace.startup(withConfig: ["DTXStartupWithGrailEnabled": true, …])
OneAgent for Android now allows you to specify a custom OkHttp client to use for network requests, that are used to transmit RUM data to Grail.
This can be set using manual startup with the ConfigurationBuilder:
public ConfigurationBuilder withOkHttpClient(okhttp3.OkHttpClient httpClient)
Likewise, an OkHttp factory can be provided to achieve the same result:
public ConfigurationBuilder withOkHttpFactory(okhttp3.Call.Factory httpFactory)
Use to identify individual users across different browsers, devices, and user sessions.
Sessions split due to idle or duration timeout are re-tagged automatically.
When OneAgent ends a tagged session because the session duration has reached its set limit or due to the user's inactivity, the subsequent session is re-tagged automatically. You don't need to provide the user identification information again.
However, note that OneAgent does not re-tag the subsequent session in the following cases:
Android
void identifyUser(String userId)
iOS
For Swift:
public static identifyUser(_ userId: String?) -> DTX_StatusCode
For Objective-C:
+ (DTX_StatusCode)identifyUser:(NSString* _Nullable)userId;
React Native
identifyUser(String userId): void
Flutter
void identifyUser(String userId)
MAUI
public void IdentifyUser(string user);