track's callback called before request were sent
Hello! : )
I'm not sure that this is correct behavior
- initializing mixpanel with
persistence: 'localStorage'
mixpanel.init(token, {
persistence: 'localStorage',
persistence_name: 'mixpanel',
})
- Trying to track event
mixpanel.track('my event', undefined (response) => {...handling error response...})and expecting to get error if smth went wrong
export function track(
event_name: string,
properties?: Dict,
optionsOrCallback?: RequestOptions | Callback,
callback?: Callback, <-- I'm want to handle error response here (for example { "error": "token, invalid format", "status": 0 })
): void;
If I track event without setting RequestOptions['send_immediately'] equals to true then my callback is called before request to mixpanel has been finished here:
Yes, in the default mode, track requests are batched and sent over the network at regular intervals. The track() callback is executed when the event is enqueued for transfer, while the actual network-sending mechanism is separate and occurs on a timer. We don't currently expose any callback from the network side of the tracking code.
Yes, in the default mode, track requests are batched and sent over the network at regular intervals. The
track()callback is executed when the event is enqueued for transfer, while the actual network-sending mechanism is separate and occurs on a timer. We don't currently expose any callback from the network side of the tracking code.
@tdumitrescu if send_immediately: true is passed in the options does the callback execute when the event gets sent (not enqueued)? Also, are there any docs that talk more about this? Thanks
@josuemy yes, with send_immediately there is no enqueueing, and the callback should fire when the network request returns. I don't know of any docs around this atm.