• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
    No results for ""


    Custom numeric metrics

    Read time: 2 minutes
    Last edited: Mar 01, 2023


    This topic explains how to create a custom numeric metric for an experiment 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 browser redirected the end user 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.

    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

    Creating 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 name", context, null, numericValue);
    /* The `context` parameter is omitted in client-side SDKs */

    Like conversion metrics, numeric metrics also require you to create an event name and insert it into your application's code to track metric data. The area of your code you should put custom conversion metric information into, and the type of information you should include, varies 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. To learn more, read Sending custom events.

    Can't access numeric metrics options?

    If the feature described below is not available in your "Create a new metric" panel, your SDKs may be out of date. To solve this problem, update your SDKs to the latest version, and contact Support to enable numeric metrics.

    To create a numeric metric:

    1. Follow steps 1-7 in Creating click conversion metrics until you have configured the metric up to the "Event information" section.
    2. Click the Event kind menu and select "Custom."
    3. Select the Numeric radio button.
    4. Enter a human-readable Event name. This is the event name you will reference in your code snippet when you insert the metric information into your app.
    5. Enter a Unit of measure to track.
    6. Choose a Success criteria from the menu.
    7. Choose one or more context kinds available for experiments 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. Click Save metric:
    The "Event information" section of the "Create a new metric" panel with a numeric metric configured.
    The "Event information" section of the "Create a new metric" panel with a numeric metric configured.
    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 might want a success criteria that is lower than the baseline if your baseline flag variation shows the original page load time and you want to measure decreases in page load time.

    After you create a metric, you can connect it to an experiment. To learn how, read Building experiments.

    You can also use the REST API: Create metric