HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In


The Optimizely SDKs make HTTP requests for every impression or conversion 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 Java 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 take advantage of features like batching, which makes it easier to handle large event volumes efficiently or to 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 event dispatcher should implement a `dispatchEvent` function, which takes in three arguments: `httpVerb`, `url`, and `params`, all of which are created by the internal `EventBuilder` class. 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. Modifying this payload will alter your results.

We provide an asynchronous event dispatcher, [optimizely-sdk-httpclient](🔗), that requires `org.apache.httpcomponents:httpclient:4.5.2` and is parameterized by in-memory queue size and number of dispatch worker threads.

To use your own event dispatcher, implement the `dispatchEvent` method in our [EventHandler](🔗) interface. `dispatchEvent` takes in a [LogEvent](🔗) object containing all of the information needed to dispatch an event to Optimizely's backend. Events should be sent to `LogEvent.getEndpointUrl` as a `POST` request with `LogEvent.getBody` as the payload and `content-type: "application/json"` as the header.