Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideRecipesAPI ReferenceChangelog
Dev guideAPI ReferenceRecipesChangelogUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Configure the JavaScript 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.

❗️

Warning

This content covers the Feature Experimentation JavaScript (Browser) SDK v6 features currently in pre-production testing and is subject to change before release

For the latest released version, see JavaScript (Browser) SDK.

Minimum SDK version

v6.0.0+

Description

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

The JavaScript (Browser) SDK has an asynchronous dispatcher. You should customize 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 lets you 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 Event Processor with an event dispatcher instance.

import { 
  createInstance,
  eventDispatcher,
  createPollingProjectConfigManager,
  createBatchEventProcessor
} from '@optimizely/optimizely-sdk';

const SDK_KEY="YOUR_SDK_KEY";

const pollingConfigManager = createPollingProjectConfigManager({
  sdkKey: SDK_KEY,
});

const batchEventProcessor = createBatchEventProcessor({
  eventDispatcher: eventDispatcher,
});

// Create an Optimizely client with the default event dispatcher
const optimizelyClientInstance = createInstance({
	projectConfigManager: pollingConfigManager,
  eventProcessor: batchEventProcessor
});

Arguments

The event dispatcher should implement a dispatchEvent function, which takes in three arguments: httpVerb, url, and params. 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.

🚧

Important

If you are using a custom event dispatcher, do not modify the event payload returned from Optimizely Feature Experimentation. Modifying this payload alters your results on the Experiment Results page.

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