For AI agents: A markdown version of this page is available at https://dnd37xeb23o8n.cloudfront.net/jen.gilbert/astro-base/fr/api/latest/experiments/create-metric.md. A documentation index is available at /llms.txt.
Language
Datadog site
ATTENTIONCe produit n'est pas pris en charge par le site Datadog que vous avez sélectionné. (US1-FED).
ATTENTIONCe produit n'est pas pris en charge par le site Datadog que vous avez sélectionné. (US2-FED).

Create metric

POSThttps://api.datadoghq.com/api/v2/experiments/metricshttps://api.us3.datadoghq.com/api/v2/experiments/metricshttps://api.us5.datadoghq.com/api/v2/experiments/metricshttps://api.datadoghq.eu/api/v2/experiments/metricshttps://api.ap1.datadoghq.com/api/v2/experiments/metricshttps://api.ap2.datadoghq.com/api/v2/experiments/metricshttps://api.uk1.datadoghq.com/api/v2/experiments/metricshttps://api.ddog-gov.com/api/v2/experiments/metricshttps://api.us2.ddog-gov.com/api/v2/experiments/metrics

Présentation

Create a metric. The metric's type is derived from the aggregation shape: a numerator alone is SIMPLE, a numerator with a denominator is RATIO, and a percentile aggregation is PERCENTILE. Warehouse aggregations reference measures by UUID. Property filters use property_id or measure_id UUIDs returned by the same metric SQL model; every reference must belong to the aggregation's data source. The is_certified attribute is rejected. Certification cannot be changed through this endpoint.

This endpoint requires the product_analytics_metrics_write permission.

OAuth apps require the product_analytics_metrics_write authorization scope to access this endpoint.

Requête

Body Data (required)

Champ
Type
Description
data [required]
object

Metric resource to create.

Réponse

Created

Response containing the metric.

Champ
Type
Description
data [required]
object

JSON:API resource containing the metric identity and fields.

Exemple de code

Create metric returns "Created" response
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/experiments/metrics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "type": "metrics",
    "attributes": {
      "name": "ex-14bb9543f523edde",
      "data_source_type": "DATADOG",
      "desired_change": "METRIC_INCREASES",
      "numerator_aggregation": {
        "operation": "sum",
        "datadog_metric_measure": {
          "name": "ex-14bb9543f523edde view duration",
          "source_type": "PRODUCT_ANALYTICS",
          "source_subtype": "RUM_VIEWS",
          "column_type": "double",
          "column_name": "@view.time_spent"
        }
      }
    }
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/experiments/metrics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "type": "metrics",
    "attributes": {
      "name": "ex-14bb9543f523edde",
      "data_source_type": "DATADOG",
      "desired_change": "METRIC_INCREASES",
      "numerator_aggregation": {
        "operation": "sum",
        "datadog_metric_measure": {
          "name": "ex-14bb9543f523edde view duration",
          "source_type": "PRODUCT_ANALYTICS",
          "source_subtype": "RUM_VIEWS",
          "column_type": "double",
          "column_name": "@view.time_spent"
        }
      }
    }
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/experiments/metrics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "type": "metrics",
    "attributes": {
      "name": "ex-14bb9543f523edde",
      "data_source_type": "DATADOG",
      "desired_change": "METRIC_INCREASES",
      "numerator_aggregation": {
        "operation": "sum",
        "datadog_metric_measure": {
          "name": "ex-14bb9543f523edde view duration",
          "source_type": "PRODUCT_ANALYTICS",
          "source_subtype": "RUM_VIEWS",
          "column_type": "double",
          "column_name": "@view.time_spent"
        }
      }
    }
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/experiments/metrics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "type": "metrics",
    "attributes": {
      "name": "ex-14bb9543f523edde",
      "data_source_type": "DATADOG",
      "desired_change": "METRIC_INCREASES",
      "numerator_aggregation": {
        "operation": "sum",
        "datadog_metric_measure": {
          "name": "ex-14bb9543f523edde view duration",
          "source_type": "PRODUCT_ANALYTICS",
          "source_subtype": "RUM_VIEWS",
          "column_type": "double",
          "column_name": "@view.time_spent"
        }
      }
    }
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/experiments/metrics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "type": "metrics",
    "attributes": {
      "name": "ex-14bb9543f523edde",
      "data_source_type": "DATADOG",
      "desired_change": "METRIC_INCREASES",
      "numerator_aggregation": {
        "operation": "sum",
        "datadog_metric_measure": {
          "name": "ex-14bb9543f523edde view duration",
          "source_type": "PRODUCT_ANALYTICS",
          "source_subtype": "RUM_VIEWS",
          "column_type": "double",
          "column_name": "@view.time_spent"
        }
      }
    }
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/experiments/metrics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "type": "metrics",
    "attributes": {
      "name": "ex-14bb9543f523edde",
      "data_source_type": "DATADOG",
      "desired_change": "METRIC_INCREASES",
      "numerator_aggregation": {
        "operation": "sum",
        "datadog_metric_measure": {
          "name": "ex-14bb9543f523edde view duration",
          "source_type": "PRODUCT_ANALYTICS",
          "source_subtype": "RUM_VIEWS",
          "column_type": "double",
          "column_name": "@view.time_spent"
        }
      }
    }
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/experiments/metrics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "type": "metrics",
    "attributes": {
      "name": "ex-14bb9543f523edde",
      "data_source_type": "DATADOG",
      "desired_change": "METRIC_INCREASES",
      "numerator_aggregation": {
        "operation": "sum",
        "datadog_metric_measure": {
          "name": "ex-14bb9543f523edde view duration",
          "source_type": "PRODUCT_ANALYTICS",
          "source_subtype": "RUM_VIEWS",
          "column_type": "double",
          "column_name": "@view.time_spent"
        }
      }
    }
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/experiments/metrics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "type": "metrics",
    "attributes": {
      "name": "ex-14bb9543f523edde",
      "data_source_type": "DATADOG",
      "desired_change": "METRIC_INCREASES",
      "numerator_aggregation": {
        "operation": "sum",
        "datadog_metric_measure": {
          "name": "ex-14bb9543f523edde view duration",
          "source_type": "PRODUCT_ANALYTICS",
          "source_subtype": "RUM_VIEWS",
          "column_type": "double",
          "column_name": "@view.time_spent"
        }
      }
    }
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/experiments/metrics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "type": "metrics",
    "attributes": {
      "name": "ex-14bb9543f523edde",
      "data_source_type": "DATADOG",
      "desired_change": "METRIC_INCREASES",
      "numerator_aggregation": {
        "operation": "sum",
        "datadog_metric_measure": {
          "name": "ex-14bb9543f523edde view duration",
          "source_type": "PRODUCT_ANALYTICS",
          "source_subtype": "RUM_VIEWS",
          "column_type": "double",
          "column_name": "@view.time_spent"
        }
      }
    }
  }
}
EOF