Skip to main content
This tutorial shows you how to use GrowthBook with Vercel’s Edge Config and Feature Flags SDK to manage feature flags in a Next.js app. You’ll need a Next app deployed on Vercel to follow along. While it’s not necessary to use GrowthBook with Vercel’s platform (see our other guides on adding GrowthBook to Next.js), this setup provides several benefits:
  • Performance: Vercel Edge Config  is a global data store that provides near-instantaneous access to your data, making it perfect for handling feature flags.
  • Streamlined: The GrowthBook SDK automatically sends feature flag values to Vercel Edge Config, keeping your data in sync.
  • Developer Experience: The Vercel Toolbar enables your team to inspect feature flags, locally override their values, and see changes.

Use Vercel Edge Config to Store GrowthBook Feature Flags

To set up Edge Config:
  1. Log in to Vercel and select your project. Navigate to Storage.
  2. Create a new Edge Config and save the ID (starting with ecfg_) to use later. If you’re part of a team in Vercel, also save your Team ID. Note that even personal accounts may have a team.
  3. Navigate to Account SettingsTokens and create a Vercel API Token. Save the value to use in the next step.

Create a GrowthBook SDK Webhook

In GrowthBook:
  1. Navigate to SDK Connections. Open or create a JavaScript SDK connection.
  2. Add a new SDK Webhook and set the type to Vercel Edge Config.
  3. Add your Edge Config ID, Vercel API Token, and Team ID.
GrowthBook SDK Webhook
After you add the webhook, click Test to verify it’s working correctly.
If you receive an items exceed size limit error, it means your feature flag payload is too large. Vercel limits the size of your Edge Config store depending on your plan. You can either reduce the number of flags or upgrade your Vercel plan.

Configure Next.js

In your Next app, install the required dependencies:

flags.ts

Create a utils/flags.ts file in your project. This file configures the GrowthBook SDK and defines some helper functions to use feature flags throughout your app.

TrackFlags.tsx

Create a utils/TrackFlags.ts file in your project. This client component sends a tracking event whenever a user is exposed to an A/B test. Replace the console.log with your own tracking callback.

Set Up Environment Variables

Pull in environment variables from your Vercel project:
This command creates an .env.local file in your project with the EDGE_CONFIG key.

Create Feature Flags in GrowthBook

In GrowthBook, create 2 new feature flags: Your flags should look like this:
Feature flags configured in GrowthBook
These simple flags demonstrate everything you need to know to create more complex feature flags with targeting rules, percent rollouts, and A/B tests.

Use Feature Flags in Your Next.js App

Open page.tsx (or your main component) and add:
Start your development server:
Now you can see your feature flags in action!

🎉 Bonus: The Vercel Toolbar

Use the Vercel Toolbar to locally override flag values and see real-time changes.
Vercel Toolbar

Enable the Toolbar

Create a new file, app/.well-known/vercel/flags/route.ts, in your project:

Set Up the FLAGS_SECRET Environment Variable

  1. Generate a new secret key:
  1. In your Vercel project settings, create a new environment variable called FLAGS_SECRET. Paste the generated key as the value.
  2. Locally, run npx vercel env pull to update your .env.local file with the new environment variable.
See Vercel’s docs for more info.

Refresh and Explore

With everything in place, it’s time to see the Vercel Toolbar in action. Refresh your app and click the toggle icon to see feature flag values and override them. You’ve got the power!

Conclusion

You’ve successfully integrated GrowthBook with Next.js and Vercel Feature Flags, giving you fine-grained control over your features, improved performance with Edge Config, and a streamlined development workflow. Now get out there and start experimenting 🧪