Analytics Events: Why Consistent Naming Matters?
You open your analytics report and see:
buttonClickclick_buttonbtnClickclickBtnbutton_clik (yes, with a typo)🤦♂️ And all of these mean the same kind of button click.
I’ve seen many projects — and it’s always the same story: naming chaos in analytics events.
Event names should be:
snake_case, camelCase, or kebab-case (pick one!),clickBtnbtnClickclick_buttononClick_buttonclick-cardcardClickcard_clickopen_popappageOpenedgoToPageclick_buttonclick_cardopen_popupsubmit_formscroll_to_bottomstart_videopause_videoadd_to_cartremove_from_cartpurchase_successlogin_successlogoutregistration_completeerror_validationclick_linkPick one style — for example, snake_case — and stick to it always.
You can even define a dictionary or a type in code.
export const ANALYTICS_EVENTS = {
click_button: 'click_button',
click_card: 'click_card',
open_popup: 'open_popup',
close_popup: 'close_popup',
submit_form: 'submit_form',
start_video: 'start_video',
pause_video: 'pause_video',
add_to_cart: 'add_to_cart',
remove_from_cart: 'remove_from_cart',
purchase_success: 'purchase_success',
login_success: 'login_success',
logout: 'logout',
registration_complete: 'registration_complete',
error_validation: 'error_validation',
click_link: 'click_link',
scroll_to_bottom: 'scroll_to_bottom'
} as const;
export type AnalyticsEvent = keyof typeof ANALYTICS_EVENTS;
export function trackEvent(event: AnalyticsEvent, payload: Record<string, unknown> = {}) {
if (process.env.NODE_ENV === 'development') {
console.log('[Analytics]', event, payload);
}
window.dataLayer?.push({
event: ANALYTICS_EVENTS[event],
...payload
});
}types.ts or events.ts.Analytics events are like an API — for your brain.
Naming chaos = mental chaos.
Standardization = clarity, automation, powerful dashboards.
Adopt a naming style. Stick to it.
Never again wonder what that one click event was called.
📊 For more tips like this — read my blog.