Pregunta

I need to use mixpanel Data Export API using jQuery.
According to this: How can I use mixpanel API? and according to mixpanel: https://mixpanel.com/docs/api-documentation/data-export-api#libs-js, I can use this:

$.getJSON('http://mixpanel.com/api/2.0/engage/?callback=?', {
        api_key: apiKey,
        expire: expire,
        sig: sig
    },
    function (result) {
        alert(result);
    }
);

But as a result I get an error as result:

"unknown param: callback
for params: {'callback': 'jQuery18208090281161325954_1358248117308', 'project_id': 160130}"

I know that the url and my data is correct since when I open browser in http://mixpanel.com/api/2.0/engage/?api_key=...&expire=...&sig=... I get correct data.

What is wrong with my code?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top