Google Ads Script for SMBs — Detect abnormal drops in impressions, CPC spikes, and cost surges.
This script compares today's account-level metrics against a rolling average (last 7 days by default). It checks for three types of anomalies: impression drops, CPC spikes, and cost spikes. When any threshold is exceeded, an email alert is sent with the current values and baseline comparison.
- Open Google Ads > Tools > Scripts
- Create a new script and paste the code from
main_en.gs(ormain_fr.gsfor French) - Update the
CONFIGblock at the top - Authorize and run a preview first
- Schedule: Daily (ideally in the afternoon for meaningful same-day data)
| Parameter | Default | Description |
|---|---|---|
TEST_MODE |
true |
When true, logs alerts without sending emails |
EMAIL |
contact@yourdomain.com |
Email address for anomaly alerts |
IMPRESSIONS_DROP_THRESHOLD |
0.5 |
Alert if today's impressions < 50% of average |
CPC_SPIKE_THRESHOLD |
1.5 |
Alert if today's CPC > 150% of average |
COST_SPIKE_THRESHOLD |
1.5 |
Alert if today's cost > 150% of daily average |
COMPARISON_RANGE |
LAST_7_DAYS |
Baseline period for average calculation |
COMPARISON_DAYS |
7 |
Number of days in the comparison range |
- Fetches today's account stats and the baseline period stats
- Calculates daily averages for impressions, CPC, and cost
- Compares today's values against thresholds
- Sends an email alert listing all anomalies with percentage comparisons
- Google Ads account
- Google Ads Scripts access
MIT — Thibault Fayol Consulting