LaunchDarkly integration
LaunchDarkly enables teams to release, monitor, and optimize software in production using feature flags, context-aware targeting, and experimentation.
The LaunchDarkly integration for Netlify enables you to use LaunchDarkly feature flags and segments with your sites on Netlify. Using Netlify Functions and Netlify Blobs, the integration ensures that changes you make on LaunchDarkly are instantly available for your site on Netlify.
# How it works
The integration between Netlify and LaunchDarkly relies on three pieces:
the LaunchDarkly integration that you install on your team and enable on your site in Netlify. After you enable the LaunchDarkly integration, it automatically injects functions into your site during the build step that will handle data updates from LaunchDarkly. The main function is the
official-launchdarkly_edge-config
function.The first time the
official-launchdarkly_edge-config
function runs, it creates a blob store for your site calledintegration-launchdarkly
. All subsequent invocations update that blob store.the Netlify integration that you install and configure for your organization in LaunchDarkly. When you make changes in LaunchDarkly, the Netlify integration sends the data to the
/.official-integration-launchdarkly/edge-config
endpoint on your site to trigger the function and update theintegration-launchdarkly
blob store.the Netlify LaunchDarkly SDK that you install and configure in your site code to access the
integration-launchdarkly
blob store. Through the client, your site will have instant access to the latest data from LaunchDarkly.
# Before you begin
To use the Netlify LaunchDarkly integration, make sure you have the following:
- an Enterprise account on LaunchDarkly
- a deployed site on Netlify
# Get started
To use the LaunchDarkly integration, you need to take the following actions across three places:
- In Netlify: install the LaunchDarkly integration and enable it on your site
- In LaunchDarkly: add and configure the Netlify integration
- In your code: install and configure the Netlify LaunchDarkly SDK
# 1. Install and enable the LaunchDarkly integration
The first step is to install the LaunchDarkly integration on your team in Netlify, enable it on your site, and then redeploy the site.
- As a Team Owner, navigate to the page for your team in the Netlify UI.
- Search for
LaunchDarkly
and select it in the search results. - On the details page, select Install.
- From your team’s Sites list, select the site you plan to use with LaunchDarkly, and navigate to .
- Select Enable.
- Select Redeploy now to rebuild and redeploy your site.
During the build step, the integration will inject the functions that will create and update a blob store with your LaunchDarkly data. The functions will appear in your function logs with the prefix official-launchdarkly
.
After the deploy is complete, the
configuration section will update to include a Syncing token. You will need this token and your Site ID for the next step.# 2. Add and configure the Netlify integration
The second step is to install the Netlify integration in LaunchDarkly.
In LaunchDarkly, navigate to the Integrations page for your organization and search for
Netlify
.Select Add integration.
In the Create Netlify configuration panel, select an Environment, and enter the Site ID and Syncing token from the Netlify UI.
You can find the ID and token listed in the
section in the Netlify UI.Review and confirm the terms and conditions, and then select Save configuration.
After you save the configuration, the integration will make a call to the https://<YOUR SITE DOMAIN>/.official-integration-launchdarkly/edge-config
endpoint on your site to trigger the related function. On the initial call, the function will create a blob store for your site called integration-launchdarkly
to store your LaunchDarkly data. Subsequent calls will update the blob store with the latest data from LaunchDarkly.
The final step is to install and configure the Netlify LaunchDarkly SDK in your site.
# 3. Install and configure the Netlify LaunchDarkly SDK
The last step is to install the Netlify LaunchDarkly SDK in your project and create a client that you can use to access LaunchDarkly data from the blob store.
Install the Netlify LaunchDarkly SDK:
npm i @netlify/launchdarkly-server-sdk
yarn add @netlify/launchdarkly-server-sdk
Add code to initialize the
ldClient
with your LaunchDarkly client-side ID and then use the client to access your LaunchDarkly feature flags.This example initializes the client and then gets the value for the
enableMyNewFeature
flag:import { init as initLD } from "@netlify/launchdarkly-server-sdk"; export default { async fetch(request: Request, env: Bindings): Promise<Response> { const clientSideID = "my-client-side-id"; const flagKey = "enableMyNewFeature"; const context = { kind: "user", key: "my-user-key-1" }; const client = initLD(clientSideID); await client.waitForInitialization(); const flagValue = await client.variation(flagKey, context, false); return new Response(`${flagKey}: ${flagValue}`); } };
# Disable the integration
To disable the LaunchDarkly integration on a site:
- In the Netlify UI, navigate to .
- Under Danger zone, select Disable.
Alternatively, you can uninstall the integration from your team and remove it from all sites in one step.
Did you find this doc useful?
Your feedback helps us improve our docs.