Creating and managing metrics
Overview
This topic explains how to create, edit, and delete metrics, and how to select which metric type to use with LaunchDarkly features, such as experiments and guarded rollouts.
When you create a metric, LaunchDarkly provides a data preview after you select an event key. Data previews give you immediate visibility into the events behind your metric so you can confirm that the right data is flowing, that filters are applied correctly, and that your aggregation method produces meaningful results. This reduces risk during metric creation and helps your team configure metrics you can trust more quickly, so you can begin experiments and rollouts with confidence.
Choose a metric type
You should choose a metric type that correctly measures the effect of a change on your customers or codebase. If you are unsure of what metric type to use, it may be helpful to begin by determining what kind of data you are trying to measure. For examples of common metrics and how to configure them, read Example metrics.
This table includes examples of different kinds of data you can measure with different metric types, and common randomization unit context kind mappings:
When you create a metric, you must decide how you want to handle its metric and unit analysis. To learn more, read Metric analysis.
Create metrics
Click on the following links to learn how to create each metric type:
- Clicked or tapped conversion metrics
- Custom conversion binary metrics
- Custom conversion count metrics
- Custom numeric metrics
- Page viewed conversion metrics
Preview event data
Metric data previews let you validate your metric configuration by showing recent event samples as you create or edit a custom metric. This section explains where previews are available, what they contain, the states you may encounter, and provides an example.
Availability
Previews are available in two places:
- In the Create metric dialog for custom metrics.
- In the Metric details tab for custom metrics, if LaunchDarkly has received recent event data.
Previews are not available for clicked or tapped metrics, or for page viewed metrics.
When there is no event data:
- In the Create metric dialog, the preview displays “No event data available to preview” and includes a Learn more link.
- In the Metric details tab, the preview component does not appear.
Preview contents
Previews display a table with up to five of the most recent events LaunchDarkly received for the selected Event key. Each row displays:
- Timestamp: When the event occurred
- Context kinds: Such as user or organization keys
- Event properties: The event JSON, truncated in the table. You can click the truncated version or expand the row to view the full JSON and copy it.
Preview states
The data preview can display different states depending on the event data available:
- Recent events shown: Displays rows from the five most recent records.
- No recent events: Displays “No event data available to preview.” You can still create the metric.
- Unable to load data: Displays an error message if LaunchDarkly cannot retrieve data.
Example
Consider a custom numeric metric that measures purchase amount:
- In the Event key field, select
purchaseCompleted
. - The preview displays the five most recent purchase events, including “Timestamp,” “Context kinds,” and “Event properties.”
- Expand a row to view the full event details and copy them if needed.
- The health check confirms that the event has been received recently and that all randomization units have events in the last 14 days.
This confirms that your instrumentation is correct and that your metric definition matches your measurement goals, so you can connect it to an experiment or rollout with confidence.
About event data previews
Data previews use the same event data source as the Event explorer. For a complete view of event history and payloads, use the event explorer.
Edit metrics
You can edit all of an existing metric’s settings except for its metric kind and metric key.
To edit a metric:
- Navigate to the Metrics list.
- Click the title of the metric you want to edit. The metric details screen opens.
- Click the pencil icon in the right sidebar next to the field you want to edit. The “Edit metric” dialog appears.
- Make the edits you want and click Save metric.
You can also use the REST API: Update metric
Filter metrics
After you create a metric, you can optionally configure metric event filters to control which events are included in its analysis. This lets you focus the metric on specific context attributes or event properties, such as events where the variationKey
is treatment
or the country
context attribute is CA
.
To learn more, read Filtering custom metric events.
Delete metrics
You should delete a metric only when you are sure you will no longer use it.
To delete a metric:
- Navigate to the Metrics list.
- Click the title of the metric you want to delete. The metric details screen opens.
- Click Delete metric. A “Delete metric” dialog appears.
- Click Delete metric.
This metric is now deleted permanently across all environments in the project.
You can also use the REST API: Delete metric