Configure event dispatcher
This topic describes how to configure the event dispatcher for HTTP requests made from every impression or conversion in the Optimizely Ruby SDK.
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 Ruby SDK has an out-of-the-box synchronous 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.
Important
Performance risks with synchronous dispatchers: It is important to customize your event dispatcher when using an SDK with a synchronous built-in event dispatcher (PHP, Ruby, and Python) to ensure that you can retrieve variations without waiting for the corresponding network request to return.
The examples show that to customize the event dispatcher, initialize the Optimizely client (or manager) with an event dispatcher instance.
# Create an Optimizely client with the default event dispatcher
optimizely_client = Optimizely::Project.new(datafile,
Optimizely::EventDispatcher.new)
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.
Our Ruby SDK includes a basic synchronous event dispatcher. If you are using the SDK in a production environment, you should provide your own event dispatcher using the networking library of your choice. Examples of alternative approaches are available here:
Updated over 2 years ago