LaunchDarkly

Use LaunchDarkly alongside Sprig in order to compare & segment results based on the user’s flag variations.

LaunchDarkly enables product and engineering teams to collaborate more effectively on releases by giving everyone the visibility that they need. By integrating LaunchDarkly with Sprig, you will be able to accomplish the following:

  1. Target users based on the LaunchDarkly flag name and variation number.
  2. Run cross-tab analysis based on the LaunchDarkly flag name and variation number.

Supported Plans:

See the table below to see if your plan includes the LaunchDarkly integration. If you would like to upgrade, please reach out to your Sprig representative, or email Sprig Customer Success at [email protected] for assistance.

PlanAvailability
Free:x:
Starter:x:
Enterprise (Concept Test):x:
Enterprise (IPS):white-check-mark:
Enterprise (Full):white-check-mark:

LaunchDarkly SDK Version:

You will need to have a minimum version of 2.24.0 for their Javascript SDK.

Sprig Supported SDKs:

Please reference the table below to determine the availability and minimum Sprig SDK version your team will need to adopt in order to integrate LaunchDarkly.

PlatformSupportedMin. SDK Version
Web:white-check-mark:2.23.0
Native iOS:x:N/A
Native Android:x:N/A
React Native:x:N/A

How to Implement:

Enabling on your Sprig product

The first step in enabling LaunchDarkly for your product is to turn the config on in the Integrations page. See below for steps:

Step 1: Head over to Integrations
Step 2: Search for LaunchDarkly and click on the LaunchDarkly card
Step 3: In the How to Connect section, toggle LaunchDarkly on

Once you have toggle the configuration on, you will be able to send LaunchDarkly flag and variations to Sprig and use LaunchDarkly as a runtime filter.

Web

In order for the Sprig SDK to read your LaunchDarkly, there is some engineering dev work required in order to properly import LaunchDarkly flags and variation for the user over to Sprig in order to target the user appropriately.

The main additional change adding an inspector during the LaunchDarkly initialization. You can add to your existing inspector, or create a new inspectors config for your LaunchDarkly client.

inspectors: [
  {
    type: 'flag-details-changed',
    name: 'my-flag-details-inspector',
    method: (details) => {
      // When flags have changed, use logic below to map flag to variation
      // Mapped object should use flag slug paired with the variation index
      const mappedLDFlags = Object.keys(details).reduce((agg, flag) => {
        agg[flag] = details[flag].variationIndex;
        return agg;
      }, {});

      // Then import the mapped data to Sprig below
      Sprig('importLaunchDarklyData', mappedLDFlags);
    },
  },
]

To see the whole example app implementation, see below for a full code sample of how it will look like during initialization.

import { sprig } from '@sprig-technologies/sprig-browser';
import * as LDClient from 'launchdarkly-js-client-sdk';

// Configuring Sprig
const Sprig = sprig.configure({
	environmentId: 'ENVIRONMENT_ID',
});

// Initializing LaunchDarkly
// Attach inspect during flag detail change
const ldClient = LDClient.initialize(clientSideID, context, {
  inspectors: [
    {
      type: 'flag-details-changed',
      name: 'my-flag-details-inspector',
      method: (details) => {
        // When flags have changed, use logic below to map flag to variation
        const mappedLDFlags = Object.keys(details).reduce((agg, flag) => {
          agg[flag] = details[flag].variationIndex;
          return agg;
        }, {});
				
        // Then import the mapped data to Sprig below
        Sprig('importLaunchDarklyData', mappedLDFlags);
      },
    },
  ],
});

How to Use:

Once you have successfully turned LaunchDarkly on in your product and your development team has inserted the necessary code snippet in your application, you are now ready to launch your first LaunchDarkly targeting survey!

Step 1: Create a new study OR edit an existing one
Step 2: Fill out the question form and move on to the audience form
Step 3: In the audience form, select a trigger for “When to Send”
Step 4: Select your LaunchDarkly Experiment attribute
Step 5: Copy and paste the corresponding experimentId from LaunchDarkly to Sprig
Step 6: Copy and paste the corresponding value for the variation and pick a comparison operator

Please refer to our guide on how to launch a study for any questions on the survey builder.

FAQs

Question: Can I target multiple flags/variations with a single study?
Answer: Yes! You can use the AND/OR targeting to support multiple flags/variations.

Question: Does this work for mobile platforms?
Answer: At this time, only the web implementation is available due to a gap in the LaunchDarkly and Sprig implementation for mobile. Please reach out to your Sprig representative, or email Sprig Customer Success at [email protected], for a feature request if this is something that interests your team.

Question: How do I export the flag name and variation number from Sprig?
Answer: On your Summary page, navigate to responses and select the CSV download option. You should be able to see each respondent, including all qualifying experiments/variations