Skip to content

mixpanel_metric (Resource)

Manages a Mixpanel metric (mixpanel_metric) — a saved behavioral metric definition that measures aggregations over user behaviors, used for tracking KPIs and building reports. See mixpanel_formula for formula-based metrics.

Example Usage

# A behavioral metric. `definition` is a Mixpanel metric definition document
# (BehaviorMetricDefinition) passed through verbatim as JSON.
resource "mixpanel_metric" "signups" {
  project_id = 1234567
  name       = "Signups"
  type       = "metric"
  definition = jsonencode({
    measurement = { /* aggregation over a behavior */ }
    behavior    = { /* the behavior to measure */ }
  })
}

Schema

Required

  • name (String)
  • type (String)

Optional

  • contacts (List of String)
  • definition (String)
  • description (String)
  • metric_id (Number)
  • owned_by (Attributes) (see below for nested schema)
  • project_id (Number)
  • share_with_project (Boolean) Whether to share this entity with the whole project after creation. Entities created by a service account are otherwise visible only to that service account. Defaults to true. See the Entity sharing guide.
  • verified (Boolean)

Read-Only

  • allow_staff_override (Boolean)
  • can_share (Boolean)
  • can_update_basic (Boolean)
  • can_update_restricted (Boolean)
  • can_update_visibility (Boolean)
  • can_view (Boolean)
  • created (String)
  • created_by (Attributes) (see below for nested schema)
  • id (Number) The ID of this resource.
  • is_locked (Boolean)
  • is_superadmin (Boolean)
  • is_visible (Boolean)
  • last_verified (String)
  • last_verified_by (Attributes) (see below for nested schema)
  • modified (String)

Nested Schema for owned_by

Required:

  • email (String)
  • id (Number)
  • name (String)

Nested Schema for created_by

Read-Only:

  • email (String)
  • id (Number)
  • name (String)

Nested Schema for last_verified_by

Read-Only:

  • email (String)
  • id (Number)
  • name (String)

Plan-time validation of definition

A malformed metric definition can be accepted by the API with a 200 and then crash the Mixpanel webapp query builder. The provider validates the decoded JSON at terraform plan time and rejects the known-corrupting shapes:

  • definition.measurement.property must be a JSON object (or null) — a string/number/array property is the confirmed-crash "wrong type" shape;
  • property-aggregating math (average, median, p25p99, custom_percentile, min, max, histogram, unique_values, most_frequent, first_value, numeric_summary) requires a non-null property (total without a property means count-of-events and is fine);
  • funnel behaviors need 2–100 steps and every step must name an event;
  • funnelOrder must be "loose" or "any";
  • for retention metrics, measurement.retentionSegmentationEvent must match one of the retention step events (the webapp derives it from behaviors[1].name).

Import

Metrics can be imported using the composite PROJECT_ID:ID format:

import {
  to = mixpanel_metric.signups
  id = "1234567:890"
}
terraform import mixpanel_metric.signups 1234567:890