This release adds opt-in support for sending events and people/group updates in batched network requests, with backup mechanisms for retrying in case of network failures and other errors. In this mode of operation, calls to mixpanel.track()
will not immediately result in a network request; instead the data is placed in a queue, and at regular intervals the available queued data is sent over the network. In cases of network failures, dirty page closures, etc., the queued data remains stored in the browser's localStorage and will be sent in retry requests.
This mode results in fewer network requests and reduces potential data loss in cases where the browser cannot communicate successfully with the Mixpanel API (e.g., when a user loses network connectivity temporarily). It requires that the user's browser supports the localStorage
API; if localStorage is not present or functional, the SDK will fall back to the old immediate-request mode.
To enable this mode, initialize the SDK with the configuration flag batch_requests
set to true:
mixpanel.init('my token', {batch_requests: true});
Other configuration options are available to control the timing and size of batches:
batch_size
: maximum number of events/updates to send in a single network request (default: 50)batch_flush_interval_ms
: milliseconds to wait between checking for batch requests to send (default: 5000 = 5 seconds)batch_request_timeout_ms
: milliseconds to wait for network responses to batch requests before they are considered timed-out and retried (default: 90000 = 90 seconds)
In a future release, this mode will be enabled by default.