---
title: Event batching for the JavaScript (Browser) SDK prior to v6
slug: feature-experimentation/docs/event-batching-javascript-prior-to-v6
docTags: 
createdAt: 2026-08-05T20:39:52.000Z
---

The [Optimizely Feature Experimentation Javascript (Browser) SDK](https://github.com/optimizely/javascript-sdk) lets you batch events and includes options to set a maximum batch size and flush interval timeout. The benefit of event batching is less network traffic for the same number of Impression and conversion events tracked.

:::hint{type="info"}
**Note**
By default, event batching is enabled in JavaScript (Browser) SDK version 3.3.0 or newer.

Event batching works with both out-of-the-box and custom event dispatchers.

The event batching process does not remove any personally identifiable information (PII) from events. You must still ensure that you are not sending any unnecessary PII to Optimizely.
:::

## Basic example

Optimizely provides two options to configure event batching: `eventBatchSize` and `eventFlushInterval`. You can pass in both options during client creation. Events are held in a queue until either:

- The number of events reaches the defined `eventBatchSize`.
- The oldest event has been in the queue for longer than the defined `eventFlushInterval`, which is specified in milliseconds. The queue is then flushed and all queued events are sent to Optimizely in a single network request.
- A new datafile revision is received. This occurs only when live datafile updates are enabled.

```javascript
import { createInstance } from '@optimizely/optimizely-sdk';

const optimizely = createInstance({
  // other options
  eventBatchSize: 100,
  eventFlushInterval: 3000,
});
```

By default, batch size is 10 and flush interval is 1 second.

:::hint{type="danger"}
**Warning**
The maximum payload size is 3.5 MB. Optimizely rejects requests with a 400 response code, `Bad Request Error`, if the batch payload exceeds this limit.

The size limitation is because of the [Optimizely Events API](docId:822ZQOB6Zk2-kWJKavBvA), which Feature Experimentation uses to send data to Optimizely.

The most common cause of a large payload size is a high batch size. If your payloads exceed the size limit, try configuring a smaller batch size.
:::

The following table defines these options and lists general recommendations. On the browser you should using a small `eventBatchSize` (10) and a short `eventFlushInterval` (1000). This ensures that events are sent in a relatively fast manner, because some events could be lost if a user immediately bounces, while gaining network efficiency in cases where many decisions calls happen back-to-back.

| Name                   | Description                                                                                                    | Recommend Value |
| ---------------------- | -------------------------------------------------------------------------------------------------------------- | --------------- |
| **eventBatchSize**     | Maximum size of batch of events to send to Optimizely. Default: 10                                             | 10              |
| **eventFlushInterval** | The maximum duration in milliseconds that an event can exist in the queue before being flushed.\ Default: 1000 | 1000            |

For information, see [Initialize the JavaScript (Browser) SDK](docId\:nHER9yNaUuV3aw35WcbhJ).

## Side effects

The following table describes other functionality related to event batching.

| Functionality              | Description                                                                                                                                                                                                                                                                                                                     |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **LogEvent**               | Whenever the event processor produces a batch of events to be dispatched, a LogEvent notification object is created, which contains the batch of conversion and decision events. This object is dispatched using the provided event dispatcher and also it is sent to the notification subscribers (see the following section). |
| **Notification Listeners** | LOG\\\_EVENT \[notification listeners]\(https\://docs.developers.optimizely.com/feature-experimentation/docs/set-up-notification-listener-javascript) are triggered when a \`LogEvent\` is passed to the event dispatcher                                                                                                       |

### Register a `LogEvent` listener

To register a `LogEvent` notification listener:

```javascript
// Using notificationCenter to register logEvent listener

optimizely.notificationCenter
  .addNotificationListener(optimizelyEnums.NOTIFICATION_TYPES.LOG_EVENT, (logEvent) => {});
```

### `LogEvent`

Represents the batch of decision and conversion events sent to the Optimizely backend.

| Parameter    | Description                                         |
| ------------ | --------------------------------------------------- |
| **url**      | URL to dispatch log event to                        |
| **httpVerb** | The HTTP verb to use when dispatching the log event |
| **params**   | Contains the event batch                            |

## Close Optimizely on application exit

If you enable event batching, **you must** call the Close method (`optimizely.close()`) before exiting. This ensures that queued events are flushed when possible to avoid any data loss.

:::hint{type="info"}
**Warning**
Because the Optimizely client maintains a buffer of queued events, you must call `close()` on the Optimizely instance before shutting down your application or whenever dereferencing the instance.
:::

| Method      | Description                                                                                                                                       |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| **close()** | Stops all timers and flushes the event queue. This method will also stop any pending timers or in-flight requests related to datafile management. |

On the browser side, optimizely.close() is automatically connected to the [pagehide event](https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event), so there is no need to do any manual instrumentation.
