Movatterモバイル変換


[0]ホーム

URL:


Dev guideRecipesAPI ReferenceChangelog
Dev guideAPI ReferenceRecipesChangelogUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog InFeature Experimentation
Dev guide
All
Pages
Start typing to search…

Configure the Java SDK event dispatcher

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

The Optimizely Feature Experimentation SDKs make HTTP requests for everydecision event or conversion event that gets triggered. Each SDK has a built-inevent 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.

import com.optimizely.ab.Optimizely;import com.optimizely.ab.config.parser.ConfigParseException;import com.optimizely.ab.event.AsyncEventHandler;import com.optimizely.ab.event.EventHandler;/** * Creates an async event handler with a max buffer of *  20,000 events and a single dispatcher thread */EventHandler eventHandler = new AsyncEventHandler(20000, 1);Optimizely optimizelyClient;try {    // Create an Optimizely client with the default event dispatcher    optimizelyClient = Optimizely.builder(datafile,                                          eventHandler).build();} catch (ConfigParseException e) {    // Handle exception gracefully    return;}

The event dispatcher should implement adispatchEvent function, which takes in three arguments:httpVerb,url, andparams, all of which are created by the internalEventBuilder class. In this function, you should send aPOST request to the givenurl using theparams 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 will alter your results.

We provide an asynchronous event dispatcher,optimizely-sdk-httpclient, that requiresorg.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 thedispatchEvent method in ourEventHandler interface.dispatchEvent takes in aLogEvent object containing all of the information needed to dispatch an event to the Optimizely Feature Experimentation backend. Events should be sent toLogEvent.getEndpointUrl as aPOST request withLogEvent.getBody as the payload andcontent-type: "application/json" as the header.

Updated 17 days ago



[8]ページ先頭

©2009-2025 Movatter.jp