Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Next.js example demonstrating LaunchDarkly feature flags with the Flags SDK, including experimentation and the Flags Explorer.
LaunchDarkly Flags SDK Example is a Vercel-deployable Next.js boilerplate that demonstrates how to connect LaunchDarkly feature flags and experiments to the Flags SDK and the Flags Explorer.
This is a Next.js example from the vercel/examples collection (5146 stars) that wires LaunchDarkly as the provider for the open-source Flags SDK using the @flags-sdk/launchdarkly adapter (v1.0.0+). It takes LaunchDarkly boolean and string flags, evaluates them on a single demo page, and conditionally renders two banners plus a checkout button color. A live demo runs at https://flags-sdk-launchdarkly.vercel.app/.
@flags-sdk/launchdarkly, which reads the EXPERIMENTATION_CONFIG Edge Config connection string automatically when the Vercel Marketplace integration has Edge Config Syncing enabled.LAUNCHDARKLY_API_KEY, LAUNCHDARKLY_PROJECT_KEY, and LAUNCHDARKLY_ENVIRONMENT variables it also fetches flag descriptions and links back to the LaunchDarkly Console.summer-sale and free-delivery booleans served with a 50/50 split by user.key, plus a proceed-to-checkout-color string flag with blue, green, and red variations.proceed-to-checkout-clicked custom conversion event, user randomization unit, and a 100% audience split.FLAGS_SECRET environment variable, and installs the LaunchDarkly integration from the Vercel Marketplace..env.example lists FLAGS_SECRET (32 random bytes, base64-encoded), LAUNCHDARKLY_PROJECT_SLUG, LAUNCHDARKLY_CLIENT_SIDE_ID, and NEXT_PUBLIC_LAUNCHDARKLY_CLIENT_SIDE_ID, plus the optional API variables.vercel link and vercel env pull.The page evaluates the summer-sale and free-delivery boolean flags through the Flags SDK and conditionally shows or hides two banners based on the results. A stable per-user id determines which 50% bucket each visitor lands in, and the Dev Tools reset that id to re-bucket on the next reload. For experimentation, the proceed-to-checkout-color flag controls a button color while the app tracks the proceed-to-checkout-clicked custom event as the conversion metric.
Yes — you create the feature flags and the experiment in the LaunchDarkly Console, and the Vercel Marketplace integration connects LaunchDarkly to your deployment through Edge Config syncing.
The required variables are FLAGS_SECRET (32 random bytes, base64-encoded), EXPERIMENTATION_CONFIG (the Edge Config connection string exposed by the LaunchDarkly integration), LAUNCHDARKLY_PROJECT_SLUG, and both LAUNCHDARKLY_CLIENT_SIDE_ID and NEXT_PUBLIC_LAUNCHDARKLY_CLIENT_SIDE_ID.
Yes — set the optional LAUNCHDARKLY_API_KEY, LAUNCHDARKLY_PROJECT_KEY, and LAUNCHDARKLY_ENVIRONMENT variables, and the Flags Explorer will display flag descriptions and a link to each flag in the LaunchDarkly Console.
Yes — the demo's Dev Tools reset the stable user id, and because flags are served with a 50/50 rollout by user.key, reloading after a reset can produce a different banner combination.
