|
| 1 | +# Growthbook Flags SDK Example |
| 2 | + |
| 3 | +This example uses GrowthBook for feature flags with the [Flags SDK](https://flags-sdk.dev) along with the `@flags-sdk/growthbook` [GrowthBook adapter](https://flags-sdk.dev/providers/growthbook) and the [Flags Explorer](https://vercel.com/docs/workflow-collaboration/feature-flags/using-vercel-toolbar). |
| 4 | + |
| 5 | +## Demo |
| 6 | + |
| 7 | +[https://flags-sdk-growthbook.vercel.app/](https://flags-sdk-growthbook.vercel.app/) |
| 8 | + |
| 9 | +## How it works |
| 10 | + |
| 11 | +This demo controls the visibility of two banners on the home page, and the color of the checkout button. |
| 12 | + |
| 13 | +Once you visit the page, you can see a variation of both/one/none of the banners. |
| 14 | + |
| 15 | +To test different variations, you can use the Dev Tools at the bottom to reset the stable id and reload the page. |
| 16 | + |
| 17 | +When you create and link a project on Vercel, you may use the [Flags Explorer](https://vercel.com/docs/workflow-collaboration/feature-flags/using-vercel-toolbar) to see what variants are active, and test different variations by creating overrides. |
| 18 | + |
| 19 | +## Deploy this template |
| 20 | + |
| 21 | +[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fexamples%2Ftree%2Fmain%2Fflags-sdk%2Fgrowthbook&env=GROWTHBOOK_CLIENT_KEY&env=FLAGS_SECRET&envDescription=The+FLAGS_SECRET+will+be+used+by+the+Flags+Explorer+to+securely+overwrite+feature+flags.+Must+be+32+random+bytes%2C+base64-encoded.+Use+the+generated+value+or+set+your+own.&envLink=https%3A%2F%2Fvercel.com%2Fdocs%2Fworkflow-collaboration%2Ffeature-flags%2Fsupporting-feature-flags%23flags_secret-environment-variable&project-name=growthbook-flags-sdk-example&repository-name=growthbook-flags-sdk-example) |
| 22 | + |
| 23 | +### Step 1: Link the project |
| 24 | + |
| 25 | +In order to use the Flags Explorer, you need to link the project on your local machine. |
| 26 | + |
| 27 | +```bash |
| 28 | +vercel link |
| 29 | +``` |
| 30 | + |
| 31 | +If your project does not exist yet, you will be prompted to create it. |
| 32 | + |
| 33 | +### Step 2: Pull all environment variables |
| 34 | + |
| 35 | +This allows the Flags SDK and the Flags Explorer to work correctly, by getting additional metadata. |
| 36 | + |
| 37 | +```bash |
| 38 | +vercel env pull |
| 39 | +``` |
| 40 | + |
| 41 | +If you are building this on the CLI, you can set the environment variables with `vercel env add` |
| 42 | + |
| 43 | +### Step 3: Create Feature Gates and Experiments |
| 44 | + |
| 45 | +On GrowthBook, create a project with the following flags split by `id`: |
| 46 | + |
| 47 | +- `free_delivery` (50% rollout or experiment) |
| 48 | +- `summer_sale` (50% rollout or experiment) |
| 49 | +- `proceed_to_checkout` (Multiple variants serving `red`, `green` or `blue`) |
| 50 | + |
| 51 | +The id of the flags in GrowthBook should match the key of the flags in the `flags.ts` file. |
| 52 | + |
| 53 | +If you have not started your experiments yet, you must do so in order to see the traffic split. |
0 commit comments