Fast and safe experimentation with Next.js App Router, Vercel Feature Flags, 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:
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.
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# oryarn dev# orpnpm dev# orbun dev
Open http://localhost:3000 with your browser to see the result.
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:
https://[project domain]/api/.well-known/vercel/webhooks/optimizely
).OPTIMIZELY_WEBHOOK_SECRET
, to the secret key.File(s) | Description |
---|---|
/app/[code]/page.tsx | Static homepage with dynamic segment for multiple variations |
/app/product/[slug]/page.tsx | Product detail page |
/app/cart/page.tsx | Cart page |
/app/.well-known/vercel/flags/route.ts | API route exposing flags to toolbar |
/app/.well-known/vercel/webhooks/optimizely/route.ts | API route called by optimizely to store experimentation data in Vercel Edge Config |
/lib/actions.ts | File containing server actions (e.g. track purchase event) |
/lib/flags.ts | Contains declared flags and precomputed flags |
/middleware.ts | Evaluates precomputed flags, set new shopper cookie |
/lib/products.ts | A hardcoded set of products |
Take a look at the following resources to learn more:
Fast and safe experimentation with Next.js App Router, Vercel Feature Flags, 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:
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.
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# oryarn dev# orpnpm dev# orbun dev
Open http://localhost:3000 with your browser to see the result.
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:
https://[project domain]/api/.well-known/vercel/webhooks/optimizely
).OPTIMIZELY_WEBHOOK_SECRET
, to the secret key.File(s) | Description |
---|---|
/app/[code]/page.tsx | Static homepage with dynamic segment for multiple variations |
/app/product/[slug]/page.tsx | Product detail page |
/app/cart/page.tsx | Cart page |
/app/.well-known/vercel/flags/route.ts | API route exposing flags to toolbar |
/app/.well-known/vercel/webhooks/optimizely/route.ts | API route called by optimizely to store experimentation data in Vercel Edge Config |
/lib/actions.ts | File containing server actions (e.g. track purchase event) |
/lib/flags.ts | Contains declared flags and precomputed flags |
/middleware.ts | Evaluates precomputed flags, set new shopper cookie |
/lib/products.ts | A hardcoded set of products |
Take a look at the following resources to learn more: