Open source experimentation
GrowthBook is the most popular open source feature flag and experimentation platform, used at scale in production by thousands of companies.
By integrating GrowthBook Cloud with Vercel, you can view and manage all of your feature flags and experiments directly in Vercel. You can also enable Edge Config sync for near-zero initialization latency.
Start by connecting to your existing project and then run vercel link in the CLI to link to the project locally.
Run vercel env pull to make the latest environment variables available to your project locally.
Run npm install flags @flags-sdk/growthbook
Within GrowthBook, create a boolean feature flag with the key example_flag.
Set the default value to true and make sure it's enabled in all environments. This will let us use the flag in our code and quickly see that it's working.
Create a flags.ts file where you define user targeting attributes and referece the feature flag you just created in GrowthBook.
import { dedupe, flag } from 'flags/next';import type { Identify } from 'flags';import { growthbookAdapter, type Attributes } from '@flags-sdk/growthbook';
// Add any user attributes you want to use for targeting or experimentationconst identify = dedupe((async ({ headers, cookies }) => { return { id: cookies.get('user_id')?.value, // etc... };}) satisfies Identify<Attributes>);
// Export each feature flag you want to use:export const exampleFlag = flag({ key: 'example_flag', identify, adapter: growthbookAdapter.feature<boolean>(), defaultValue: false,});You can now import your flags in any server component:
import { exampleFlag } from "../flags";
export default async function Page() { const example = await exampleFlag();
return <div>Flag {example ? "on" : "off"}</div>;}If you run your app, you should see Flag on, indicating everything is working correctly.
Learn how to create a custom adapter, log experiment exposure events, configure Edge Config and more.
Installation is quick and easy. We will create a new account for you on GrowthBook Cloud and set you up with all of the required environment variables to quickly integrate our SDK into your code. If you enable Edge Config, we will also set up a webhook for you to keep feature definitions in sync automatically.