Dev guideAPI Reference
Dev guideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Configure the JavaScript (Browser) SDK event dispatcher

How to configure the event dispatcher for HTTP requests made from every impression or conversion in the Optimizely Feature Experimentation JavaScript (Browser) SDK.

The Optimizely Feature Experimentation SDKs make HTTP requests for every decision event or conversion event that gets triggered. Each SDK has a built-in event dispatcher for handling these events, but we recommend overriding it based on the specifics of your environment.

The JavaScript SDK has an out-of-the-box asynchronous dispatcher. We recommend customizing the event dispatcher you use in production to ensure that you queue and send events in a manner that scales to the volumes handled by your application. Customizing the event dispatcher allows you to efficiently handle large event volumes or implement retry logic when a request fails. You can build your dispatcher from scratch or start with the provided dispatcher.

The examples show that to customize the event dispatcher, initialize the Optimizely client (or manager) with an event dispatcher instance. The JavaScript example is for SDKs version 3.0.1 and later.

// 3.0.1 SDK and above
import { createInstance, eventDispatcher } from '@optimizely/optimizely-sdk';

// Create an Optimizely client with the default event dispatcher
const optimizelyClientInstance = createInstance({
  sdkKey: '<YOUR_SDK_KEY>',

The event dispatcher should implement a dispatchEvent function, which takes in two arguments: an object with httpVerb, url, and params properties, all of which are created by the internal EventBuilder class, and an optional callback. In this function, you should send a POST request to the given url using the params as the body of the request (be sure to stringify it to JSON) and {content-type: 'application/json'} in the headers.



If you are using a custom event dispatcher, do not modify the event payload returned from Optimizely Feature Experimentation. Modifying this payload will alter your results.

By default, our JavaScript (Browser) SDK uses a basic asynchronous event dispatcher.