VercelLogotypeVercelLogotype
LoginSign Up
Back to Templates

Optimizely Feature Experimentation

Fast and safe experimentation with Next.js App Router, Vercel Feature Flags, and Optimizely Feature Experimentation

DeployView Demo
Optimizely Feature Experimentation

Next.js and Optimizely Feature Experimentation

This is a Next.js template that integrates with Optimizely Feature Experimentation.

This project uses Next.js App Router and Partial Prerendering (PPR) to combine the benefits of static and dynamic rendering. This enables fast page loads to users with dynamic content and experiments. Optimizely experimentation data is saved to Vercel Edge Config through Optimizely webhooks which allows Edge Middleware and React Server Components (RSC) to perform decisions with minimal latency.

This project uses:

  • Next.js App Router
  • Partial Prerendering (PPR)
  • Vercel Edge Config
  • Edge Middleware
  • Tailwind CSS & shadcn/ui
  • Vercel Toolbar
  • Vercel Feature Flags
  • Optimizely Feature Experimentation

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

Getting started

Sign up for a free Optimizely Feature Flags account and create a new project.

You must set the following environment variables to run this application:

  • OPTIMIZELY_API_KEY
  • OPTIMIZELY_SDK_KEY
  • OPTIMIZELY_PROJECT_ID
  • OPTIMIZELY_WEBHOOK_SECRET
  • API_TOKEN
  • TEAM_ID
  • EDGE_CONFIG
  • FLAGS_SECRET Create via: node -e "console.log(crypto.randomBytes(32).toString('base64url'))"

The Optimizely API key, SDK key, and Project ID are retrieved from your Optimizely Feature Experimentation project and account settings. The Optimizely webhook secret is created upon webhook creation. See the "Integrating Optimizely Webhooks with Vercel Edge Config" section below and Optimizely's Create Webhooks documentation for more details.

A Vercel API Token, Team ID, and Edge Config are required for storing experiment data in Vercel Edge Config. Refer to Creating an Access Token in Vercel's REST API documentation for creating your token, and Vercel Edge Config documentation for creating your Edge Config store.

Run the development server locally:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Open http://localhost:3000 with your browser to see the result.

Integrating Optimizely Webhooks with Vercel Edge Config

This experimentation template uses Optimizely webhooks to sync experiment data to Vercel Edge Config. This allows experiment decisions to run in Edge Middleware and React Server Components with minimal latency.

To configure your Optimizely webhook:

  1. Navigate your browser to app.optimizely.com.
  2. Login and go to your Optimizely Feature Experimentation project settings.
  3. Select the "Webhooks" tab.
  4. Click "Create New Webhook".
  5. Provide a name for your webhook.
  6. Set the URL to the location of your Next.js Optimizely webhook route (https://[project domain]/api/.well-known/vercel/webhooks/optimizely).
  7. Under events, ensure the following events are selected:
    1. Datafile: Updated
    2. Flag: Created, Updated, Archived, Deleted
    3. Event: Created, Updated, Archived, Deleted
    4. Variable: Created, Updated, Archived, Deleted
    5. Variation: Created, Updated, Archived, Deleted
  8. Click "Save" and note the secret key generated for your webhook.
  9. Set your Vercel environment variable, OPTIMIZELY_WEBHOOK_SECRET, to the secret key.
  10. Once your webhook is created, create or update a flag in Optimizely to trigger the webhook and sync your experiment data to Vercel Edge Config.

Important files and folders

File(s)Description
/app/[code]/page.tsxStatic homepage with dynamic segment for multiple variations
/app/product/[slug]/page.tsxProduct detail page
/app/cart/page.tsxCart page
/app/.well-known/vercel/flags/route.tsAPI route exposing flags to toolbar
/app/.well-known/vercel/webhooks/optimizely/route.tsAPI route called by optimizely to store experimentation data in Vercel Edge Config
/lib/actions.tsFile containing server actions (e.g. track purchase event)
/lib/flags.tsContains declared flags and precomputed flags
/middleware.tsEvaluates precomputed flags, set new shopper cookie
/lib/products.tsA hardcoded set of products

Learn More

Take a look at the following resources to learn more:

  • Guide: How to Integrate Optimizely Feature Experimentation with Next.js and Vercel
  • Workshop: Fast & Safe Experimentation with Next.js and Optimizely
  • Vercel Feature Flags
  • Precomputed Flags
  • Vercel Toolbar
  • Next.js Documentation
  • Learn Next.js
GitHub Repovercel/nextjs-optimizely-experimentation
Use Cases
Edge MiddlewareEdge ConfigStarter
Stack
Next.jsTailwind

Related Templates

Get Started

  • Templates
  • Supported frameworks
  • Marketplace
  • Domains

Build

  • Next.js on Vercel
  • Turborepo
  • v0

Scale

  • Content delivery network
  • Fluid compute
  • CI/CD
  • Observability
  • AI GatewayNew
  • Vercel AgentNew

Secure

  • Platform security
  • Web Application Firewall
  • Bot management
  • BotID
  • SandboxNew

Resources

  • Pricing
  • Customers
  • Enterprise
  • Articles
  • Startups
  • Solution partners

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Community

Frameworks

  • Next.js
  • Nuxt
  • Svelte
  • Nitro
  • Turbo

SDKs

  • AI SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDK
  • Streamdown AINew

Use Cases

  • Composable commerce
  • Multi-tenant platforms
  • Web apps
  • Marketing sites
  • Platform engineers
  • Design engineers

Company

  • About
  • Careers
  • Help
  • Press
  • Legal
  • Privacy Policy

Community

  • Open source program
  • Events
  • Shipped on Vercel
  • GitHub
  • LinkedIn
  • X
  • YouTube

Loading status…

Select a display theme:
    • AI Cloud
      • v0

        Build applications with AI

      • AI SDK

        The AI Toolkit for TypeScript

      • AI Gateway

        One endpoint, all your models

      • Vercel Agent

        An agent that knows your stack

      • Sandbox

        AI workflows in live environments

    • Core Platform
      • CI/CD

        Helping teams ship 6× faster

      • Content Delivery

        Fast, scalable, and reliable

      • Fluid Compute

        Servers, in serverless form

      • Observability

        Trace every step

    • Security
      • Bot Management

        Scalable bot protection

      • BotID

        Invisible CAPTCHA

      • Platform Security

        DDoS Protection, Firewall

      • Web Application Firewall

        Granular, custom protection

    • Company
      • Customers

        Trusted by the best teams

      • Blog

        The latest posts and changes

      • Changelog

        See what shipped

      • Press

        Read the latest news

      • Events

        Join us at an event

    • Learn
      • Docs

        Vercel documentation

      • Academy

        Linear courses to level up

      • Knowledge Base

        Find help quickly

      • Community

        Join the conversation

    • Open Source
      • Next.js

        The native Next.js platform

      • Nuxt

        The progressive web framework

      • Svelte

        The web’s efficient UI framework

      • Turborepo

        Speed with Enterprise scale

    • Use Cases
      • AI Apps

        Deploy at the speed of AI

      • Composable Commerce

        Power storefronts that convert

      • Marketing Sites

        Launch campaigns fast

      • Multi-tenant Platforms

        Scale apps with one codebase

      • Web Apps

        Ship features, not infrastructure

    • Tools
      • Marketplace

        Extend and automate workflows

      • Templates

        Jumpstart app development

      • Partner Finder

        Get help from solution partners

    • Users
      • Platform Engineers

        Automate away repetition

      • Design Engineers

        Deploy for every idea

  • Enterprise
  • Pricing
Log InContact
Sign Up
Sign Up
Back to Templates
DeployView Demo

Next.js App Router Playground

Examples of many Next.js App Router features.
Next.js App Router Playground

Next.js Boilerplate

Get started with Next.js and React in seconds.
Next.js Boilerplate
v0

Build applications with AI

AI SDK

The AI Toolkit for TypeScript

AI Gateway

One endpoint, all your models

Vercel Agent

An agent that knows your stack

Sandbox

AI workflows in live environments

CI/CD

Helping teams ship 6× faster

Content Delivery

Fast, scalable, and reliable

Fluid Compute

Servers, in serverless form

Observability

Trace every step

Bot Management

Scalable bot protection

BotID

Invisible CAPTCHA

Platform Security

DDoS Protection, Firewall

Web Application Firewall

Granular, custom protection

Customers

Trusted by the best teams

Blog

The latest posts and changes

Changelog

See what shipped

Press

Read the latest news

Events

Join us at an event

Docs

Vercel documentation

Academy

Linear courses to level up

Knowledge Base

Find help quickly

Community

Join the conversation

Next.js

The native Next.js platform

Nuxt

The progressive web framework

Svelte

The web’s efficient UI framework

Turborepo

Speed with Enterprise scale

AI Apps

Deploy at the speed of AI

Composable Commerce

Power storefronts that convert

Marketing Sites

Launch campaigns fast

Multi-tenant Platforms

Scale apps with one codebase

Web Apps

Ship features, not infrastructure

Marketplace

Extend and automate workflows

Templates

Jumpstart app development

Partner Finder

Get help from solution partners

Platform Engineers

Automate away repetition

Design Engineers

Deploy for every idea