Using Global Config with Split
This guide will help you get started with using Vercel's Split integration with Global Config. This integration allows you to use Global Config as a configuration source for your Split feature flags.
Split is a feature flag provider that tracks event data, enabling you to release features, target them to audiences, and measure their impact on customer experience metrics securely.
The Split Global Config integration enables you to write your Split rollout plan to a Global Config. Doing so will allow you to evaluate feature flags at ultra-low latency with Vercel's CDN while tracking events and impressions data with Split.
Before using this integration, you should have:
- The latest version of Vercel CLI. To check your version, use
vercel --version. To install or update Vercel CLI, use:Terminalpnpm i -g vercel@latestTerminalyarn global add vercel@latestTerminalnpm i -g vercel@latestTerminalbun add -g vercel@latest - A project. If you don't have one, you can run the following terminal commands to create a Next project:
pnpm create next-app@latest yarn create next-app@latest npx create-next-app@latest bunx create-next-app@latest - A Vercel project. If you don't have one, see Creating a Project
- A Global Config. If you don't have one, follow the Global Config quickstart
- The Global Config SDK:
Terminal
pnpm i @vercel/global-configTerminalyarn add @vercel/global-configTerminalnpm i @vercel/global-configTerminalbun add @vercel/global-config
Visit the Split page in the Vercel Integration Marketplace and select the Add Integration button. From the Integration dialog:
- Select a Vercel team and project to connect the integration to
- Log into Split
- Select the Split Environment you want to use
- Select an existing Global Config or create a new one
- Copy the Global Config item key provided on this page. You'll need it to add it to your Environment Variables
If you already have existing feature flags, you can skip this step and use those. In this example, we'll create one called
New_Marketing_Page. You can set the user targeting to Joe and Bobby.To create a feature flag in Split:
- Log into your Split management console and select the workspace icon near the top-left of the page
- In the sidebar, under Target, select Feature flags. Add the name
New_Marketing_Page, and set the traffic type touser. Select Create to finish - With your feature flag created, select the feature flag and open Definition in the sidebar. Select Initiate Environment to configure your flag
- Add valid users to the feature flag
- Scroll down to Targeting and select Add new individual target
- Under To user, add any username you want to test. This example uses
Joe. - Select Add new individual target, then set the Description option to
off. Add another username under To user. This example usesBobby - Select Review Changes, then Create to finish
Next, you need to add your credentials to your project's local environment to use the Split integration in your code.
Next, you'll add the following credentials to your Vercel project:
SPLIT_SDK_CLIENT_API_KEYEDGE_CONFIG_SPLIT_ITEM_KEYGLOBAL_CONFIG
To add environment variables to your project, visit your Vercel dashboard and select the project you want to use the Split integration with. Then select Settings > Environment Variables.
To get your Split client-side API keys:
- Log into your Split management console and select the workspace icon near the top-left of the page
- In the list of options that appears, select Admin Settings, then navigate to API Keys -> SDK API Keys
- Copy the client-side keys associated with the workspace and environment you're using
To add your Global Config Split item key, if you didn't copy it after setting up the integration on Vercel:
- Visit your dashboard on Vercel
- In the Integrations section in the sidebar, select Manage
- On the integration page, select Configure
- You should see the item key on the page that opens. Copy it
To add your Global Config's connection string to your project:
- Visit your project's page in the dashboard
- Open Storage in the sidebar. Select Connect Store and select the Global Config associated with your Split integration. The
GLOBAL_CONFIGenvironment variable will be set automatically.
Now you're ready to use the Split Global Config integration in your code.
Open your project's code on your local machine and do the following:
- Install Split's Browser SDK, Vercel integration utilities, and Vercel's Global Config SDK:
Terminalpnpm i @splitsoftware/splitio-browserjs @splitsoftware/vercel-integration-utils @vercel/global-configTerminalyarn add @splitsoftware/splitio-browserjs @splitsoftware/vercel-integration-utils @vercel/global-configTerminalnpm i @splitsoftware/splitio-browserjs @splitsoftware/vercel-integration-utils @vercel/global-configTerminalbun add @splitsoftware/splitio-browserjs @splitsoftware/vercel-integration-utils @vercel/global-config- Create an API route in your project. The following example fetches a treatement based on which user is visiting. You can specify the user by appending
?userKey=Joeor?userKey=Bobbyto the URL when visiting the route:
app/api/marketing-example/route.tsimport { SplitFactory, PluggableStorage, ErrorLogger, } from '@splitsoftware/splitio-browserjs'; import { EdgeConfigWrapper } from '@splitsoftware/vercel-integration-utils'; import { createClient } from '@vercel/global-config'; export async function GET(request: Request) { const { EDGE_CONFIG_SPLIT_ITEM_KEY, SPLIT_SDK_CLIENT_API_KEY } = process.env; if (!SPLIT_SDK_CLIENT_API_KEY || !EDGE_CONFIG_SPLIT_ITEM_KEY) return new Response( `Failed to find your SDK Key (${SPLIT_SDK_CLIENT_API_KEY}) or item key ${EDGE_CONFIG_SPLIT_ITEM_KEY}`, ); const edgeConfigClient = createClient(process.env.GLOBAL_CONFIG); const { searchParams } = new URL(request.url); const userKey = searchParams.get('userKey') || 'anonymous'; const client = SplitFactory({ core: { authorizationKey: SPLIT_SDK_CLIENT_API_KEY, key: userKey, }, mode: 'consumer_partial', storage: PluggableStorage({ wrapper: EdgeConfigWrapper({ // The Global Config item key where Split stores // feature flag definitions edgeConfigItemKey: EDGE_CONFIG_SPLIT_ITEM_KEY, // The Global Config client edgeConfig: edgeConfigClient, }), }), // Disable or keep only ERROR log level in production, // to minimize performance impact debug: ErrorLogger(), }).client(); await new Promise((resolve) => { client.on(client.Event.SDK_READY, () => resolve); client.on(client.Event.SDK_READY_TIMED_OUT, () => resolve); }); // Replace this with the feature flag you want const FEATURE_FLAG = 'New_Marketing_Page'; const treatment = await client.getTreatment(FEATURE_FLAG); // Must await in app-router; waitUntil() is not // yet supported await client.destroy(); // treatment will be 'control' if the SDK timed out if (treatment == 'control') return new Response('Control marketing page'); return treatment === 'on' ? new Response('New marketing page') : new Response('Old marketing page'); }app/api/marketing-example/route.jsimport { SplitFactory, PluggableStorage, ErrorLogger, } from '@splitsoftware/splitio-browserjs'; import { EdgeConfigWrapper } from '@splitsoftware/vercel-integration-utils'; import { createClient } from '@vercel/global-config'; export async function GET(request) { const { EDGE_CONFIG_SPLIT_ITEM_KEY, SPLIT_SDK_CLIENT_API_KEY } = process.env; if (!SPLIT_SDK_CLIENT_API_KEY || !EDGE_CONFIG_SPLIT_ITEM_KEY) return new Response( `Failed to find your SDK Key (${SPLIT_SDK_CLIENT_API_KEY}) or item key ${EDGE_CONFIG_SPLIT_ITEM_KEY}`, ); const edgeConfigClient = createClient(process.env.GLOBAL_CONFIG); const { searchParams } = new URL(request.url); const userKey = searchParams.get('userKey') || 'anonymous'; const client = SplitFactory({ core: { authorizationKey: SPLIT_SDK_CLIENT_API_KEY, key: userKey, }, mode: 'consumer_partial', storage: PluggableStorage({ wrapper: EdgeConfigWrapper({ // The Global Config item key where Split stores // feature flag definitions edgeConfigItemKey: EDGE_CONFIG_SPLIT_ITEM_KEY, // The Global Config client edgeConfig: edgeConfigClient, }), }), // Disable or keep only ERROR log level in production, // to minimize performance impact debug: ErrorLogger(), }).client(); await new Promise((resolve) => { client.on(client.Event.SDK_READY, () => resolve); client.on(client.Event.SDK_READY_TIMED_OUT, () => resolve); }); // Replace this with the feature flag you want const FEATURE_FLAG = 'New_Marketing_Page'; const treatment = await client.getTreatment(FEATURE_FLAG); // Must await in app-router; waitUntil() is not // yet supported await client.destroy(); // treatment will be 'control' if the SDK timed out if (treatment == 'control') return new Response('Control marketing page'); return treatment === 'on' ? new Response('New marketing page') : new Response('Old marketing page'); }pages/api/marketing-example.tsimport { SplitFactory, PluggableStorage, ErrorLogger, } from '@splitsoftware/splitio-browserjs'; import { EdgeConfigWrapper } from '@splitsoftware/vercel-integration-utils'; import { createClient } from '@vercel/global-config'; import { NextFetchEvent } from 'next/server'; export default async function handler( request: Request, context: NextFetchEvent, ) { const { EDGE_CONFIG_SPLIT_ITEM_KEY, SPLIT_SDK_CLIENT_API_KEY } = process.env; if (!SPLIT_SDK_CLIENT_API_KEY || !EDGE_CONFIG_SPLIT_ITEM_KEY) return new Response( `Failed to find your SDK Key (${SPLIT_SDK_CLIENT_API_KEY}) or item key ${EDGE_CONFIG_SPLIT_ITEM_KEY}`, ); const edgeConfigClient = createClient(process.env.GLOBAL_CONFIG); const { searchParams } = new URL(request.url); const userKey = searchParams.get('userKey') || 'anonymous'; const client = SplitFactory({ core: { authorizationKey: SPLIT_SDK_CLIENT_API_KEY, key: userKey, }, mode: 'consumer_partial', storage: PluggableStorage({ wrapper: EdgeConfigWrapper({ // The Global Config item key where Split stores // feature flag definitions edgeConfigItemKey: EDGE_CONFIG_SPLIT_ITEM_KEY, // The Global Config client edgeConfig: edgeConfigClient, }), }), // Disable or keep only ERROR log level in production, // to minimize performance impact debug: ErrorLogger(), }).client(); // Wait until await new Promise((resolve) => { client.on(client.Event.SDK_READY, () => resolve); client.on(client.Event.SDK_READY_TIMED_OUT, () => resolve); }); // Replace this with the feature flag you want const FEATURE_FLAG = 'New_Marketing_Page'; const treatment = await client.getTreatment(FEATURE_FLAG); // Must await in app-router; waitUntil() is not // yet supported context.waitUntil(client.destroy()); // treatment will be 'control' if the SDK timed out if (treatment == 'control') return new Response('Control marketing page'); return treatment === 'on' ? new Response('New marketing page') : new Response('Old marketing page'); }pages/api/marketing-example.jsimport { SplitFactory, PluggableStorage, ErrorLogger, } from '@splitsoftware/splitio-browserjs'; import { EdgeConfigWrapper } from '@splitsoftware/vercel-integration-utils'; import { createClient } from '@vercel/global-config'; export default async function handler(request, context) { const { EDGE_CONFIG_SPLIT_ITEM_KEY, SPLIT_SDK_CLIENT_API_KEY } = process.env; if (!SPLIT_SDK_CLIENT_API_KEY || !EDGE_CONFIG_SPLIT_ITEM_KEY) return new Response( `Failed to find your SDK Key (${SPLIT_SDK_CLIENT_API_KEY}) or item key ${EDGE_CONFIG_SPLIT_ITEM_KEY}`, ); const edgeConfigClient = createClient(process.env.GLOBAL_CONFIG); const { searchParams } = new URL(request.url); const userKey = searchParams.get('userKey') || 'anonymous'; const client = SplitFactory({ core: { authorizationKey: SPLIT_SDK_CLIENT_API_KEY, key: userKey, }, mode: 'consumer_partial', storage: PluggableStorage({ wrapper: EdgeConfigWrapper({ // The Global Config item key where Split stores // feature flag definitions edgeConfigItemKey: EDGE_CONFIG_SPLIT_ITEM_KEY, // The Global Config client edgeConfig: edgeConfigClient, }), }), // Disable or keep only ERROR log level in production, // to minimize performance impact debug: ErrorLogger(), }).client(); // Wait until await new Promise((resolve) => { client.on(client.Event.SDK_READY, () => resolve); client.on(client.Event.SDK_READY_TIMED_OUT, () => resolve); }); // Replace this with the feature flag you want const FEATURE_FLAG = 'New_Marketing_Page'; const treatment = await client.getTreatment(FEATURE_FLAG); // Must await in app-router; waitUntil() is not // yet supported context.waitUntil(client.destroy()); // treatment will be 'control' if the SDK timed out if (treatment == 'control') return new Response('Control marketing page'); return treatment === 'on' ? new Response('New marketing page') : new Response('Old marketing page'); }/api/marketing-example.tsimport { SplitFactory, PluggableStorage, ErrorLogger, } from '@splitsoftware/splitio-browserjs'; import { EdgeConfigWrapper } from '@splitsoftware/vercel-integration-utils'; import { RequestContext } from '@vercel/edge'; import { createClient } from '@vercel/global-config'; export default async function handler( request: Request, context: RequestContext, ) { const { EDGE_CONFIG_SPLIT_ITEM_KEY, SPLIT_SDK_CLIENT_API_KEY } = process.env; if (!SPLIT_SDK_CLIENT_API_KEY || !EDGE_CONFIG_SPLIT_ITEM_KEY) return new Response( `Failed to find your SDK Key (${SPLIT_SDK_CLIENT_API_KEY}) or item key ${EDGE_CONFIG_SPLIT_ITEM_KEY}`, ); const edgeConfigClient = createClient(process.env.GLOBAL_CONFIG); const { searchParams } = new URL(request.url); const userKey = searchParams.get('userKey') || 'anonymous'; const client = SplitFactory({ core: { authorizationKey: SPLIT_SDK_CLIENT_API_KEY, key: userKey, }, mode: 'consumer_partial', storage: PluggableStorage({ wrapper: EdgeConfigWrapper({ // The Global Config item key where Split stores // feature flag definitions edgeConfigItemKey: EDGE_CONFIG_SPLIT_ITEM_KEY, // The Global Config client edgeConfig: edgeConfigClient, }), }), // Disable or keep only ERROR log level in production, // to minimize performance impact debug: ErrorLogger(), }).client(); // Wait until await new Promise((resolve) => { client.on(client.Event.SDK_READY, () => resolve); client.on(client.Event.SDK_READY_TIMED_OUT, () => resolve); }); // Replace this with the feature flag you want const FEATURE_FLAG = 'New_Marketing_Page'; const treatment = await client.getTreatment(FEATURE_FLAG); // Must await in app-router; waitUntil() is not // yet supported context.waitUntil(client.destroy()); // treatment will be 'control' if the SDK timed out if (treatment == 'control') return new Response('Control marketing page'); return treatment === 'on' ? new Response('New marketing page') : new Response('Old marketing page'); }pages/api/marketing-example.jsSplitFactory, import { PluggableStorage, ErrorLogger, } from '@splitsoftware/splitio-browserjs'; import { EdgeConfigWrapper } from '@splitsoftware/vercel-integration-utils'; import { createClient } from '@vercel/global-config'; export default async function handler(request, context) { const { EDGE_CONFIG_SPLIT_ITEM_KEY, SPLIT_SDK_CLIENT_API_KEY } = process.env; if (!SPLIT_SDK_CLIENT_API_KEY || !EDGE_CONFIG_SPLIT_ITEM_KEY) return new Response( `Failed to find your SDK Key (${SPLIT_SDK_CLIENT_API_KEY}) or item key ${EDGE_CONFIG_SPLIT_ITEM_KEY}`, ); const edgeConfigClient = createClient(process.env.GLOBAL_CONFIG); const { searchParams } = new URL(request.url); const userKey = searchParams.get('userKey') || 'anonymous'; const client = SplitFactory({ core: { authorizationKey: SPLIT_SDK_CLIENT_API_KEY, key: userKey, }, mode: 'consumer_partial', storage: PluggableStorage({ wrapper: EdgeConfigWrapper({ // The Global Config item key where Split stores // feature flag definitions edgeConfigItemKey: EDGE_CONFIG_SPLIT_ITEM_KEY, // The Global Config client edgeConfig: edgeConfigClient, }), }), // Disable or keep only ERROR log level in production, // to minimize performance impact debug: ErrorLogger(), }).client(); // Wait until await new Promise((resolve) => { client.on(client.Event.SDK_READY, () => resolve); client.on(client.Event.SDK_READY_TIMED_OUT, () => resolve); }); // Replace this with the feature flag you want const FEATURE_FLAG = 'New_Marketing_Page'; const treatment = await client.getTreatment(FEATURE_FLAG); // Must await in app-router; waitUntil() is not // yet supported context.waitUntil(client.destroy()); // treatment will be 'control' if the SDK timed out if (treatment == 'control') return new Response('Control marketing page'); return treatment === 'on' ? new Response('New marketing page') : new Response('Old marketing page'); }- Start a local development server. If you're using Vercel CLI, enter the following command in the terminal:
terminalvercel dev- Navigate to http://localhost:3000/api/split-example?userKey=Joe. You should see either
New marketing pageorOld marketing pagebased on how your feature flags are configured in Split- Try changing the
userKeysearch param's value toBobby, or deleting it altogether, to see different responses when you visit the route
- Try changing the
Now that you have set up the Split Global Config integration, you can explore the following topics to learn more:
Was this helpful?