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

Custom numeric metrics

Read time: 5 minutes
Last edited: Nov 13, 2024

Overview

This topic explains how to create a custom numeric metric in LaunchDarkly. Custom numeric metrics track changes to the amount of something, such as dollars spent or latency time. Unlike conversion metrics, which track how many users triggered an event or the number of times an event occurs, 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 number of items in a shopping cart at checkout
  • How long it takes for a server to respond to a request
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.

Metric definition

When you create a custom numeric metric, you must first decide:

  • What do you want to measure: select Value/size.
  • how multiple event values are aggregated per unit:
    • Sum: the total value per unit. For example, this option adds together the total purchase amount of all of a customer's purchases.
    • Average: the average value per unit. For example, this option takes the average purchase price of all of a customer's purchases.

Then, custom numeric metric definition options include:

  • Analysis method:
    • Average: "average" is the default analysis method. For metrics you plan to use in funnel experiments, you must select "Average."
    • Percentile: you can choose between P50-P99, which represent the 50th through the 99th percentile.
  • Randomization unit: one or more context kinds, such as "user," "device," or "request," that the metric can measure events from.
  • Success criteria:
    • Higher is better: choose this option for metrics measuring positive things like cart checkouts or sign-ups.
    • Lower is better: choose this option for metrics measuring negative things like errors.
  • Units without events:
    • Exclude units that did not send any events from the analysis: this option is best for latency metrics. If LaunchDarkly never receives an event for a context instance, you do not want to default to 0 because LaunchDarkly would interpret this as an extremely fast latency time, which would skew or invalidate the results.
    • Include units that did not send any events and set their value to 0: this option is best for metrics where an incomplete process can be treated the same as 0, such as tracking cart totals for an online store. In this example, customers who put items in their cart but never completed the checkout process are treated as if they purchased $0.
  • Unit of measure: the label for what the metric is measuring, such as dollars or milliseconds.

To learn more about the metric definition options, read Metric analysis.

You cannot use custom numeric metrics in funnel metric groups. To learn more, read Funnel metric groups.

Create custom numeric metrics

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

This is an example of sending 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 and managing metrics.

Sending custom events to LaunchDarkly also requires 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 custom numeric metric:

  1. Navigate to the Metrics list.
  2. Click Create metric. The "Create metric" dialog appears.
  3. Select an event kind of Custom.
  4. Search for or enter an Event key.
  • A list of events your environment has recently received appears when you click into the Event key field. Begin typing an event key to view a list of events that match your search.
  1. Choose Value/size as what you want to measure.
A custom numeric metric.
A custom numeric metric.
  1. Choose how multiple event values are aggregated per unit:
  • Sum: the total value per unit.
  • Average: the average value per unit.
  1. In the Metric definition section, select the following:
  • Average or a specific percentile click rate.
  • of the per [randomization unit] event: select the context kind for the metric to measure events from.
  • where higher is better or lower is better: select whether the desired outcome is a higher number or a lower number.
  1. Enter a Unit of measure.
  2. Enter a metric Name.
  3. (Optional) Add a Description.
  4. (Optional) Add any Tags.
  5. (Optional) Update the Maintainer.
  6. 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 Guarded rollouts.

You can also use the REST API: Create metric