Analytics Events: Why Consistent Naming Matters?
You open your analytics report and see:
buttonClick
click_button
btnClick
clickBtn
button_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!),clickBtn
btnClick
click_button
onClick_button
click-card
cardClick
card_click
open_popap
pageOpened
goToPage
click_button
click_card
open_popup
submit_form
scroll_to_bottom
start_video
pause_video
add_to_cart
remove_from_cart
purchase_success
login_success
logout
registration_complete
error_validation
click_link
Pick 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.