---
title: "Keep a tracking plan in the code · Agent Wranglers"
url: https://agentwranglers.se/playbook/analytics/events-and-metrics/tracking-plan
id: ANA-1
level: Recommended
updated: 2026-10-27
build: a2a6bdfed830
tokens: 854
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Keep a tracking plan in the code

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Events and metrics](https://agentwranglers.se/playbook/analytics/events-and-metrics.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: ANA-1
- Level: Recommended
- Chapter: [Events and metrics](https://agentwranglers.se/playbook/analytics/events-and-metrics.md)
- 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.
- 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.
- 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/structure.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript 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 example

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

## Sources

- [JSON Schema 2020-12](https://json-schema.org/draft/2020-12)

## Related rules

- AIF-49 [Collect feedback on every answer](https://agentwranglers.se/playbook/ai-features/logs-privacy-and-feedback/feedback-on-every-answer.md) in AI features

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/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.

- Next: [Validate every event before you store it](https://agentwranglers.se/playbook/analytics/events-and-metrics/event-validation.md)
- [Events and metrics](https://agentwranglers.se/playbook/analytics/events-and-metrics.md)
