Best Practices for Naming Events in Application Insights
Tracking custom events with TrackEvent()
in Azure Application Insights helps you monitor how users interact with your app. However, to obtain meaningful data, it's essential to name your events clearly and consistently.
Here are some best practices:
Use Clear, Descriptive Names
Write event names using a Verb-Noun format like UserLoggedIn
, FileDownloaded
, or OrderSubmitted
. This makes them easy to understand.
Stick to PascalCase
Use PascalCase (each word starts with a capital letter), and avoid:
- Spaces (
User Logged In
) - Dashes (
User-Logged-In
) - Underscores (
user_logged_in
)
Use: UserLoggedIn
Don’t Include Dynamic Data
Keep user IDs, file names, or other changing values out of the event name.
Instead, put that info in custom properties or metrics.
Keep It Consistent
Follow the same naming style across your app. This makes it easier to search and analyze data later.
Be Specific When Needed
If similar actions happen in different contexts, make your event name more specific:ContactFormSubmitted
vs. FeedbackFormSubmitted
Tip
Use a naming template like:<Action><Entity>[<Qualifier>]
Example: AddedItemToCart
A clean, consistent naming strategy makes your telemetry easier to work with, both now and in the future.
Comments