Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

track's callback called before request were sent #433

Open
Pavel-Liteiniy opened this issue Jul 16, 2024 · 3 comments
Open

track's callback called before request were sent #433

Pavel-Liteiniy opened this issue Jul 16, 2024 · 3 comments

Comments

@Pavel-Liteiniy
Copy link

Hello! : )

I'm not sure that this is correct behavior

  1. initializing mixpanel with persistence: 'localStorage'
    mixpanel.init(token, {
      persistence: 'localStorage',
      persistence_name: 'mixpanel',
    })
  1. 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:

image
@tdumitrescu
Copy link
Member

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.

@josuemy
Copy link

josuemy commented Nov 17, 2024

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

@tdumitrescu
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants