Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Learn how to use Optimizely to run feature flags and A/B experiments at the edge with Vercel Edge Middleware.
Feature Flags with Optimizely is a Next.js starter template from Vercel's examples repository that demonstrates running Optimizely Full Stack feature flagging and A/B experiments inside Edge Middleware on Vercel. The template uses the Optimizely JavaScript SDK to evaluate a product_sort feature flag at the edge and returns different sorting methods based on a user cookie.
This template is a ready-to-deploy Next.js application that integrates Optimizely Full Stack with Vercel Edge Middleware. It takes an Optimizely SDK Key and a datafile from the Optimizely CDN as inputs, and outputs middleware behavior that delivers different feature variations to users based on flag rules. The project is built with Next.js and Tailwind CSS, and is designed to be deployed to Vercel with a one-click clone.
product_sort flag and a sort_method variable, configured to deliver either "alphabetical" or "popular_first" sorting based on a 50% traffic rule.This template is for Next.js developers who want to add feature flags to edge-rendered applications. It suits teams already using Optimizely or evaluating experimentation platforms, and product engineers who need to roll out features gradually and roll them back instantly without deploying new code.
product_sort flag to expose a new sorting algorithm to 50% of traffic in the primary environment, then adjust the percentage at any time.First, you register a free Optimizely account, create a feature flag and variable, and set up a targeted delivery rule. Then you copy the SDK key from Settings > Primary Environment, add it as the OPTIMIZELY_SDK_KEY environment variable in Vercel, and deploy the template. At runtime, Edge Middleware reads the user's cookie ID, calls the Optimizely SDK to evaluate the flag, and returns the appropriate variation. When you change flags in Optimizely, a webhook can hit a Vercel Deploy Hook to rebuild the app and pull the updated datafile.
Yes, a free Optimizely account is required. The setup instructions link to Optimizely's free feature flagging sign-up page and assume you have a Flags-enabled project.
It requires OPTIMIZELY_SDK_KEY, which you copy from Optimizely's Settings > Primary Environment and paste into your Vercel project's Environment Variables section.
The template fetches the latest datafile from the Optimizely CDN during every build. To make updates automatic, you can create a Deploy Hook in Vercel and configure an Optimizely Webhook to call it whenever your flags change.
The example creates a flag named product_sort with a string variable sort_method. The default variation uses "alphabetical", while the "on" variation sets it to "popular_first", and a targeted delivery rule delivers that variation to 50% of traffic.
