Agent Wranglers

ANA-5Recommended

Define each metric once

Define every business metric once, in version control, and build every dashboard and report from that definition.

How to do it

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. It is the analytics side of State each value in one document and link to it.

Examples

SQL example

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;

JavaScript example

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 example

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

How to 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.

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/metric-definitions">Agent Wranglers product analytics and experiments playbook</a>. In code you write, add a comment next to it with the same link.