setDispatchInterval

The setDispatchInterval() method sets a custom dispatch interval. Tracked events are temporarily stored in a queue and sent in batches. By default, batches are sent every 30 seconds (30000 milliseconds).

Syntax

tracker.dispatchInterval = milliseconds
getTracker().setDispatchInterval(milliseconds);

Parameters

milliseconds (number, required)

The interval time (in milliseconds) for dispatching tracked events. If 0 milliseconds, events will be sent right away. If -1 milliseconds, events won’t be sent automatically and can be send manually.

Examples

To set the dispatch interval time to 60 seconds (60x1000 milliseconds):

tracker.dispatchInterval = 60 * 1000
getTracker().setDispatchInterval(60 * 1000);

To block sending events automatically and send them manually:

val tracker: Tracker = (application as PiwikApplication).tracker
tracker.dispatchInterval = -1
// Catch and track exception
try {
  cartItems = tracker.getCartItems()
} catch (e: java.lang.Exception) {
  TrackHelper.track().exception(e).description(e.message)
  tracker.dispatch()
  cartItems = null
}
Tracker tracker = ((PiwikApplication) getApplication()).getTracker();
tracker.setDispatchInterval(-1);
// Catch and track exception
try {
  cartItems = getCartItems();
} catch (Exception e) {
  TrackHelper.track().exception(e).description(e.getMessage());
  tracker.dispatch();
  cartItems = null;
}

Notes

  • If more than one event is queued, the data is sent in bulk using the POST method with a JSON payload.