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);
For naming rules and limits, see Event and session properties.
Event 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.
The following fields can be modified or added:
event_properties.*—event properties.session_properties.*—session properties (only on session property events).url.full—complete request URL.exception.stack_trace—exception stack traces.All other fields are read-only and can't be modified. The original values are 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;});}