NOTE: We have upgraded our Wingify FullStack and Mobile Testing products into a more powerful and unified solution: Feature Experimentation. The legacy products are now deprecated for new users. To learn more about our new offering, refer to Getting Started with Feature Experimentation.
In this article, you’ll learn:
- The concept of Event Batching in Wingify
- Advantages of using Event Batching
- Things to consider while working with Event Batching
- How you can configure Event Batching in Wingify
- What Happens When the Batch Limit is Reached?
- How to send the data to Wingify servers before the batch size/time interval is reached?
About Event Batching in Wingify
Event Batching enables Wingify 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 Wingify servers, i.e., SDK collects the number of events over a period of time and then dispatch them to the Wingify servers. For example, if there are 4000 events, SDK collects them, adds them to a queue, and sends them to Wingify servers in one network request. This is what Event Batching in Wingify FullStack does for you.
Note: Event Batching can send the events for visitors and conversion tracking.
To better understand the concept of Event Batching in Wingify 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 Wingify offers to accomplish this.
NOTE: To track visitors, use the Activate API, whereas to track conversions, use Track API.
One way to track visitors and conversions is to trigger one API request for each visitor to the Wingify 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.
INFO: We recommend using this when you want to see real-time reporting.
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 Wingify servers. This is done using Event Batching in Wingify FullStack. SDK collects the events, places them in a queue, and sends them to Wingify 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 Wingify. 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 Wingify 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 Wingify 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 Wingify 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 Wingify Servers Before the Batch Size/Time Interval is Reached?
Configure Event Batching in Wingify FullStack
Wingify offers two configuration options for sending events to the Wingify 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.
Note: As of now, Event Batching is available in Node.js SDK and Python SDKs.
Events per Request - Specify the number of events that should be batched together and sent to the Wingify 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 Wingify:
- 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 Wingify 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, Wingify SDKs also provide a functionality to call a function upon success/failure of batch network requests to the Wingify 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:
var settingsFile = await vwoSdk.getSettingsFile(accountId, sdkKey);
vwoSdk.lanuch({
settingsFile: settingsFile,
batchEvents: {
eventsPerRequest: 1000, // specify the number of events
flushCallback: (err, events) => console.log(err, events)
}
});Want to Send the Data to Wingify Servers Before the Batch Size/Time Interval is Reached?
The default behaviour of sending data to the Wingify 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.
Info: We recommend using the Flush Events API to prevent data loss if your server needs to restart.
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 Wingify servers, and the same will start reflecting in the reports.
To configure the flushEvents API, use the following code snippet:
var settingsFile = await vwoSdk.getSettingsFile(accountId, sdkKey);
var vwoClientInstance = vwoSdk.launch({
settingsFile: settingsFile,
batchEvents: {
eventsPerRequest: 1000, // specify the number of events
flushCallback: (err, events) => console.log(err, events)
}
});
// Example usage of flushEvents API
// Node.js events - SIGINT(ctr-c), SIGTERM otherwise
process.on('SIGINT', async () => {
console.log('SIGINT signal received.');
vwoClientInstance.flushEvents().then(data => {
console.log('data', data); // if anything to do with data
process.exit(0); // gracefully shutdown
});
});To learn more about the technical aspects of Event Batching in Wingify, refer to this.