Skip to content

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
# 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. Takes the mean and standard deviation of spend, CTR, CPC and conversions over a 14-day rolling window.
  2. Scores each day by its distance from that baseline in standard deviations.
  3. Flags days where the score passes 2.0, roughly the outer 5% under a normal distribution.

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.

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 adapted to your account?

We write Google Ads scripts, set up server-side GA4 and build reports that answer a specific question.