---
title: "Define each metric once · Agent Wranglers"
url: https://agentwranglers.se/playbook/data/product-analytics/metric-definitions
updated: 2026-10-20
licence: "All rights reserved"
---

# Define each metric once

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

- Level: Recommended
- Chapter: [Product analytics](https://agentwranglers.se/playbook/data/product-analytics)
- Rule: Define every business metric once, in version control, and build every dashboard and report from that definition.
- How: Write the definition as code or SQL with a name, owner, formula, filters and time zone. A semantic layer such as dbt's MetricFlow or Cube does this, or a folder of reviewed SQL views. "Active user" must mean the same in every chart, for example "signed in at least once in the last 28 days". Change a definition through review, and note the change date on charts.
- Check: A script lists every saved dashboard query and fails on any that computes a named metric without the shared view or metric. Two dashboards showing the same metric for the same day show the same number.

Example:

```sql
CREATE VIEW metric_weekly_active_users AS
SELECT date_trunc('week', received_at AT TIME ZONE 'UTC') AS week,
       count(DISTINCT anonymous_id) AS weekly_active_users
FROM events
WHERE name = 'session_started' AND traffic = 'visitor'
GROUP BY 1;
```

```js
export const METRICS = {
  weekly_active_users: { owner: 'product', view: 'metric_weekly_active_users', definition: 'Distinct analytics IDs with session_started in an ISO week, UTC' },
};
```

```python
METRICS = {
    "weekly_active_users": {"owner": "product", "view": "metric_weekly_active_users",
                            "definition": "Distinct analytics IDs with session_started in an ISO week, UTC"},
}
```

**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/metric-definitions`.

- Previous: [Record business facts on the server](https://agentwranglers.se/playbook/data/product-analytics/server-side-business-events)
- Next: [Keep test and bot traffic out of the numbers](https://agentwranglers.se/playbook/data/product-analytics/exclude-test-traffic)
- [Product analytics](https://agentwranglers.se/playbook/data/product-analytics)
