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

Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Customize event dispatcher

This topic describes how to configure the event dispatcher for HTTP requests made from every impression or conversion in the Optimizely Objective-C 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.

Optimizely recommends 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.

CustomEventDispatcher *customEventDispatcher = [[CustomEventDispatcher alloc] init];

/** 
 * Initialize your Manager 
 *  (settings will propagate to OPTLYClient and Optimizely)
 */
  OPTLYManager *manager = [[OPTLYManager alloc] initWithBuilder:[OPTLYManagerBuilder  builderWithBlock:^(OPTLYManagerBuilder * _Nullable builder) {
      builder.sdkKey = @"SDK_KEY_HERE";
			builder.eventDispatcher = customEventDispatcher;
    }]];
let customEventDispatcher: CustomEventDispatcher = CustomEventDispatcher.init()

/**
 * Initialize your Manager 
 * (settings will propagate to OPTLYClient and Optimizely)
 */
 let manager = OPTLYManager(builder: OPTLYManagerBuilder(block: { (builder) in
  builder?.sdkKey = "SDK_KEY_HERE"
  builder?.eventDispatcher = customEventDispatcher
 }))

The included event handler implementation, OptimizelySDKEventDispatcher, includes queueing and flushing, so will work even if an app is offline. You will need to implement OPTLYEventDispatcher to use your own event handler.