0.0.7 • Published 8 months ago

@optimizely/edge-delivery v0.0.7

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
8 months ago

Prequisites

Implementing 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 you'd prefer to start from scratch using Cloudflare's getting started guide.

Installing the Edge Delivery SDK

Install the Edge Delivery library using npm:

npm install @optimizely/edge-delivery

Implementing and executing experiments

The SDK requires a Snippet ID (snippetId) to know which configuration file to retrieve to execute your experiments.

Basic configuration options

It's recommended to set a Development URL (devUrl) for the SDK to use as a target when testing locally or at your worker site directly.

const options = {
    "snippetId": "29061560280",
    "devUrl": "https://example.com/"
};

applyExperiments

The applyExperiments method is used to execute experiments. This method uses the request information to make experiment bucketing decisions and apply active experiment variations to the control. Any decisions or changes that cannot be made on the edge are packaged together and added to the <head> element for execution on the browser.

import { applyExperiments } from '@optimizely/edge-delivery';
...
await applyExperiments(request, ctx, options);

Other configuration options

Optionally, you may pass a Response object as the control in the options parameter. This can be useful if you already have an existing Cloudflare Worker that, for example, makes modifications to the control outside of Optimizely experiments.

let control = await fetch(request);
...
const options = {
    // Other options
    "control": control
};