Email Reports
Weekly analytics digests delivered to your inbox. The email-reports worker runs on a cron schedule and queries your analytics worker to build and send a summary email.
Overview
Each weekly report includes:
- KPI cards — pageviews, unique visitors, and custom event count with week-over-week change
- Anomaly alerts — flagged automatically when traffic changes by more than 30%
- Top 5 pages by pageviews
- Top 3 referrer sources
- Top 3 countries
- Bot traffic summary — total blocked requests and top bot user-agents
The email-reports package is a separate Cloudflare Worker. It does not share state with the main analytics worker — it only calls the analytics worker's /query API to fetch data.
Setup
Copy the example config:
Edit packages/email-reports/wrangler.toml with your values:
Environment variables:
ANALYTICS_WORKER_URL— base URL of your main analytics workerANALYTICS_API_KEY— theQUERY_API_KEYsecret from your main workerEMAIL_API_URL— email service base URL (Euromail, Resend, SendGrid)EMAIL_API_KEY— email service API keyEMAIL_FROM— sender addressSITE_NAME— displayed in the report headerSITE_URL— used for page links in the report
Create the KV namespace for recipients and copy the ID into wrangler.toml:
Set the secrets that should not go in wrangler.toml:
Deploy:
0 9 * * 1 fires every Monday at 9am UTC. Adjust the cron expression in wrangler.toml to change the schedule. Cloudflare cron triggers require a paid Workers plan.
Managing recipients
All recipient endpoints require X-API-Key: <ADMIN_API_KEY>.
Add a recipient
Remove a recipient
List all recipients
Testing
Send a test report to any address without waiting for the cron to fire:
The response includes the generated subject line and whether the send succeeded.
Report contents
Each digest covers the previous 7 days and compares it to the 7 days before that.
- KPI cards — pageviews, unique visitors, and custom event count, each with a colour-coded week-over-week percentage change
- Anomaly alerts — shown when pageview count changes by more than 30% compared to the prior week
- Top 5 pages — paths ranked by pageview count
- Top 3 referrers — referrer hostnames ranked by visit count
- Top 3 countries — country codes ranked by pageview count
- Bot traffic — total blocked requests and up to 5 top bot user-agents (only shown when bot hits are present)
Was this page helpful?