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


    Custom conversion metrics

    Read time: 1 minute
    Last edited: Mar 01, 2023


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

    Creating custom conversion metrics

    Custom conversion metrics require you to create an event name and insert it into your application to track conversions for any event in your code. To add a custom conversion 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, value);

    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.

    Often, the information you should put in your code includes the event key, context object, data field, or numeric value fields. To learn more, read the Sending custom events documentation for your SDKs.

    To create a custom conversion metric:

    1. Follow steps 1-7 in Creating click conversion metrics until you have configured the form up to the "Event information" section.
    2. Click the Event kind menu and select "Custom":
    A custom metric event kind.
    A custom metric event kind.
    1. Select the Conversion radio button.
    2. 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.
    3. 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 conversion metric configured.
    The "Event information" section of the "Create a new metric" panel with a conversion metric configured.

    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