Product analytics Recommended
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.
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;
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' },
};
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: 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.