Affected: All SDKs
Overview
If you run experiments in LaunchDarkly, you can register custom conversion metric events to track contextual behavior and make data-driven decisions. By registering metric events, you can analyze the performance of different variations of your feature flag and optimize it accordingly.
Solution
To register events for metrics in experiments, you need two components: an Evaluation event, also known as a feature event, and a Metric event, also known as a custom event. For more information, refer to the documentation of Experimentation events.
The Evaluation event is usually generated by a variation call associated with the feature flag used in the experiment. On the other hand, the Metric event is generally generated by a track call and connected to the experiment.
variation()
or variationDetail()
methods. If you are using the React Web SDK, useFlags()
hook is also sufficient. If you want to learn more about these methods, read Evaluating flags and Flag evaluation reasons.
track()
call. If you want to learn more about how to track, please read Sending custom events. If you are using an Experimentation/metric integration such as Segment, follow the steps in Experimentation and metric integrations for your integration to set up metric tracking.flush()
method to send events immediately without waiting for the next interval. The flush()
call is an optional step that may or may not be required, depending on your application. If you'd like to learn more about the flush call, read Flushing events.Steps
- Setup an experiment with a feature flag.
-
Evaluate the feature flag (for example:
flag-experiment
) using one of the methods mentioned above. -
Connect a metric (for example:
metric-ab-test
) to the experiment with an event name. -
Track the metric using the event name. For example,
track('metric-ab-test')
. -
[Optional]
flush()
call at the end.