mixpanel / mixpanel-js

Official Mixpanel JavaScript Client Library
https://mixpanel.com/help/reference/javascript
Other
885 stars 312 forks source link

There is a mismatch between library support and HTTP specification #241

Open sachinmour opened 4 years ago

sachinmour commented 4 years ago

According to https://developer.mixpanel.com/docs/http GET requests are used for single event tracking and POST requests are used for multiple event tracking which will send an array of events.

But the mixpanel-js library itself uses POST request by default to send a single event. Also there is no way to send multiple events directly using mixpanel-js.

It would be nice to have some clarification on this.

tdumitrescu commented 4 years ago

Sorry it's not as clear as it should be. The HTTP doc you linked says "The Mixpanel HTTP tracking API accepts POST and GET requests" - and what that means is that either one can be used for the exact same types of requests, the only difference being whether the payload is encoded as a URL param or in the request body. Either one will work for any number of events. The only difference between tracking a single event vs multiple events is that you can send a single event without putting it in a JSON array, but that's basically a shorthand for the sake of convenience.

This library will soon support batching multiple events into a single request, but that happens behind the scenes. You'll still need to make a .track() call for each event.

sachinmour commented 4 years ago

ah ok. Is there a specific reason as to why we prefer POST request over GET. I am assuming because of payload limit on GET. Also in the documentation it's not clear how the retry mechanism work or if it works. If you can elaborate, i can make a pull request to update the documentation.

tdumitrescu commented 4 years ago

The most compelling reason is indeed that you can send a much larger payload in the request body, pretty much a necessity if you're going to send event batches at once.

The SDK currently doesn't have any built-in retries. This is something we're releasing soon as part of a batching/queueing infrastructure, but it should be basically transparent to the developer. You'll still simply be calling mixpanel.track(), and the SDK will do its best to make sure the data makes it to our API servers even if there's a temporary problem, device is currently offline etc.