How to set up daily alerting on marketing metrics with SQL

Anton Prygin20 Jun 2025

Problem

The marketing team of Garage Eight watched registrations and product activations every day on dashboards. Reading the charts took time, and the team wanted to open them only after a sharp spike or drop. They wanted a daily message saying whether the metrics were anomalous, simple enough for an analyst to build and maintain in SQL. A first rule, z-score alone, missed significant changes and flagged others wrongly.

Example from the article: a daily registrations series with visible peaks and deep drops, where z-score alone left several real movements unflagged.

Solution in brief

Two SQL checks run on each daily metric. A z-score over the previous 13 days of the same day type (workday or weekend) reacts fast to current drops. The 99th and 1st percentiles over 28 days mark extreme values. One alert means a non-critical anomaly; both together mean the marketing team should investigate. The result, with plan-versus-fact, is posted to a messenger through an API connection.

Questions this case answers
  • How to flag anomalies in a daily business metric with weekday and weekend differences using only SQL window functions and no model training
  • How to cut false and missed alerts of a single threshold rule by requiring agreement between two rules of different time horizons
  • How to replace daily dashboard checks of registrations and activations with an alert that fires only on real anomalies?
  • How to detect anomalies in a daily metric with plain SQL and no ML model?

Tools and methods

  • Z-score on a 13-day window — sensitive, short-horizon anomaly rule
  • 99th/1st percentile over 28 days — distribution-free rule for extreme values
  • Slack — daily delivery of the alert message
  • Plan-versus-fact traffic lights — red below 60%, yellow below 90%, green otherwise
Continue reading — it's free

Google or a one-time email code. No password.