Installation
Install with a package managerAdapter Usage
Import the Default Adapter
A default adapter is available for use, assuming the appropriate environment variables are setEnvironment Variables
The default adapter automatically uses following environment variables:Create a Custom Adapter
You can provide custom configuration by usingcreateGrowthBookAdapter:
User Identification
GrowthBook uses Attributes to evaluate feature flags and experiments. You should write an identify function providing these Attributes to GrowthBook flags:Adapter Methods and Properties
.feature<T>()
This method implements the Adapter interface for a GrowthBook feature. Typically flag definitions are applied in single file (e.g. flags.ts).
feature({ exposureLogging: false }))
.initialize()
Initializes the GrowthBook SDK. This is done on-demand when a growthbook flag is evaluated, and is not required to be called manually:
.setTrackingCallback()
Set a back-end callback to handle experiment exposures. This allows you to log exposures to your analytics platform. Typically this is done in the same file where your flags are defined (e.g. flags.ts).
.setStickyBucketService()
Sticky bucketing ensures that users see the same experiment variant, even when user session, user login status, or experiment parameters change. See the Sticky Bucketing docs for more information. If your organization and experiment supports sticky bucketing, you must implement an instance of the StickyBucketService to use Sticky Bucketing.
.growthbook
You may access the underlying GrowthBook instance. Specifically, our Flags SDK adapter wraps the GrowthBookClient class read more. All user evaluation options (attributes, tracking callbacks, sticky buckets) are applied at the userContext level (not globally).
.stickyBucketService
If you have set a sticky bucket service, you may retrieve its instance.
Edge Config
The adapter can load your SDK payload from Vercel’s Edge Config to lower the latency of feature flag evaluation:- Set
GROWTHBOOK_EDGE_CONNECTION_STRING(orEXPERIMENTATION_CONFIGif installed through the Vercel Marketplace) in your environment. Optionally setGROWTHBOOK_EDGE_CONFIG_ITEM_KEYto override the default key name (defaults to your client key). - Or pass
edgeConfigdirectly to the adapter.
Configuring a SDK Webhook
- To automatically populate the Edge Config whenever your feature definitions change, create a SDK Webhook on the same SDK Connection that you are using for the Next.js integration.ts
- Select “Vercel Edge Config” as the webhook type and fill out the following fields:
- Vercel Edge Config ID (begins with
ecfg_) - Team ID (optional)
- Vercel API Token (see Vercel → Account Settings → Tokens)
- Endpoint URL is being set to
- Method is being set to
PATCH - An Authorization: Bearer token header is being added with your Vercel API Token
- The Payload format is being set to
Vercel Edge Config
Vercel Edge Config limitationsVercel’s Edge Config is subject to storage size limitations. If your SDK payload is excessively large, you may not be able to populate the your Edge Config. Read more about limitations here.
Additional Configuration
- Initialization: The adapter auto-initializes when a flag is evaluated. To pre-initialize, call
initialize()manually. - Exposure Logging: By default, exposures are logged when flags are evaluated. You can disable this with
exposureLogging: falseor provide a custom tracking callback (applicable to back-end tracking only).
Flags Explorer Integration
To expose GrowthBook data to the Flags Explorer, use thegetProviderData function in your API route:
GROWTHBOOK_API_KEY. You will need to create and provide either a Personal Access Token (read-only) or an API Key.
You will also need to provide a FLAGS_SECRET environment variable. See Vercel’s Flags Explorer guide.
Client-side Tracking
When using the Flags SDK, we strongly encourage using server-side tracking when possible. However, some event trackers are best suited for client-side implementation. Additionally, some user attributes may only be available in a front-end context. We recommend implementing client-side tracking using some glue components:- A
<GrowthbookTracking>server component which takes a list of evaluated feature ids and prepares the data necessary to hydrate the tracking calls for the client. It embeds a<GrowthbookTrackingClient>client component. - A
<GrowthbookTrackingClient>client component responsible for executing and deduping your tracking calls in the browser. You will need to define a client-side tracking callback within this component. Under the hood, this component works by replaying all of the experiment evaluations in a client context. - You must include
<GrowthbookTracking>in any component which evaluates a feature flag (or specifically: all referenced flags that may trigger experiment tracking callbacks).
components/growthbook/client-side-tracking/growthbook-tracking.tsx
components/growthbook/client-side-tracking/client.tsx
app/layout.tsx

