Dynatrace allows you to send custom events to track business metrics or application-specific data. You can also enrich all events with additional context using event modifiers.
Before you can send event or session properties from your application, you must first define them in the Dynatrace web UI. Any properties that are not pre-configured will be discarded.
To define a new property:
Experience Vitals, select the frontend for which you want to add the property.cart.total_value).string, boolean, or number.Dynatrace automatically prefixes your field name with event_properties. or session_properties. based on the property type you selected. For example, a field name of cart.total_value will become event_properties.cart.total_value.
Use sendEvent() to report custom events with properties. Property keys must be prefixed with event_properties..
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';double value = 149.99;// Using constructorDynatrace().sendEvent(EventData(duration: 250,eventProperties: {'event_properties.checkout_step': 'payment_confirmed','event_properties.cart_value': value,'event_properties.item_count': 3,},));// Using addEventProperty methodfinal event = EventData(duration: 250)..addEventProperty('event_properties.checkout_step', 'payment_confirmed')..addEventProperty('event_properties.item_count', 3);if (value > 0) {event.addEventProperty('event_properties.cart_value', value);}Dynatrace().sendEvent(event);
event_properties..Valid examples:
event_properties.checkout_stepevent_properties.cart.total_valueevent_properties.user_tierEvent modifiers allow you to intercept and modify all events before they are sent to Dynatrace. Use them to add common properties, redact sensitive information, or filter events.
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';Dynatrace().addEventModifier((event) {// Add experiment tracking to all eventsevent['event_properties.experiment_id'] = 'checkout_flow_v2';event['event_properties.variant'] = 'treatment_a';return event;});
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';// Define the modifierMap<String, dynamic>? myModifier(Map<String, dynamic> event) {event['event_properties.custom'] = 'value';return event;}// Add the modifierDynatrace().addEventModifier(myModifier);// Remove when no longer neededDynatrace().removeEventModifier(myModifier);
Event modifiers have restrictions on which fields can be modified to ensure data integrity.
event_properties. / session_properties. prefix)._, and dot ..The following fields can be modified:
event_properties.* - Custom event propertiessession_properties.* - Session properties (only on session property events)url.full - The complete request URLexception.stack_trace - Exception stack tracesMost standard Dynatrace fields cannot be modified, including:
start_time.http.*.characteristics.*.Attempting to modify read-only fields will have no effect. The original values will be preserved.
Return null to discard an event:
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';Dynatrace().addEventModifier((event) {// Filter out events from test usersif (event['event_properties.is_test_user'] == true) {return null; // Discard this event}return event;});
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';Dynatrace().addEventModifier((event) {// Redact user IDs from URLsif (event.containsKey('url.full')) {event['url.full'] = event['url.full'].toString().replaceAll(RegExp(r'/users/\w+/'), '/users/{id}/');}return event;});
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';void setupFeatureFlagTracking(Map<String, bool> featureFlags) {Dynatrace().addEventModifier((event) {for (final entry in featureFlags.entries) {event['event_properties.ff_${entry.key}'] = entry.value;}return event;});}
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';void setupConditionalEnrichment() {Dynatrace().addEventModifier((event) {// Only enrich HTTP eventsif (event.containsKey('http.request.method')) {event['event_properties.api_client'] = 'flutter_app';event['event_properties.api_version'] = 'v2';}// Only enrich error eventsif (event.containsKey('exception.type')) {event['event_properties.error_context'] = 'user_session';}return event;});}