ANA-1Recommended
Keep a tracking plan in the code
List every analytics event in one file in the repository, with its name, purpose, owner and properties. Name events as an object and a past-tense action.
How to do it
Use one naming scheme, such as order_completed or signup_started, all lower case with underscores. Never put values in names, such as clicked_plan_pro. Put them in properties. Write the plan as a schema file, such as JSON Schema or a typed module, and generate the tracking functions from it. Then a typo fails the build instead of creating a new event. Remove an event from the plan when its last chart goes, as with any dead code.
Examples
JavaScript example
// tracking-plan.js: the only place events are defined
export const EVENTS = {
order_completed: { owner: 'checkout', purpose: 'Count sales per plan', properties: { order_id: 'string', plan: ['basic', 'pro'], amount_cents: 'integer' } },
signup_started: { owner: 'growth', purpose: 'Measure the sign-up funnel', properties: { source: ['home', 'pricing'] } },
};
export const EVENT_NAME = /^[a-z]+(_[a-z]+)+$/;
Python example
import re
EVENTS = {
"order_completed": {"owner": "checkout", "purpose": "Count sales per plan",
"properties": {"order_id": str, "plan": ("basic", "pro"), "amount_cents": int}},
"signup_started": {"owner": "growth", "purpose": "Measure the sign-up funnel",
"properties": {"source": ("home", "pricing")}},
}
EVENT_NAME = re.compile(r"^[a-z]+(_[a-z]+)+$")
def test_event_names_follow_the_scheme():
assert all(EVENT_NAME.match(name) for name in EVENTS)
How to check
A test reads the plan and fails on any name that does not match ^[a-z]+(_[a-z]+)+$. A grep finds no call to the raw track( function outside the generated module.
Sources
Related rules
- AIF-49 Collect feedback on every answer in AI features
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/analytics/events-and-metrics/tracking-plan">Agent Wranglers product analytics and experiments playbook</a>. In code you write, add a comment next to it with the same link.