Table Of Contents

Previous topic

23.20. The NotificationsManager Object

Next topic

24. Protolib API

This Page

23.21. The CustomMetricEventBatch Object

The CustomMetricEventBatch object provides a way to batch up groups of custom metric events allowing an application to reduce the number of required api calls to submit it’s custom metrics events.

Required scripts

The CustomMetricEventBatch object requires:

/*{{ javascript("jslib/services/turbulenzservices.js") }}*/

23.21.1. Methods

23.21.1.1. create

Summary

Creates a new custom metric event batch

Syntax

var customMetricEventBatch = CustomMetricEventBatch.create();

Each custom metric event batch can hold a number of custom metric events and can be sent to the servers using TurbulenzServices.sendCustomMetricEventBatch

23.21.1.2. push

Summary

Push a new custom metric event into a batch

Syntax

customMetricEventBatch.push(eventKey, eventValue);
eventKey
A JavaScript string. The event key you want to track this event occurrence against, e.g. ‘levelOneCompleted’.
eventValue
An JavaScript number or array of numbers. The event value you want to associate with this event occurrence, e.g. the time taken to complete the level.

The push method allows you to store an additional metric in the custom metric event batch to be sent to servers at a later time.

23.21.1.3. length

Summary

Get the number of custom metrics in the current batch

Syntax

if (customMetricEventBatch.length() > maxMetricsToBatch)
{
    TurbulenzServices.sendCustomMetricEventBatch(customMetricEventBatch, ...);
}

The length method allows you to track how many metrics have been pushed into a batch to determine when you wish to flush it to the servers.

23.21.1.4. clear

Summary

Clear any stored metrics from the batch

Syntax

customMetricEventBatch.clear();

After sending a batch of custom metric events to the servers with the TurbulenzServices.sendCustomMetricEventBatch method the CustomMetricEventBatch object can be reused. Calling clear will empty the batch and reset its length to 0 allowing it to be reused, this reuse can help memory performance avoid extra object creation. If you wish to ignore metrics already pushed onto the batch but not sent this method can also be used to discard them.