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 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.
Metric keys and event keys are different
LaunchDarkly automatically generates a metric key when you create a metric. You can use the metric key to identify the metric in API calls.
Custom conversion/binary and custom numeric metrics also require an event key. You can set the event key to anything you want. Adding this event key to your codebase lets your SDK track actions customers take in your app as events. To learn more, read Sending custom events.
Get a list of all metrics for the specified project.
The filter
parameter supports the following operators: contains
.
You can only filter certain fields in metrics when using the filter
parameter. Additionally, you can only filter some fields with certain operators.
When you search for metrics, the filter
parameter supports the following fields and operators:
Field |
Description | Supported operators |
---|---|---|
tags |
The metric tags. | contains |
For example, the filter ?filter=tags contains ["tag1", "tag2", "tag3"]
matches metrics that have all three tags.
The documented values for filter
query parameters are prior to URL encoding. For example, the [
in ?filter=tags contains ["tag1", "tag2", "tag3"]
must be encoded to %5B
.
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 metricFor example, expand=experimentCount
includes the experimentCount
field for each metric in the response.
Metrics collection response
Invalid access token
Invalid resource identifier
{- "items": [
- {
- "experimentCount": 0,
- "metricGroupCount": 0,
- "_id": "5902deadbeef667524a01290",
- "_versionId": "version-id-123abc",
- "key": "metric-key-123abc",
- "name": "My metric",
- "kind": "custom",
- "_attachedFlagCount": 0,
- "_links": {
- "parent": {
- "href": "/api/v2/metrics/my-project",
- "type": "application/json"
}, - "self": {
- "href": "/api/v2/metrics/my-project/my-metric",
- "type": "application/json"
}
}, - "_site": {
- "href": "string",
- "type": "string"
}, - "_access": {
- "denied": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- null
], - "actions": [
- "*"
], - "notActions": [
- null
], - "effect": "allow",
- "role_name": "string"
}
}
], - "allowed": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- null
], - "actions": [
- "*"
], - "notActions": [
- null
], - "effect": "allow",
- "role_name": "string"
}
}
]
}, - "tags": [ ],
- "_creationDate": 0,
- "lastModified": {
- "date": "2021-08-05T19:46:31.148082Z"
}, - "maintainerId": "569fdeadbeef1644facecafe",
- "_maintainer": {
- "_links": {
- "self": {
- "href": "/api/v2/members/569f183514f4432160000007",
- "type": "application/json"
}
}, - "_id": "569f183514f4432160000007",
- "firstName": "Ariel",
- "lastName": "Flores",
- "role": "admin",
- "email": "ariel@acme.com"
}, - "description": "string",
- "isNumeric": true,
- "successCriteria": "HigherThanBaseline",
- "unit": "string",
- "eventKey": "string",
- "randomizationUnits": [
- "user"
], - "unitAggregationType": "average",
- "analysisType": "mean",
- "percentileValue": 95,
- "eventDefault": {
- "disabled": true,
- "value": 0
}
}
], - "_links": {
- "self": {
- "href": "/api/v2/metrics/my-project?limit=20",
- "type": "application/json"
}
}, - "totalCount": 0
}
Create a new metric in the specified project. The expected POST
body differs depending on the specified kind
property.
Metric response
Invalid request
Invalid access token
Forbidden
Invalid resource identifier
Status conflict
Rate limited
{- "eventKey": "trackedClick",
- "isActive": true,
- "isNumeric": false,
- "key": "metric-key-123abc",
- "kind": "custom"
}
{- "experimentCount": 0,
- "metricGroupCount": 0,
- "_id": "5902deadbeef667524a01290",
- "_versionId": "version-id-123abc",
- "key": "metric-key-123abc",
- "name": "My metric",
- "kind": "custom",
- "_attachedFlagCount": 0,
- "_links": {
- "parent": {
- "href": "/api/v2/metrics/my-project",
- "type": "application/json"
}, - "self": {
- "href": "/api/v2/metrics/my-project/my-metric",
- "type": "application/json"
}
}, - "_site": {
- "href": "string",
- "type": "string"
}, - "_access": {
- "denied": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "allow",
- "role_name": "string"
}
}
], - "allowed": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "allow",
- "role_name": "string"
}
}
]
}, - "tags": [ ],
- "_creationDate": 0,
- "lastModified": {
- "date": "2021-08-05T19:46:31.148082Z"
}, - "maintainerId": "569fdeadbeef1644facecafe",
- "_maintainer": {
- "_links": {
- "self": {
- "href": "/api/v2/members/569f183514f4432160000007",
- "type": "application/json"
}
}, - "_id": "569f183514f4432160000007",
- "firstName": "Ariel",
- "lastName": "Flores",
- "role": "admin",
- "email": "ariel@acme.com"
}, - "description": "string",
- "isNumeric": true,
- "successCriteria": "HigherThanBaseline",
- "unit": "string",
- "eventKey": "string",
- "randomizationUnits": [
- "user"
], - "unitAggregationType": "average",
- "analysisType": "mean",
- "percentileValue": 95,
- "eventDefault": {
- "disabled": true,
- "value": 0
}, - "experiments": [
- {
- "key": "experiment-key-123abc",
- "name": "Example experiment",
- "environmentId": "1234a56b7c89d012345e678f",
- "environmentKey": "production",
- "creationDate": 0,
- "archivedDate": 0,
- "_links": {
- "parent": {
- "href": "/api/v2/projects/my-project/environments/my-environment",
- "type": "application/json"
}, - "self": {
- "href": "/api/v2/projects/my-project/environments/my-environment/experiments/example-experiment",
- "type": "application/json"
}
}
}
], - "metricGroups": [
- {
- "key": "metric-group-key-123abc",
- "name": "My metric group",
- "kind": "funnel",
- "_links": {
- "parent": {
- "href": "/api/v2/projects/my-project",
- "type": "application/json"
}, - "self": {
- "href": "/api/v2/projects/my-project/metric-groups/my-metric-group",
- "type": "application/json"
}
}
}
], - "isActive": true,
- "_attachedFeatures": [
- {
- "name": "Example flag",
- "key": "flag-key-123abc",
- "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "_site": {
- "href": "string",
- "type": "string"
}
}
], - "_version": 1,
- "selector": "string",
- "urls": [
- {
- "property1": null,
- "property2": null
}
]
}
Get information for a single metric from the specific project.
LaunchDarkly supports four 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 metricexperimentCount
includes the number of experiments from the specific project that use the metricmetricGroups
includes all metric groups from the specific project that use the metricmetricGroupCount
includes the number of metric groups from the specific project that use the metricFor example, expand=experiments
includes the experiments
field in the response.
Metric response
Invalid access token
Forbidden
Invalid resource identifier
Rate limited
{- "experimentCount": 0,
- "metricGroupCount": 0,
- "_id": "5902deadbeef667524a01290",
- "_versionId": "version-id-123abc",
- "key": "metric-key-123abc",
- "name": "My metric",
- "kind": "custom",
- "_attachedFlagCount": 0,
- "_links": {
- "parent": {
- "href": "/api/v2/metrics/my-project",
- "type": "application/json"
}, - "self": {
- "href": "/api/v2/metrics/my-project/my-metric",
- "type": "application/json"
}
}, - "_site": {
- "href": "string",
- "type": "string"
}, - "_access": {
- "denied": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "allow",
- "role_name": "string"
}
}
], - "allowed": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "allow",
- "role_name": "string"
}
}
]
}, - "tags": [ ],
- "_creationDate": 0,
- "lastModified": {
- "date": "2021-08-05T19:46:31.148082Z"
}, - "maintainerId": "569fdeadbeef1644facecafe",
- "_maintainer": {
- "_links": {
- "self": {
- "href": "/api/v2/members/569f183514f4432160000007",
- "type": "application/json"
}
}, - "_id": "569f183514f4432160000007",
- "firstName": "Ariel",
- "lastName": "Flores",
- "role": "admin",
- "email": "ariel@acme.com"
}, - "description": "string",
- "isNumeric": true,
- "successCriteria": "HigherThanBaseline",
- "unit": "string",
- "eventKey": "string",
- "randomizationUnits": [
- "user"
], - "unitAggregationType": "average",
- "analysisType": "mean",
- "percentileValue": 95,
- "eventDefault": {
- "disabled": true,
- "value": 0
}, - "experiments": [
- {
- "key": "experiment-key-123abc",
- "name": "Example experiment",
- "environmentId": "1234a56b7c89d012345e678f",
- "environmentKey": "production",
- "creationDate": 0,
- "archivedDate": 0,
- "_links": {
- "parent": {
- "href": "/api/v2/projects/my-project/environments/my-environment",
- "type": "application/json"
}, - "self": {
- "href": "/api/v2/projects/my-project/environments/my-environment/experiments/example-experiment",
- "type": "application/json"
}
}
}
], - "metricGroups": [
- {
- "key": "metric-group-key-123abc",
- "name": "My metric group",
- "kind": "funnel",
- "_links": {
- "parent": {
- "href": "/api/v2/projects/my-project",
- "type": "application/json"
}, - "self": {
- "href": "/api/v2/projects/my-project/metric-groups/my-metric-group",
- "type": "application/json"
}
}
}
], - "isActive": true,
- "_attachedFeatures": [
- {
- "name": "Example flag",
- "key": "flag-key-123abc",
- "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "_site": {
- "href": "string",
- "type": "string"
}
}
], - "_version": 1,
- "selector": "string",
- "urls": [
- {
- "property1": null,
- "property2": null
}
]
}
Patch a metric by key. Updating a metric uses a JSON patch representation of the desired changes. To learn more, read Updates.
Metric response
Invalid request
Invalid access token
Invalid resource identifier
Status conflict
Rate limited
[- {
- "op": "replace",
- "path": "/name",
- "value": "my-updated-metric"
}
]
{- "experimentCount": 0,
- "metricGroupCount": 0,
- "_id": "5902deadbeef667524a01290",
- "_versionId": "version-id-123abc",
- "key": "metric-key-123abc",
- "name": "My metric",
- "kind": "custom",
- "_attachedFlagCount": 0,
- "_links": {
- "parent": {
- "href": "/api/v2/metrics/my-project",
- "type": "application/json"
}, - "self": {
- "href": "/api/v2/metrics/my-project/my-metric",
- "type": "application/json"
}
}, - "_site": {
- "href": "string",
- "type": "string"
}, - "_access": {
- "denied": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "allow",
- "role_name": "string"
}
}
], - "allowed": [
- {
- "action": "string",
- "reason": {
- "resources": [
- "proj/*:env/*;qa_*:/flag/*"
], - "notResources": [
- "string"
], - "actions": [
- "*"
], - "notActions": [
- "string"
], - "effect": "allow",
- "role_name": "string"
}
}
]
}, - "tags": [ ],
- "_creationDate": 0,
- "lastModified": {
- "date": "2021-08-05T19:46:31.148082Z"
}, - "maintainerId": "569fdeadbeef1644facecafe",
- "_maintainer": {
- "_links": {
- "self": {
- "href": "/api/v2/members/569f183514f4432160000007",
- "type": "application/json"
}
}, - "_id": "569f183514f4432160000007",
- "firstName": "Ariel",
- "lastName": "Flores",
- "role": "admin",
- "email": "ariel@acme.com"
}, - "description": "string",
- "isNumeric": true,
- "successCriteria": "HigherThanBaseline",
- "unit": "string",
- "eventKey": "string",
- "randomizationUnits": [
- "user"
], - "unitAggregationType": "average",
- "analysisType": "mean",
- "percentileValue": 95,
- "eventDefault": {
- "disabled": true,
- "value": 0
}, - "experiments": [
- {
- "key": "experiment-key-123abc",
- "name": "Example experiment",
- "environmentId": "1234a56b7c89d012345e678f",
- "environmentKey": "production",
- "creationDate": 0,
- "archivedDate": 0,
- "_links": {
- "parent": {
- "href": "/api/v2/projects/my-project/environments/my-environment",
- "type": "application/json"
}, - "self": {
- "href": "/api/v2/projects/my-project/environments/my-environment/experiments/example-experiment",
- "type": "application/json"
}
}
}
], - "metricGroups": [
- {
- "key": "metric-group-key-123abc",
- "name": "My metric group",
- "kind": "funnel",
- "_links": {
- "parent": {
- "href": "/api/v2/projects/my-project",
- "type": "application/json"
}, - "self": {
- "href": "/api/v2/projects/my-project/metric-groups/my-metric-group",
- "type": "application/json"
}
}
}
], - "isActive": true,
- "_attachedFeatures": [
- {
- "name": "Example flag",
- "key": "flag-key-123abc",
- "_links": {
- "property1": {
- "href": "string",
- "type": "string"
}, - "property2": {
- "href": "string",
- "type": "string"
}
}, - "_site": {
- "href": "string",
- "type": "string"
}
}
], - "_version": 1,
- "selector": "string",
- "urls": [
- {
- "property1": null,
- "property2": null
}
]
}
Delete a metric by key.
Action succeeded
Invalid access token
Forbidden
Invalid resource identifier
Rate limited
{- "code": "unauthorized",
- "message": "Invalid access token"
}