---
title: Feed a metric
description: A pipeline that writes one number a day from an analytics query, authored as a routine.
---

**You get** a metric that holds one observation per day, fetched from a
query API by a routine Foundation runs, so the number is current when anyone
asks and nobody types it.

## The prompt

```text
Read the skill at https://github.com/fred-abrahamson/midland-examples/blob/main/feed-a-metric/SKILL.md and follow it. Outcome: the metric "Active customers (28d)" holds, every morning at 06:00 Europe/Berlin, the count of distinct customers with a product event in the trailing 28 days. Source: our analytics query API, credential "analytics-query". Definition: an active subscription, excluding accounts on our own email domain. Draft the routine, preview it against yesterday's window, and stop before activating so I can compare the number.
```

## The skill

[feed-a-metric/SKILL.md](https://github.com/fred-abrahamson/midland-examples/blob/main/feed-a-metric/SKILL.md) covers the runtime
contract, the reporting window, the query and one write keyed by the window
end. It also covers fixtures for a value and for an empty result, and shows
what a good preview looks like.

## Check

The preview's value matches the number in the provider's own dashboard for
the same window. Activate. Tomorrow the metric shows a new observation, and
the routine's attempt links to it.
