LaunchDarkly Flags SDK Example

R
Renaudil y a 2 jours
0

Description

Learn how to set up LaunchDarkly, including experimentation alongside Flags SDK and Edge Config.

npx boilerapp launchdarkly-flags-sdk

文档

LaunchDarkly Flags SDK Example

This example uses LaunchDarkly for feature flags with the Flags SDK along with the @flags-sdk/launchdarkly LaunchDarkly adapter and the Flags Explorer.

How it works

This demo uses two feature flags on LaunchDarkly to control the visibility of two banners on the page. Both flags are configured to show/hide each banner 50% of the time.

Once you visit the page, you can see a variation of both/one/none of the banners. Since this example is using a stable id to identify users, you will see the same variation until you reset your id.

To test different variations, you can use the Dev Tools at the bottom to reset the stable id and reload the page. This allows you to test different variations of the banners.

If you deployed your own and configured the feature flags on LaunchDarkly, you can also use the Flags Explorer to test different variations by creating overrides.

Deploy this template

The easiest way to get started with LaunchDarkly is through the integration in Vercel Marketplace.

Deploy with Vercel

Step 1: Link the project

In order to use the Flags Explorer, you need to link the project on your local machine.

vercel link

Select the project from the list you just deployed.

Step 2: Pull all environment variables

This allows the Flags SDK and the Flags Explorer to work correctly, by getting additional metadata.

vercel env pull

Step 3: Create Feature Flags

Head over to the LaunchDarkly Console and create the feature flags and experiments required by this template.

Be sure to enable the SDKs using Client-side ID option for each Feature Flag.

Feature Flags:

  • Summer Sale (type boolean) with the key summer-sale and the variations true and false. Edit the default targeting rule to serve a percentage rollout with a 50/50 split by user.key.
  • Free Delivery (type boolean) with the key free-delivery and the variations true and false. Edit the default targeting rule to serve a percentage rollout with a 50/50 split by user.key.
  • Proceed to Checkout (type string) with the key proceed-to-checkout and the following variations:
    • Name: Control, Value: blue
    • Name: Test, Value: green
    • Name: Test #2, Value: red

You can also find the flag keys in the flags.ts file.

Ensure all Flags are ON.

Step 4: Configure the Experiment

Create the Proceed to Checkout experiment:

  • Name: Proceed to Checkout
  • Hypothesis: Button color influences rate at which customers proceed to checkout
  • Type: Feature change
  • Randomization Unit: user
  • Randomization Attribute: key
  • Metric: Create a new metric:
    • Event kind: Custom
    • Event key: proceed-to-checkout-clicked
    • What do you want to measure? Occurence (conversion: binary)
    • Metric definition: Percentage of user units that sent the event, where higher is better
    • Metric name: Proceed to Checkout Clicked
  • Varaiations: Choose flag proceed-to-checkout
  • Audience:
    • In this experiment: Choose Custom and enter 100%
    • Split audience: Choose Split equally
  • Statistical approach: Default values

After that, start the Experiment.

Step 6: Set environment variables

See .env.example for a template.

  • FLAGS_SECRET
  • EDGE_CONFIG (Vercel Edge Config connection string)
  • LAUNCHDARKLY_PROJECT_SLUG
  • LAUNCHDARKLY_CLIENT_SIDE_ID
  • NEXT_PUBLIC_LAUNCHDARKLY_CLIENT_SIDE_ID (set to same value as LAUNCHDARKLY_CLIENT_SIDE_ID)

(Optional) If you provide the LAUNCHDARKLY_API_KEY, LAUNCHDARKLY_PROJECT_KEY and LAUNCHDARKLY_ENVIRONMENT environment variables, the Flags Explorer will fetch additional metadata from the LaunchDarkly API.

This will show the description (if set) and displays a link to the feature flag on the LaunchDarkly Console.

You can create an API key and find project and environment values in the LaunchDarkly Console.

Prix

Gratuit

FREE

评论 (0)

常见问题

常见问题解答 (FAQ)

有问题?我们有答案。如果您找不到想要的答案,请随时联络我们。

Boilerapp 是一个专门用于分享 Boilerplates、入门套件(Starter Kits)和项目模版的开发者社区平台。我们的目标很简单:为您节省初始配置(Setup)的时间,让您可以专注于真正重要的代码。无论您是在寻找简单的代码库还是完整的 SaaS 项目,都能在这里找到。

还有其他问题?

我们的团队随时为您提供帮助。联络我们,我们将尽快回复。