There is nothing wrong with your code.
The callback
parameter works for other endpoints like .../events/top
and .../funnels/list
, but this error is returned for this particular engage
endpoint.
You will have to raise this as an issue with Mixpanel, that this endpoint does not support JSONP callbacks.
Somewhat confusingly, you can post data using a different engage
endpoint, by following the instructions on this page:
https://mixpanel.com/docs/people-analytics/people-http-specification-insert-data
Here is an example that works with this endpoint:
var mixpanel_token = "<insert token for your mixpanel project here>";
var myData = { "$set": {
"$first_name": "John",
"$last_name": "Smith" },
"$token": mixpanel_token,
"$distinct_id": "99999",
"$ip": "0" };
var dataEncodedToBase64 = window.btoa(JSON.stringify(myData));
var path = 'http://api.mixpanel.com/engage?callback=?';
$.getJSON(path, { 'data': dataEncodedToBase64, 'verbose': 1 }, function(json) {
console.log("Success");
console.log(json);
});
Just note that your code should work for the other endpoints in the link you provided in your question, just not for engage
.