Skip to content
HomeScripts/gads-anomaly-detector

Z-score anomaly detection (Python CLI)

A command from the google-ads-agents repo. Takes a 14-day rolling mean and standard deviation for spend, CTR, CPC and conversions, and flags days more than two standard deviations out.

Python CLI
# Run via google-ads-agents CLI
python scripts/gads_anomalies.py \
  --customer 123-456-7890 \
  --days 30 \
  --baseline-days 14 \
  --z 2 \
  --json

How it works

  1. Calculates mean and standard deviation for key metrics (Spend, CTR, CPC, Conversions) over a 14-day rolling window.
  2. Computes Z-score distance from historical baseline.
  3. Flags any date where the Z-score exceeds 2.0 (statistically significant anomaly at p < 0.05).

Step-by-step installation

  1. Clone repository: git clone https://github.com/arcbaslow/google-ads-agents
  2. Install dependencies: uv pip install -r scripts/requirements.txt
  3. Authenticate: python scripts/gads_auth.py --adc
  4. Run the anomaly command with your customer ID.

Frequently asked questions

Can this run in CI?

Pass --json and it writes machine-readable output to stdout, which is enough for a GitHub Actions step or a cron job to parse.

Need one of these adapted to your account?

We write Google Ads scripts, set up server-side GA4, and build the reporting that answers a specific question.