Metrics

Available for Pro and Enterprise plans

Metrics are necessary components of experiments. Experimentation is available to customers on a Pro or Enterprise plan. To learn more, read about our pricing. To add Experimentation to your plan, contact Sales.

Metrics track flag behavior over time when an experiment is running. The data generated from experiments gives you more insight into the impact of a particular flag. To learn more, read Creating metrics.

Using the metrics API, you can create, delete, and manage metrics.

Are you importing metric events?

If you want to import metric events into LaunchDarkly from an existing data source, use the metric import API. To learn more, read Importing metric events.

List metrics

Get a list of all metrics for the specified project.

Expanding the metric list response

LaunchDarkly supports expanding the "List metrics" response. By default, the expandable field is not included in the response.

To expand the response, append the expand query parameter and add the following supported field:

  • experimentCount includes the number of experiments from the specific project that use the metric

For example, expand=experimentCount includes the experimentCount field for each metric in the response.

Request
path Parameters
projectKey
required
string <string>

The project key

query Parameters
expand
string <string>

A comma-separated list of properties that can reveal additional information in the response.

Responses
200

Metrics collection response

401

Invalid access token

404

Invalid resource identifier

get/api/v2/metrics/{projectKey}
Request samples
Response samples
application/json
{
  • "items": [
    ],
  • "_links": {
    }
}

Create metric

Create a new metric in the specified project. The expected POST body differs depending on the specified kind property.

Request
path Parameters
projectKey
required
string <string>

The project key

Request Body schema: application/json
key
required
string

A unique key to reference the metric

name
string

A human-friendly name for the metric

description
string

Description of the metric

kind
required
string

The kind of event your metric will track

Enum: "pageview" "click" "custom"
selector
string

One or more CSS selectors. Required for click metrics only.

Array of objects (UrlPost)

One or more target URLs. Required for click and pageview metrics only.

isActive
boolean

Whether the metric is active. Set to true to record click or pageview metrics. Not applicable for custom metrics.

isNumeric
boolean

Whether to track numeric changes in value against a baseline (true) or to track a conversion when an end user takes an action (false). Required for custom metrics only.

unit
string

The unit of measure. Applicable for numeric custom metrics only.

eventKey
string

The event name to use in your code. Required for custom metrics only.

successCriteria
string

Success criteria. Required for custom numeric metrics, optional for custom conversion metrics.

Enum: "HigherThanBaseline" "LowerThanBaseline"
tags
Array of strings

Tags for the metric

randomizationUnits
Array of strings

An array of randomization units allowed for this metric

Responses
201

Metric response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

409

Status conflict

429

Rate limited

post/api/v2/metrics/{projectKey}
Request samples
application/json
{
  • "eventKey": "trackedClick",
  • "isActive": true,
  • "isNumeric": false,
  • "key": "metric-key-123abc",
  • "kind": "custom"
}
Response samples
application/json
{
  • "experimentCount": 0,
  • "_id": "5902deadbeef667524a01290",
  • "key": "metric-key-123abc",
  • "name": "My metric",
  • "kind": "custom",
  • "_attachedFlagCount": 0,
  • "_links": {
    },
  • "_site": {
    },
  • "_access": {
    },
  • "tags": [ ],
  • "_creationDate": 0,
  • "lastModified": {
    },
  • "maintainerId": "569fdeadbeef1644facecafe",
  • "_maintainer": {
    },
  • "description": "string",
  • "isNumeric": true,
  • "successCriteria": "HigherThanBaseline",
  • "unit": "string",
  • "eventKey": "string",
  • "randomizationUnits": [
    ],
  • "experiments": [
    ],
  • "isActive": true,
  • "_attachedFeatures": [
    ],
  • "_version": 1,
  • "selector": "string",
  • "urls": [
    ]
}

Get metric

Get information for a single metric from the specific project.

Expanding the metric response

LaunchDarkly supports two fields for expanding the "Get metric" response. By default, these fields are not included in the response.

To expand the response, append the expand query parameter and add a comma-separated list with any of the following fields:

  • experiments includes all experiments from the specific project that use the metric
  • experimentCount includes the number of experiments from the specific project that use the metric

For example, expand=experiments includes the experiments field in the response.

Request
path Parameters
projectKey
required
string <string>

The project key

metricKey
required
string <string>

The metric key

query Parameters
expand
string <string>

A comma-separated list of properties that can reveal additional information in the response.

Responses
200

Metric response

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/metrics/{projectKey}/{metricKey}
Request samples
Response samples
application/json
{
  • "experimentCount": 0,
  • "_id": "5902deadbeef667524a01290",
  • "key": "metric-key-123abc",
  • "name": "My metric",
  • "kind": "custom",
  • "_attachedFlagCount": 0,
  • "_links": {
    },
  • "_site": {
    },
  • "_access": {
    },
  • "tags": [ ],
  • "_creationDate": 0,
  • "lastModified": {
    },
  • "maintainerId": "569fdeadbeef1644facecafe",
  • "_maintainer": {
    },
  • "description": "string",
  • "isNumeric": true,
  • "successCriteria": "HigherThanBaseline",
  • "unit": "string",
  • "eventKey": "string",
  • "randomizationUnits": [
    ],
  • "experiments": [
    ],
  • "isActive": true,
  • "_attachedFeatures": [
    ],
  • "_version": 1,
  • "selector": "string",
  • "urls": [
    ]
}

Update metric

Patch a metric by key.

Request
path Parameters
projectKey
required
string <string>

The project key

metricKey
required
string <string>

The metric key

Request Body schema: application/json
Array
op
required
string

The type of operation to perform

path
required
string

A JSON Pointer string specifying the part of the document to operate on

value
required
any

A JSON value used in "add", "replace", and "test" operations

Responses
200

Metric response

400

Invalid request

401

Invalid access token

404

Invalid resource identifier

409

Status conflict

429

Rate limited

patch/api/v2/metrics/{projectKey}/{metricKey}
Request samples
application/json
[
  • {
    }
]
Response samples
application/json
{
  • "experimentCount": 0,
  • "_id": "5902deadbeef667524a01290",
  • "key": "metric-key-123abc",
  • "name": "My metric",
  • "kind": "custom",
  • "_attachedFlagCount": 0,
  • "_links": {
    },
  • "_site": {
    },
  • "_access": {
    },
  • "tags": [ ],
  • "_creationDate": 0,
  • "lastModified": {
    },
  • "maintainerId": "569fdeadbeef1644facecafe",
  • "_maintainer": {
    },
  • "description": "string",
  • "isNumeric": true,
  • "successCriteria": "HigherThanBaseline",
  • "unit": "string",
  • "eventKey": "string",
  • "randomizationUnits": [
    ],
  • "experiments": [
    ],
  • "isActive": true,
  • "_attachedFeatures": [
    ],
  • "_version": 1,
  • "selector": "string",
  • "urls": [
    ]
}

Delete metric

Delete a metric by key.

Request
path Parameters
projectKey
required
string <string>

The project key

metricKey
required
string <string>

The metric key

Responses
204

Action succeeded

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

delete/api/v2/metrics/{projectKey}/{metricKey}
Request samples
Response samples
application/json
{
  • "code": "unauthorized",
  • "message": "Invalid access token"
}