Skip to main content

How to Add a New Case

The two default cases (ga4_events and ga4_sessions) cover event counts and session traffic. If you want to monitor something else, for example revenue by product category or transactions by country, you create a new case. A case is a self-contained configuration that tells the module which table to read, which metric to track, and how to group the data.

This guide walks through adding a new case called ga4_purchases that monitors purchase revenue broken down by country.

What you will need

  • The anomaly detection module enabled in your project ("enabled": true in includes/custom/modules/anomaly_detection/config.json)
  • A BigQuery table containing the metric you want to monitor, with at least 60 days of daily history
  • Familiarity with the Getting Started guide

Step 1: Register the case in module config

Open includes/custom/modules/anomaly_detection/config.json and add your new case name to the cases array:

{
"enabled": true,
"version": 1,
"cases": ["ga4_events", "ga4_sessions", "ga4_purchases"]
}

The case name must match exactly the filename you will create in the next step.

Step 2: Create the case file

Create a new file at includes/custom/modules/anomaly_detection/cases/ga4_purchases.yaml.

The file below is a working starting point. Update the fields marked with # ← set this to match your source table and data structure. Everything else can stay as-is for a first run.

model_type: "ARIMA_PLUS"

case_data_project: "your_project_id" # ← set this
case_data_dataset: "your_dataset_id" # ← set this
case_data_table: "ga4_purchases" # ← set this

model_cron: "* * *"

training_start_date: ""
training_end_date: ""
training_end_days_ago: 2
training_window_days: 90

time_series_timestamp_col: "event_date" # ← set this
time_series_data_col: "revenue" # ← set this
time_series_data_agg: "sum"

time_series_id_cols:
- "country" # ← set this

data_frequency: "DAILY"
decompose_time_series: true
clean_spikes_and_dips: true
adjust_step_changes: true
auto_arima: true

training_min_series_days: 60
training_min_series_avg: 20
top_n_time_series: 5

detection_min_series_days: 7
detection_min_series_avg: 50

anomaly_detection_end_days_ago: 2
anomaly_detection_window_days: 7

anomaly_prob_threshold: 0.97
model_version: 1
Start with a single dimension

Every entry in time_series_id_cols multiplies the number of models the module trains. For a first run, one dimension is enough. Add more only once you have confirmed the results are reliable.

Step 3: Run the module

In your Dataform workspace, open Start execution, select Tags, and enter:

module_anomaly_detection

Dataform will pick up the new case and run the full pipeline for it alongside the existing cases. With three cases active, you will see nine intermediate actions plus the shared anomaly_detection_report output.

Step 4: Commit your changes

Once the run completes without errors, go back to your Dataform workspace and click Commit in the top bar.

Write a short commit message, for example:

feat: add ga4_purchases anomaly detection case

Click Commit to save your changes to the repository.

Next steps