Experimentation Lab
Interactive implementation reference
Edge implementation

Edge Delivery

Apply Web Experimentation decisions and HTML changes in a Cloudflare Worker before content reaches the browser.

Cloudflare Worker · HTMLRewriter
This runtime cannot execute inside a Next.js browser process. The page shows the native, official SDK shape; use the JavaScript, React, or Next.js pages for a live decision and event round trip with the same project, flag, event, and visitor ID.

Implementation

Official docs ↗
npm install @optimizely/edge-delivery@latest
import { applyExperiments } from '@optimizely/edge-delivery';

export default {
  async fetch(request, env, ctx) {
    const control = await fetch(request);
    return applyExperiments(request, ctx, {
      control,
      projectId: env.OPTIMIZELY_PROJECT_ID,
    });
  },
};