Setting up a traffic alert takes two minutes. You pick a metric, type a number that feels right, and point it at Slack or a webhook. Then one of two things happens. Either it fires every Saturday night until someone mutes the channel, or it stays quiet on the afternoon a deploy removes your tracking tag and nobody notices for a day.
Both outcomes are predictable from data you already have. If your analytics tool can export hourly visitors, you can replay any rule over the last few months and count two things before it ever wakes anyone up: how many notifications it would have sent, and which of your known incidents it would have caught. That's a backtest, and it's about 35 lines of Python.
The data: a fictional site with four known incidents
To score rules you need the truth, and with real data the truth is fuzzy. So I simulated one: 84 days (2,016 hours, 7 September to 29 November 2026) of a small site with a normal daily curve, quieter weekends, slow growth and random noise. The generator is seeded, so every number below can be reproduced. Then I planted four events:
- Launch week (5–11 October): traffic ×2.2 for seven days. Real, and good news. You probably want to know, once.
- Tracking outage (21 October, 14:00, 5 hours): a deploy drops the tag and visitors fall to 0–3 an hour. This is the one an alert exists for.
- Partial breakage (4 November, 09:00, 8 hours): a consent-banner change loses 45% of visits. Bad, and much harder to spot.
- Bot burst (18 November, 03:00, 3 hours): +600 visitors an hour in the middle of the night.
The rules never see this list. It's only used afterwards to score them: a notification counts as "caught" if it fires during an event (or within an hour after it ends) and as noise otherwise.
The script
Each rule is a function that looks at one hour and says "this is off". The backtest walks through the hours and counts episodes, not hours: a notification goes out when a rule switches into alert, and nothing more until it switches back. That's how most alerting tools behave, and it's the number your team actually experiences.
import csv, statistics as st from datetime import datetime, timedelta rows = [(datetime.strptime(h, '%Y-%m-%d %H:%M'), int(v)) for h, v in list(csv.reader(open('hourly.csv')))[1:]] def baseline(i, how): # same hour of the week, previous 4 weeks past = [rows[i - 168 * k][1] for k in range(1, 5) if i - 168 * k >= 0] return None if len(past) < 4 else (st.median(past) if how == 'median' else st.mean(past)) def backtest(name, fire, recover=None, need=1): alerts, on, streak = [], False, 0 for i, (ts, v) in enumerate(rows): hit = fire(i, v) streak = streak + 1 if hit else 0 if not on and streak >= need: on = True; alerts.append(ts) # one notification per episode elif on and (recover(i, v) if recover else not hit): on = False return name, alerts def off_by(pct, how, min_base=0): # True when v is more than pct away from the baseline def f(i, v): b = baseline(i, how) return b is not None and b >= min_base and abs(v - b) > pct * b return f RULES = [ backtest('fixed: <40 or >400', lambda i, v: v < 40 or v > 400), backtest('fixed + recovery: fire <40/>400, clear >60/<350', lambda i, v: v < 40 or v > 400, recover=lambda i, v: 60 < v < 350), backtest('same hour last 4 weeks, MEAN, ±50%', off_by(0.5, 'mean')), backtest('same hour last 4 weeks, MEDIAN, ±50%', off_by(0.5, 'median')), backtest('MEDIAN ±50%, 2 hours in a row', off_by(0.5, 'median'), need=2), backtest('MEDIAN ±40%, 2 hours in a row', off_by(0.4, 'median'), need=2), backtest('MEDIAN ±40%, 2 hours, baseline >= 100', off_by(0.4, 'median', 100), need=2), ] Three knobs are worth naming:
-
recover: a separate threshold for switching the alert off again. Without it, a value hovering around the limit fires, clears, fires, clears. -
need: how many hours in a row the condition must hold before anyone is told. -
baseline: what "normal" means. A fixed number, or the same hour of the week over the previous four weeks (168 hours = one week back), averaged with a mean or a median.
The input is a two-column CSV, hour,visitors, one row per hour. A short scoring script compares the notifications with the event list.
The results
| Rule | Notifications | Not during any event | Launch week | Tracking outage | Partial breakage | Bot burst |
|---|---|---|---|---|---|---|
| Fixed: <40 or >400 | 77 | 66 | after 13 h (9 notifications) | 1 h | missed | 1 h |
| Fixed + recovery threshold | 46 | 39 | after 13 h (5) | 1 h | missed | 1 h |
| Same hour, mean, ±50% | 37 | 30 | 1 h (4) | 1 h | 1 h | 1 h |
| Same hour, median, ±50% | 32 | 24 | 1 h (5) | 1 h | after 5 h | 1 h |
| Median ±50%, 2 h in a row | 6 | 1 | 2 h (3) | 2 h | missed | 2 h |
| Median ±40%, 2 h in a row | 8 | 2 | 2 h (3) | 2 h | 2 h | 2 h |
| Median ±40%, 2 h, baseline ≥ 100 | 9 | 0 | after 10 h (7) | 2 h | 2 h | missed |
"1 h" means the notification fired in the first hour of the event. Over 12 weeks, 66 needless notifications is between five and six a week, and that's what gets a channel muted.
Finding 1: A fixed threshold mostly measures your weekly pattern
The fixed rule (below 40 or above 400 visitors an hour) looks sensible on a weekday chart. But this site's quietest hours, weekend nights, sit right around 40. 58 of its 66 noise notifications were on weekend nights, between 21:00 and 06:00, when nothing was wrong.
It also caught the launch only after 13 hours, the first hour launch traffic crossed 400, and then fired nine separate times during the week as traffic swung above and below the line. And it missed the partial breakage completely: a weekday that lost 45% of its visits from 09:00 to 17:00 still had 79–122 visitors an hour, comfortably inside 40–400.
A fixed threshold is fine for one job: "visitors are basically zero", the dead-tag case. It caught the outage in the first hour. For that job, set the low line well below your quietest normal hour, not near it.
Finding 2: A recovery threshold cuts repeats, not wrong alarms
Adding a recovery threshold (fire below 40, clear only above 60, and the same idea at the top) took the fixed rule from 77 notifications to 46 and the launch-week repeats from nine to five. That's what recovery thresholds are for: a value that wobbles around the limit no longer re-fires every hour.
What it can't fix is a baseline that's wrong for the hour. 39 notifications were still noise, 32 of them on weekends again. Recovery thresholds are worth having on any rule, but they're a second step after choosing what "normal" is.
Finding 3: Compare with the same hour last weeks, and use the median
Comparing each hour with the same hour of the week over the last four weeks removes the daily and weekly pattern from the question. Both versions caught all four incidents at ±50%. The noise was still high (30 and 24 notifications). For the median rule, 22 of the 24 came between 20:00 and 05:00, small night hours where 50% is only a few dozen visitors.
The mean and the median behaved differently for a reason worth seeing. Here's 4 November, the partial-breakage day, with the four values each baseline was built from:
| Hour | Visitors | Mean baseline | Median baseline | Same hour, 1–4 weeks earlier |
|---|---|---|---|---|
| 09:00 | 79 | 178 | 142 | 117, 145, 139, 310 |
| 12:00 | 103 | 239 | 192 | 183, 154, 202, 417 |
| 14:00 | 122 | 199 | 206 | 186, 3, 226, 380 |
| 15:00 | 109 | 197 | 198 | 210, 0, 187, 391 |
Four weeks back was launch week (310, 417, 380, 391). Two weeks back was the tracking outage (3, 0). The mean swallowed both. In the morning, launch week inflated it, which is why the mean rule "caught" the breakage within an hour: right answer, wrong reason. In the afternoon the outage dragged it back down. A mean baseline inherits every incident of the last four weeks, and then raises false alarms or hides real ones for a month afterwards.
The median ignored one odd week out of four and stayed close to normal throughout. It caught the breakage only after five hours at ±50%, because a 45% drop sits just under a 50% threshold. That's honest behaviour, and the next findings deal with it.
Finding 4: "Two hours in a row" is the biggest noise filter
Requiring the condition to hold for two consecutive hours cut the median rule from 32 notifications to 6, and from 24 noise notifications to 1. The cost is exactly one hour of delay on every real event. For most sites, a dead tracking tag noticed after two hours instead of one is a fine trade for not training your team to ignore the channel.
At ±50% it missed the partial breakage. Tightening to ±40% caught all four incidents with 8 notifications and only 2 of them noise. On paper, that's the winner.
Finding 5: Don't trust the winner until it survives other data
I tuned ±40% on the same 12 weeks I scored it on, which is the classic way to fool yourself. So I regenerated the whole quarter with two other seeds: same pattern, same four events, different random noise. Then I re-ran every rule unchanged:
| Rule | Seed 42 (above) | Seed 7 | Seed 2026 |
|---|---|---|---|
| Median ±50%, 2 h | 6 notifications, 1 noise, breakage missed | 6, 2 noise, breakage missed | 3, 0 noise, breakage missed |
| Median ±40%, 2 h | 8, 2 noise, all caught | 11, 7 noise, breakage after 6 h | 13, 8 noise, breakage after 4 h |
| Median ±40%, 2 h, baseline ≥ 100 | 9, 0 noise, bot burst missed | 9, 0 noise, bot burst missed | 10, 0 noise, bot burst missed |
The "winner" sent three to four times as much noise on the other two quarters. The ±50% rule was boringly consistent: quiet every time, and every time blind to the 45% drop. The baseline guard (only alert when the same hour normally has at least 100 visitors) never sent a single noise notification, and never caught the 3 a.m. bot burst either, because 3 a.m. is exactly the kind of hour it ignores. It also fired seven times during launch week, once a day as each launch morning crossed the line.
None of these is "the right rule". Each is a different trade, and the backtest makes the trade visible. If you tune on your own data, choose on one period and check on another: tune on the first eight weeks and see whether the result holds on the last four, or compare this quarter with last.
Finding 6: Some failures need a different detector
The partial breakage is the incident a site owner would most want to catch, and no hourly rule caught it reliably without noise. I tried one more thing: a daily rule comparing each day's total with the median of the same weekday over the four weeks before. At ±20% it caught the breakage on one seed out of three. At ±15% it caught it on two of three, at the cost of one noise alert per quarter. An eight-hour, 45% drop on a site this size is close to the limit of what a visitor count can tell apart from noise.
That's not a reason to give up. It's a reason to catch some failures where they happen instead of downstream in the numbers. A consent-banner change that drops tracking is better caught by a test that runs before deploy. I wrote about putting a pre-consent check in CI a few days ago. Alerts are the safety net for whatever the tests didn't think of.
Running it on your own data
- Export hourly visitors for the last three months or more, as
hour,visitors. Four weeks of history are needed before the same-hour baseline starts, so 12 weeks gives you 8 weeks of scoring. - Write down what really happened. Deploys, outages, launches, campaigns, consent or tag changes. If you keep a release log for your analytics, you already have this list. If you don't, start one today, because next quarter's backtest needs it.
- Look at your quiet hours before picking numbers. Pull out one hour of the week, say all the Sunday 03:00 values, and paste them into a statistics calculator to see the median, quartiles and spread. If your quietest normal hour has a median of 40, a "below 40" rule will fire every week. One bot-heavy hour among a dozen normal ones moves the mean a lot and the median hardly at all, the same lesson as Finding 3.
- Replay several rules and read two columns: notifications per week that weren't incidents, and incidents missed. Decide in advance how many needless notifications per week your team will tolerate, then pick the most sensitive rule under that budget.
- Check the pick on a different period. If it falls apart, take the simpler rule.
- Plan for good news. Launches and campaigns will trigger traffic alerts. Mute or annotate them in advance instead of letting them teach people to ignore alerts.
- Re-run the backtest every few months. Traffic grows, the weekly pattern shifts, and a threshold that was right in spring can be noise by winter.
If you use DataVisitors, its Insights feature has threshold alerts on visitors, page views, events or bounce rate, with a separate recovery threshold, delivered to a webhook you configure. It's currently waitlist-only. A backtest like this is a cheap way to choose those numbers before you turn a rule on, whatever tool you end up using.
What this doesn't show
- Real traffic. The data is simulated, with noise that is better behaved than real traffic. Real sites have holidays, outages at the analytics vendor, and slow drifts that no planted event represents.
- Other metrics. Only visitors per hour. Conversion rates, bounce rate and event counts have their own noise, and ratio metrics need minimum-volume guards even more.
- Smarter detectors. Seasonal decomposition, forecasting models and anomaly-detection services can do better than a median of four values. They still need the same backtest, and the simple rules make a good baseline to beat.
- Your team's tolerance. "Two noise notifications a quarter" is a choice, not a law. The backtest gives you the counts; the budget is yours.
The script, the generator and the scoring code are short enough to adapt in an afternoon. The rule that survives a backtest on your own history will be much less exciting than the one you'd have typed into the alert form, and much more likely to still be switched on next month.
Need an internal dashboard with alert rules your team can review? The team behind FindUtils takes on freelance work on Upwork, including a Laravel Livewire app or admin panel with dynamic pages and forms.