No results for ""
  • Home
  • API docs


Custom conversion/binary metrics

Read time: 4 minutes
Last edited: Jun 07, 2024


This topic explains how to create a custom conversion/binary 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.

Metric analysis

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

  • 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 conversion/binary metrics

Custom conversion/binary metrics require an event key from your application's code to track conversions for any event in your code. To add a custom conversion/binary 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, value);

The area of your code you should put custom conversion/binary metric information into, and the type of information you should include, varies based on which SDKs you use. Often, 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 custom conversion/binary 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 Conversion/binary.
  9. Enter a human-readable Event key. You will reference this event key in your codebase 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 conversion/binary metric event kind.
A custom conversion/binary metric event kind.
  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. For metrics you plan to use in funnel experiments, you must select "Average individual unit values."
  2. 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