6 min read

Anomaly Insights, Slack, Discord & Webhooks

How TrimStats detects traffic drops, spikes, conversion dips, and friction surges against rolling 7-day baselines and delivers alerts and digests to email, Slack, Discord, and HMAC-signed webhooks.

Imtiaz Rayhan
Imtiaz RayhanCo-Founder & Lead Engineer, DotCamp & TrimStats
Verified against live TrimStats APIs
Quick reference

How do TrimStats automated anomaly insights, Slack/Discord alerts, and digests work?

Every 6 hours, TrimStats compares rolling 7 completed UTC days against the prior 7 completed UTC days across site traffic, top 40 pages, top 30 referrers, up to 10 goals, and UI friction routes. Alerts and weekly or monthly digests deliver to email, Slack, Discord, or HMAC-signed JSON webhooks, capped by Valkey to 1 anomaly notification per UTC day per rule.

Why rolling 7-day baseline detection avoids false alarms

Naive analytics alerts compare today against yesterday and page you every Saturday morning because B2B traffic naturally dips on weekends. They also trigger false alarms on tiny samples where dropping from 4 visitors to 2 looks like a -50% crash.

TrimStats solves both problems by comparing 7 completed UTC days (yesterday minus 6 through yesterday) against the preceding 7 completed UTC days (yesterday minus 14 through yesterday minus 8). Every full week contains the same mix of weekdays and weekend days, and every detector enforces a strict minimum sample-size guardrail.

Site analytics / Automated Insights
Active anomalies explain what shifted (+173.8% spike or +146.2% friction surge), which referrers or CSS selectors drove it, and the fastest next step to investigate.

Active anomalies appear on the dedicated Insights page in your site sidebar with 14-day daily trends, contributing drivers, 30-day history, and actionable tips, and can trigger automated alerts to email, Slack, Discord, or generic HTTPS webhooks.

Anomaly types & statistical guardrails

Every anomaly detector enforces a minimum sample-size guardrail to prevent false alarms on low-traffic pages or goals:

Anomaly typeDimensionMinimum baseline / volumeTrigger threshold
traffic_dropSite-wide>= 50 baseline visitors<= -25% change
traffic_spikeSite-wide>= 50 baseline visitors>= +60% change
traffic_drop / traffic_spikeTop 40 pages (pathname)>= 40 baseline visitors<= -30% drop or >= +80% spike
traffic_drop / traffic_spikeTop 30 referrers>= 30 baseline visitors<= -30% drop or >= +80% spike
conversion_dipConfigured goals (up to 10)>= 15 baseline goal conversions & >= 50 site visitors<= -25% drop in conversion rate
friction_spikePages with rage/dead clicks>= 15 friction clicks in current 7d>= +50% increase vs baseline

Supported delivery channels

Configure up to 20 alert rules per site under Site settings -> Anomaly Alerts & Scheduled Digests. Each rule picks a delivery channel, anomaly types to subscribe to, and an optional weekly (Mondays 08:00 UTC) or monthly (1st of month 08:00 UTC) summary digest.

ChannelTarget formatPayload & security
EmailVerified workspace member emailHTML + plain-text alert and digest emails delivered via Resend.
Slackhttps://hooks.slack.com/services/...Slack Block Kit cards with escaped mrkdwn (prevents @channel/@here injection). URL stored AES-256-GCM encrypted and masked after saving.
Discordhttps://discord.com/api/webhooks/... (optional ?thread_id=)Discord embeds with allowed_mentions: { parse: [] } so untrusted paths cannot ping roles. URL stored AES-256-GCM encrypted and masked after saving.
WebhookAny public HTTPS endpoint on port 443Versioned JSON signed with X-TrimStats-Signature HMAC-SHA256. DNS is resolved to public IPs only with IP-pinned HTTPS connections, no redirects, and a 5-second timeout.

Setting up & testing alert rules

Site settings / Anomaly Alerts & Digests
Route specific anomaly types and weekly or monthly summaries to email, Slack, Discord, or HMAC-signed webhooks, then confirm delivery immediately with Test.
  1. 1

    Open Site settings -> Alerts

    Navigate to Site settings -> Anomaly Alerts & Scheduled Digests and choose Email, Slack, Discord, or Webhook.

  2. 2

    Enter target, anomaly types, and digest cadence

    Paste the verified member email or HTTPS webhook URL, pick an optional display label, toggle which anomaly types should fire, and select Weekly digest + alerts, Monthly digest + alerts, or Anomaly alerts only.

  3. 3

    Copy the signing secret (generic webhooks only)

    Generic webhooks automatically generate a 32-byte whsec_... signing secret that is displayed once immediately after saving. Store it in your receiver environment to verify incoming requests.

  4. 4

    Click Test to verify delivery

    Click Test next to any rule to send an immediate test ping from the collector (rate-limited to 1 per 10 seconds per rule and 5 per 5 minutes per site). Scheduled anomaly checks run every 6 hours and deduplicate deliveries in Redis to at most one anomaly notification per UTC day per rule.

Verifying generic webhook signatures

Every generic webhook delivery is sent as an application/json POST request with replay-protected HMAC-SHA256 headers:

HeaderExample / FormatPurpose
X-TrimStats-Eventanomaly.detected, digest.weekly, digest.monthly, webhook.testEvent type for routing inside your handler.
X-TrimStats-DeliveryUUID v4Unique delivery identifier for idempotent processing.
X-TrimStats-TimestampUnix seconds (1764576000)Timestamp used when computing the signature.
X-TrimStats-Signaturet=<unix>,v1=<hex_hmac_sha256>Hex HMAC-SHA256 over ${timestamp}.${rawBody} using your whsec_... secret.
verify-trimstats-alert.tsts
1import crypto from 'node:crypto';
2
3export function verifyTrimStatsAlertWebhook(
4 rawBody: string,
5 signatureHeader: string | undefined,
6 secret: string,
7 toleranceSec = 300,
8): boolean {
9 if (!signatureHeader || !secret) return false;
10
11 let timestamp = 0;
12 let signature = '';
13 for (const part of signatureHeader.split(',')) {
14 const [k, v] = part.trim().split('=');
15 if (k === 't' && v) timestamp = Number(v);
16 if (k === 'v1' && v) signature = v;
17 }
18
19 const nowSec = Math.floor(Date.now() / 1000);
20 if (!timestamp || !signature || Math.abs(nowSec - timestamp) > toleranceSec) {
21 return false;
22 }
23
24 const expected = crypto
25 .createHmac('sha256', secret)
26 .update(`${timestamp}.${rawBody}`, 'utf8')
27 .digest('hex');
28
29 const a = Buffer.from(signature, 'utf8');
30 const b = Buffer.from(expected, 'utf8');
31 return a.length === b.length && crypto.timingSafeEqual(a, b);
32}
Example anomaly.detected payloadjson
1{
2 "version": "2026-12-01",
3 "event": "anomaly.detected",
4 "deliveryId": "c1f8a92e-4f10-4b22-9f41-6b8a7e0e1234",
5 "sentAt": "2026-12-01T06:00:00.000Z",
6 "site": { "id": "...", "name": "Acme SaaS", "domain": "acme.com" },
7 "dashboardUrl": "https://www.trimstats.com/sites/.../insights",
8 "data": {
9 "count": 1,
10 "anomalies": [
11 {
12 "type": "traffic_drop",
13 "dimension": "pathname",
14 "dimensionValue": "/pricing",
15 "baselineValue": 1200,
16 "currentValue": 780,
17 "pctChange": -35,
18 "sampleSize": 1980,
19 "detectedAt": "2026-12-01T06:00:00.000Z"
20 }
21 ]
22 }
23}
Outbound SSRF & timeout guardrails

Generic webhooks require HTTPS on port 443 and must resolve exclusively to public IP addresses. TrimStats pins the validated IP per connection, disables HTTP redirects, enforces a 5-second timeout, and treats any non-2xx status as a failed delivery.

Common technical questions

What exact percentage thresholds trigger TrimStats anomaly insights?
Site traffic triggers at <= -25% drop or >= +60% spike (>= 50 baseline visitors); pages and referrers at <= -30% or >= +80% (>= 30-40 visitors); conversion goals at <= -25% (>= 15 baseline conversions); and UI friction at >= +50% (>= 15 clicks).
Which alert channels and digest cadences can I configure per site?
Each site supports up to 20 alert rules across Email, Slack incoming webhooks, Discord webhooks, and generic HTTPS webhooks. Every rule chooses which anomaly types trigger notifications plus Weekly digest + alerts, Monthly digest + alerts, or Anomaly alerts only, with a rate-limited Test button in Site settings.
How do I verify generic TrimStats alert webhook signatures?
TrimStats generates a unique whsec_ signing secret per generic webhook rule and sends X-TrimStats-Signature: t=<unix>,v1=<hex_hmac_sha256> computed over `${t}.${rawBody}`. Reject timestamps older than 5 minutes and compare the hex digest with crypto.timingSafeEqual.

Related guides