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..
using Dynatrace.MAUI;double value = 149.99;var event = new EventData().AddEventProperty("event_properties.checkout_step": "payment_confirmed").AddEventProperty("event_properties.cart_value", value).AddEventProperty("event_properties.item_count", 3);Agent.Instance.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.
using Dynatrace.MAUI;class MyModifier : IEventModifier{public Dictionary<string, object>? ModifyEvent(Dictionary<string, object> fields){// Add custom fields to production eventsfields["event_properties.app_build"] = "1.2.3";fields["event_properties.environment"] = "production";return fields;}}...Agent.Instance.AddEventModifier(new MyModifier(event));
Return null to discard an event:
using Dynatrace.MAUI;class MyModifier : IEventModifier{public Dictionary<string, object>? ModifyEvent(Dictionary<string, object> fields){// Discard events from test usersif (fields["event_properties.is_test_user"] == true){return null; // Discard event}return fields;}}...Agent.Instance.AddEventModifier(new MyModifier(event));
using Dynatrace.MAUI;class MyModifier : IEventModifier{public Dictionary<string, object>? ModifyEvent(Dictionary<string, object> fields){// Redact email addresses from custom propertiesif (fields.ContainsKey("event_properties.user_email")){fields["event_properties.user_email"] = "[REDACTED]";}return fields;}}...Agent.Instance.AddEventModifier(new MyModifier(event));
using Dynatrace.MAUI;// Remove the modifier when no longer neededAgent.Instance.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.
using Dynatrace.MAUI;class FeatureFlagModifier : IEventModifier{var featureFlags = new Dictionary<string, object>{{ "checkout_v2", true },{ "new_payment_flow", false },{ "enhanced_search", true }}public Dictionary<string, object>? ModifyEvent(Dictionary<string, object> fields){foreach (var entry in fields){fields[$"event_properties.ff_{entry.Key}"] = entry.Value;}return fields;}}...Agent.Instance.AddEventModifier(new FeatureFlagModifier(event));
using Dynatrace.MAUI;class EnrichmentModifier : IEventModifier{public Dictionary<string, object>? ModifyEvent(Dictionary<string, object> fields){// Add experiment tracking to checkout eventsif (fields.ContainsKey("event_properties.checkout_step")){fields["event_properties.experiment_id"] = "checkout_flow_v2";fields["event_properties.variant"] = "treatment_a";}return fields;}}...Agent.Instance.AddEventModifier(new EnrichmentModifier(event));