Skip to main content
Create metrics that aggregate measurements across instances of an entity.

Before You Begin

Before creating a metric, ensure you have:
  • An API access token with appropriate permissions
  • Created the entity you want to measure
  • Created a fact table with the measurements to aggregate
  • Determined the aggregation type and time windows

Create an Average Metric

Create an average metric that measures the average sales amount per user:
curl -X POST "https://api.confidence.dev/v1/metrics" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "displayName": "Average sales amount per user during the first week after exposure",
    "entity": "entities/user",
    "factTable": "factTables/my-fact-table",
    "aggregationWindow": "604800s",
    "exposureOffset": "0s",
    "typeSpec": {
      "averageMetricSpec": {
        "measurement": {
          "name": "sales_amount",
          "repeated": false
        },
        "aggregation": {
          "type": "AGGREGATION_TYPE_SUM"
        }
      }
    },
    "varianceReductionConfig": {
      "disabled": false
    }
  }'

Create a Ratio Metric

Create a ratio metric like conversion rate:
curl -X POST "https://api.confidence.dev/v1/metrics" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "displayName": "Conversion rate in first week",
    "entity": "entities/user",
    "factTable": "factTables/conversions",
    "aggregationWindow": "604800s",
    "exposureOffset": "0s",
    "typeSpec": {
      "ratioMetricSpec": {
        "numerator": {
          "measurement": {
            "name": "converted",
            "repeated": false
          },
          "aggregation": {
            "type": "AGGREGATION_TYPE_SUM"
          }
        },
        "denominator": {
          "measurement": {
            "name": "eligible",
            "repeated": false
          },
          "aggregation": {
            "type": "AGGREGATION_TYPE_SUM"
          }
        }
      }
    },
    "varianceReductionConfig": {
      "disabled": false
    }
  }'

Aggregation Types

For average metrics, choose how to aggregate data within units:
  • AGGREGATION_TYPE_SUM: Sum all measurements
  • AGGREGATION_TYPE_COUNT: Count occurrences
  • AGGREGATION_TYPE_COUNT_DISTINCT: Count unique values
  • AGGREGATION_TYPE_MAX: Maximum value
  • AGGREGATION_TYPE_MIN: Minimum value
  • AGGREGATION_TYPE_UNIQUE: Single unique value (fails if multiple values exist)

Time Windows

Aggregation Window

The aggregationWindow defines how long after exposure to aggregate measurements:
"aggregationWindow": "604800s"  // 7 days
Common windows:
  • 86400s: 1 day
  • 604800s: 7 days
  • 2592000s: 30 days

Exposure Offset

The exposureOffset defines how long to wait after exposure before starting measurement:
"exposureOffset": "0s"  // Start immediately
Example with delay:
"exposureOffset": "86400s"  // Wait 1 day before measuring

Variance Reduction (CUPED)

Enable or disable variance reduction to improve statistical power:

Enabled (Default)

"varianceReductionConfig": {
  "disabled": false
}

Disabled

"varianceReductionConfig": {
  "disabled": true
}

Next Steps

After creating metrics:
  • Configure experiments to track these metrics
  • Analyze experiment results using these metrics
  • Create additional metrics to measure different aspects of user behavior