Product analytics Required
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.
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]+)+$/;
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.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers data playbook: https://agentwranglers.se/playbook/data/product-analytics/tracking-plan.