No results for ""
EXPAND ALL
  • Home
  • API docs

GIVE DOCS FEEDBACK

Custom numeric metrics

Read time: 5 minutes
Last edited: May 20, 2024

Overview

This topic explains how to create a custom numeric metric in LaunchDarkly.

Call track and flush when an end user is redirected

SDKs send events at regular intervals, such as every five seconds. If a browser redirects an end user to another page, any events that occurred between when the SDK last sent events and when the browser redirected will be lost. To avoid this, call track and then flush when you know the browser will redirect an end user to another page, such as on click. To learn more, read Sending custom events and Flushing events.

You can use numeric metrics to track the changes in a value against a baseline value. Unlike conversion metrics, which track whether or not an event occurred, numeric metrics let you measure changes in value against a baseline flag variation you choose.

For example, you can use numeric metrics to track:

  • Page load time
  • The efficacy of various search algorithms
  • The number of items in a shopping cart at checkout
Choosing success criteria for numeric metrics

When you designate a success criteria, you can choose Lower than baseline or Higher than baseline depending on what you want to track. For example, if you're trying to track page load time to measure the impact of your infrastructure changes, you will want success criteria to be lower than the baseline.

Metric analysis

When you create a metric you must decide how you want to handle its metric analysis:

  • Units without events: For metrics related to latency, you should choose "Excluding units without events from the analysis." To learn more, read Units without events.
  • Unit aggregation method: Select either Sum individual unit values or Average individual unit values, depending on what the metric is measuring. For metrics you plan to use in funnel experiments, you must select Average individual unit values. To learn more, read Unit aggregation method.

Create custom numeric metrics

To add a custom numeric metric in LaunchDarkly, you must identify it with a code snippet embedded in your app.

To add a custom event:

client.track("Example event key", context, null, numericValue);
/* The `context` parameter is omitted in client-side SDKs */

Numeric metrics require an event key from your application's code to track metric data. The area of your code you should put custom metric information into, and the type of information you should include, vary based on which SDKs you use.

Usually, the information you should put in your code includes the event key, context object, data field, or numeric value fields.

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. To learn more, read Creating metrics.

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.

Try it in your SDK: Sending custom events

To create a numeric metric:

  1. Navigate to the Metrics list.
  2. Click Create metric. The "Create metric" dialog appears.
  3. Enter a human-readable Name for the metric.
  4. (Optional) Enter a Description.
  5. (Optional) Type or choose from available Tags.
  6. (Optional) Choose a Maintainer. By default, the person who creates the metric is set as the Maintainer.
  7. In the "Event information" section select Custom.
  8. Select Numeric.
  9. Enter a human-readable Event key. This is the event key you will reference in your code snippet when you insert the metric information into your app.
    • A list of environments displays showing which environments have received events from your SDKs with the key you entered. If no environments are receiving events with the key you entered, check that your SDKs are configured correctly.
A custom numeric metric event kind.
A custom numeric metric event kind.
  1. Enter a Unit of measure to track.
  2. Choose a Success criteria from the menu.
  1. Choose one or more randomization units for the metric to measure events from.
Metrics must use valid randomization units

Using invalid randomization units will result in invalid experiment results. To learn more, read Randomization units. If you're unsure of which randomization unit to use, contact Support for help determining valid context kind selections.

  1. Choose a Unit aggregation method.
  2. Select how you want LaunchDarkly to handle Units without events.
  3. Click Create metric.

After you create a metric, you can connect it to an experiment or use it to monitor the performance of flag changes. To learn how, read Creating experiments and Release Guardian.

You can also use the REST API: Create metric