Metrics

Experimentation is an add-on feature

Metrics are necessary components of experiments. Experimentation is available as an add-on for customers on an Enterprise plan. To learn more, read about our pricing. To upgrade 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.

List metrics

Get a list of all metrics for the specified project.

Request
path Parameters
projectKey
required
string <string>

The project key

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.

Array of objects (UrlPost)

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

isActive
boolean

Whether the metric is active

isNumeric
boolean

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

unit
string

The unit of measure. Only for numeric custom metrics.

eventKey
string

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

successCriteria
string

Success criteria. Required for numeric custom metrics.

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

Tags for the 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": "my-metric",
  • "kind": "custom"
}
Response samples
application/json
{
  • "experimentCount": 0,
  • "_id": "5902deadbeef667524a01290",
  • "key": "my-metric",
  • "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",
  • "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. Supported fields are explained above.

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": "my-metric",
  • "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",
  • "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": "my-metric",
  • "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",
  • "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"
}