Originally published on Extenify.
Z-score anomaly detection is the usual first try when you want alerts on daily installs, active users or reviews, but the textbook rolling version is close to useless on real app metrics. Here is why it stays silent when a release breaks something, and the three changes that make it catch a real drop on day one, with a small Node.js function you can reuse.
The textbook version, tested on real data
The classic formula is simple: z = (value - mean) / stddev, computed over a trailing window (say 28 days), with an alert when |z| passes about 3.
The Extenify team tested that exact setup on 184 days of daily npm downloads for webextension-polyfill (May to October 2026). The series looks a lot like store data: a strong weekly rhythm (the median Saturday was only about 38% of the median Wednesday), a one-day spike, eleven days reported as zero by the source, and roughly 20% growth from mid-September. They also injected a 30% drop on three weekdays in late October.
The results:
- 1 day flagged out of 184 (the spike)
- 0 of 11 zero days flagged
- The injected 30% drop scored -0.11, missed even at a threshold of 2
Why a rolling z-score goes blind
Three effects stack on top of each other:
- Weekday swings inflate the standard deviation. A window mixing weekdays and weekends has a huge spread, so almost nothing looks unusual.
- Weekends drag the mean down. A weekday that lost 30% lands right next to the mixed mean, which is why the drop scored about zero.
- Bad points poison the window. Zeros and spikes widen the spread further and hide whatever comes next.
The z-score idea is fine. The baseline (mean and standard deviation of the raw series) is the problem.
Three fixes that make it work
Fix 1: treat impossible zeros as missing. A product with thousands of daily users never truly hits zero; that is a failed fetch or a reporting gap. Exclude it from the baseline, skip scoring it, and fire a separate "no data" alert.
Fix 2 (tried, rejected): compare with the same weekday. Using the median of the last eight Tuesdays flagged 11 days on normal data (mostly from growth and a holiday) and still missed the drop. Eight points per weekday are too few and too stale.
Fix 3: remove the weekday pattern, then score robustly.
- Learn a factor per weekday from the last 8 weeks: that weekday's median divided by the overall median.
- Divide every day by its factor so all recent days become comparable.
- Score against the last 14 adjusted days with the modified z-score,
0.6745 * (x - median) / MAD, as described in the NIST/SEMATECH e-Handbook. - Also require a minimum change (15%) so tiny but "significant" moves stay quiet.
A condensed version of the scoring step (Node.js 18+, no dependencies):
const median = (xs) => { const s = [...xs].sort((a, b) => a - b), m = Math.floor(s.length / 2); return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2; }; const dow = (day) => new Date(`${day}T00:00:00Z`).getUTCDay(); // series: [{ day: 'YYYY-MM-DD', value: number | null }], oldest first, zeros already set to null function scoreDay(series, i, { factorDays = 56, window = 14, threshold = 3, minChange = 0.15 } = {}) { const today = series[i]; if (i < factorDays || today.value === null) return null; const hist = series.slice(i - factorDays, i).filter((p) => p.value !== null); const typical = median(hist.map((p) => p.value)); const factor = (d) => { const v = hist.filter((p) => dow(p.day) === d).map((p) => p.value); return v.length >= 3 ? median(v) / typical : 1; }; const recent = series.slice(i - window, i) .filter((p) => p.value !== null) .map((p) => p.value / factor(dow(p.day))); if (recent.length < window / 2) return null; const x = today.value / factor(dow(today.day)); const base = median(recent); const mad = median(recent.map((v) => Math.abs(v - base))); if (mad === 0) return null; const score = (0.6745 * (x - base)) / mad; const change = (x - base) / base; const flagged = Math.abs(score) >= threshold && Math.abs(change) >= minChange; return { day: today.day, score, change, flagged }; } How the detectors compare
| Detector | Flags on normal data | Caught the 30% drop |
|---|---|---|
| Rolling z-score (mean/stddev, 28 days) | 1 | No (-0.11) |
| Same weekday (median/MAD, 8 weeks) | 11 | No |
| Weekday-adjusted median/MAD (14 days) | 2 | Yes, first day (-31%, score -3.4) |
Know the limits: normal noise in this series was about 6% of the level, so a drop had to be roughly 25% or more to pass. A 20% drop went unflagged, and the method needs about eight weeks of history before it can score anything.
Small counts and alert hygiene
Daily review counts are often tiny, so the median and MAD collapse to zero. Use a Poisson probability instead: how likely is today's count given the usual rate? Nine one-star reviews on a day that normally brings two has a probability of about 0.00024, while zero reviews when two are typical (0.135) is routine. Estimate the rate from the last 28 days' median and alert below about 0.001.
Then turn flags into alerts people trust:
- Alert once per episode, not once per flagged day.
- Respect direction: an install drop is urgent, a spike can wait for the weekly report.
- Annotate known events like releases, featuring and holidays.
- Keep a "no data" alert, since a silent collector looks like a quiet week.
Key takeaways
- A plain rolling z-score on daily data with a weekly rhythm misses real drops.
- Treat impossible zeros as missing and alert on them separately.
- Divide out weekday factors, then score with median and MAD instead of mean and standard deviation.
- Pair the score threshold with a minimum percentage change.
- Use a Poisson test, not a z-score, for small counts like reviews.
The original article includes the full CLI script, raw outputs and a per-metric checklist in its complete guide to z-score anomaly detection for daily app metrics. If you would rather not build the pipeline, Extenify tracks store installs, ratings and reviews and sends anomaly alerts for extensions and apps.
What does your team use to decide when a metric change deserves an alert?



