In this article, you’ll learn: |
Event Batching enables VWO SDK to process the events for visitors and goal tracking, place them in a queue, and dispatch them in a single network request to the VWO servers, i.e., SDK collects the number of events over a period of time and then dispatch them to the VWO servers. For example, if there are 4000 events, SDK collects them, adds them to a queue, and sends them to VWO servers in one network request. This is what Event Batching in VWO FullStack does for you.
To better understand the concept of Event Batching in VWO FullStack, consider the following scenario.
Assume that, on average, 1000 visitors land on your website in a day. Now you wish to track these visitors and the corresponding conversions. Let's take a look at the different options that VWO offers to accomplish this.
One way to track visitors and conversions is to trigger one API request for each visitor to the VWO server, i.e., a one-to-one mapping between the visitor and an API request to the server. The advantage of this implementation is that you get real-time reporting, i.e., the events appear instantly in the report.
Another way to track visitors and conversions is by processing the events, placing them in a queue, and dispatching them in a single network request to the VWO servers. This is done using Event Batching in VWO FullStack. SDK collects the events, places them in a queue, and sends them to VWO servers in a single network request. It’s that simple.
It typically eliminates the overhead of sending individual requests for tracking each visitor or goal. With this implementation, the campaign reports will only be updated once the batch events request is sent from the SDK to VWO. This may take a few seconds to reflect in the report depending on the batch size.
To learn how to configure Event Batching, refer to Configure Event Batching in VWO FullStack.
Advantages of Using Event Batching
- It brings in efficiency, i.e., SDK will have to send fewer network requests for tracking visitors or goals.
- Increases flexibility in sending events to the VWO server, i.e., to send events, you have the option to configure the batch size (number of events) or the time interval.
- Reduce the total transmitted data by extracting common properties in every event and sending them once per batch network request.
- Allow flushing of events data in the queue if you want to reflect that data in VWO reporting dashboards (before the batch size/ time interval is reached) or prevent data loss if your server needs to restart. To know more about this, refer to Want to Send the Data to VWO Servers Before the Batch Size/Time Interval is Reached?
Configure Event Batching in VWO FullStack
VWO offers two configuration options for sending events to the VWO servers. You can configure the Event Batching while instantiating the SDK by passing the batch events configuration key along with one or both of the Event Batching options.
- Events per Request - Specify the number of events that should be batched together and sent to the VWO server in a single network request. Until this number is not reached, all events will be queued.
NOTE:
1. The maximum number of events that can be queued at a time is 5000. The maximum payload size is 10 MB.
2. Based on the batch size, the events may take a few seconds to reflect in the report. - Request Time Interval - Specify the time interval at which the event batches are sent to the server.
NOTE: Time starts after the first event is added to the queue. For example, if the time interval starts at nth time and the first event occurs at (n + 5)th time, the timer will start from (n + 5)th time and will be cleared once the queue is flushed.
Things to Consider While Configuring Event Batching
You must consider the following while you are configuring Event Batching in VWO:
- If the only eventsPerRequest is provided, the requestTimeInterval is set to a default value of 600(10 minutes).
- If the only requestTimeInterval is provided, the eventsPerRequest is set to a default value of 100 events.
- If both eventsPerRequest and requestTimeInterval are specified, SDK will send a batch request based on the first event. For example, if the count of events exceeds the limit first, the batch request is sent, and the timer is reset; if the time has passed without the required events being filled in, a batch request is sent, the queue is cleared, and the timer is reset.
What Happens When the Batch Limit is Reached?
If the number of events in the batch exceeds the limit, viz., 5000 events, the VWO server will reject the request with status code 413 Payload Too Large. To fix this, we recommend that you try with a smaller event number by reducing eventsPerRequest or set a shorter time interval via requestTimeInterval.
Furthermore, VWO SDKs also provide a functionality to call a function upon success/failure of batch network requests to the VWO server. You can do this by passing flushCallback in batch events configuration at the time of launching the SDK.
To configure the flushCallback, use the following code snippet:
Want to Send the Data to VWO Servers Before the Batch Size/Time Interval is Reached?
The default behaviour of sending data to the VWO servers is that all events are queued until the batch size is not reached. But what if you wish to send the data before the batch size limit is reached? This can be accomplished using the Flush Events API.
Assume that your batch size is 2000, and currently, there are only 700 events in the queue, and you wish to view the data of these 700 events in the report without waiting for the batch size to reach its limit, i.e., 2000.
To achieve this, you can flush the queue using the Flush Events API. This way, a network call with 700 events (or whatever was the number of events in the queue at the time of flush) will go to the VWO servers, and the same will start reflecting in the reports.
To configure the flushEvents API, use the following code snippet:
To learn more about the technical aspects of Event Batching in VWO, refer to this.