dada
11 min
doc with headers docid\ rlp1waisa9gyy0idadh2w optimizely edge delivery lets you execute optimizely web experiments on cloudflare workers https //developers cloudflare com/workers/ for help with installation, see the demo walkthrough below and follow the steps in this article prerequisites have a cloudflare account https //dash cloudflare com/sign up/workers and pages install the wrangler cli https //developers cloudflare com/workers/wrangler/ route your website through cloudflare have an optimizely web experimentation account create an experiment quick start clone the edge delivery repository https //github com/optimizely/edge delivery and go to the templates/edge delivery starter directory cd templates/edge delivery starter install the requirements npm install run the worker locally npm run dev this opens your worker in a browser it loads the website https //example com/ and executes an experiment that modifies the h1 header text at the edge modify the snippet id and dev url environment variables in the wrangler toml file the snippet id https //support optimizely com/hc/en us/articles/4410284078605 check that the snippet is implemented#h 01hp06r9k06mdhk64f4zs4fvzh ( snippetid ) determines which configuration file to use for executing your experiments the development url ( devurl ) identifies what the sdk should target when testing locally or directly on your worker site this project's environment variables are set to an example experiment by default modify them to test an experiment against your website const options = { "snippetid" "29061560280", "devurl" "https //example com/" }; run npm run dev again to test the changes log in to your cloudflare account using oauth wrangler login deploy the worker to your cloudflare account npm run deploy add a route for your cloudflare worker https //developers cloudflare com/workers/configuration/routing/routes/ for the target website you want to proxy alternatively, you can add a route to the wrangler toml file before running npm run deploy go to your website in a browser to see your experiments in action implement in an existing worker you can install the optimizely edge delivery sdk in any existing cloudflare worker, whether you already route your incoming traffic through a cloudflare worker or prefer to start from scratch using cloudflare's getting started guide https //developers cloudflare com/workers/get started/guide/ install the edge delivery sdk install the edge delivery library https //www npmjs com/package/@optimizely/edge delivery using npm npm install @optimizely/edge delivery\@latest implement and execute experiments applyexperiments the applyexperiments method executes experiments using the request information to make experiment bucketing decisions and apply active experiment variations to the control any decisions or changes that cannot be made at the edge are packaged together and added to the \<head> element for execution in the browser import { applyexperiments } from '@optimizely/edge delivery'; await applyexperiments(request, ctx, options); other configuration options if you already have a cloudflare edge worker proxying your traffic, you can install and execute experiments in your existing cloudflare worker by downloading and installing the library with npm, adding the import, and passing a response object as the control in the options parameter let control = await fetch(request); const options = { // other options "control" control }; corrected!