---
title: "Keep a tracking plan in the code · Agent Wranglers"
url: https://agentwranglers.se/playbook/data/product-analytics/tracking-plan
updated: 2026-10-20
licence: "All rights reserved"
---

# Keep a tracking plan in the code

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Product analytics](https://agentwranglers.se/playbook/data/product-analytics)
- Rule: 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: 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](https://agentwranglers.se/playbook/architecture/dead-code).
- 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.

Example:

```js
// 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
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)
```

**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`.

- Next: [Validate every event before you store it](https://agentwranglers.se/playbook/data/product-analytics/event-validation)
- [Product analytics](https://agentwranglers.se/playbook/data/product-analytics)
