Overview
This guide helps send LaunchDarkly feature flag impressions as events to Mixpanel. This is useful if you want to answer questions like:- What did my users do after being exposed to an experiment?
- Did users who were exposed convert better than users who didn’t?
- Were the right set of users exposed to my experiment?
Exporting data from LaunchDarkly
In order to perform its analyses, Mixpanel needs impression events. These events tell Mixpanel which user was exposed to which variant at which time. These events must be called$experiment_started and must have the Experiment name and Variant name properties — Mixpanel recognizes these events and uses them to autopopulate the Experiments report.
- Pay to export from LaunchDarkly to Pubsub. If you go this route, you will need to write some code that pulls from PubSub and pushes to Mixpanel. We have a sample guide here. This is server-side, so will likely be more accurate, but requires more work to integrate.
- Log assignments with wrapper code (see below). This is more convenient, but can be less reliable due to the limitations of client-side tracking.
Logging assignments with wrapper code
To manually log LaunchDarkly assignments, you’ll need to find all places in your code where feature flags are being invoked and replace with a wrapper function. The example below is based on Javascript, see LaunchDarkly SDK documentation to find the syntax for your language of choice.Find all places where feature flags are being invoked
LaunchDarkly’s SDK exposes methods for retrieving whether or not a feature is enabled for the current user.Track events to Mixpanel
In order to capture assignment data, every time the feature flag is invoked, you need to log the user, timestamp, and which experiment and variant they’re seeing. To do this for all experiments, we recommend wrapping the code that checks whether a feature flag is enabled in a helper function. You can then callmixpanel.track to send an event as part of that helper function: