Issues when running Mixpanel API in Ionic app

We’re trying to implement an app that uses Mixpanel to send data when the users change between different views in the app, in order to see how many users drop off at each step before the purchase is done, using angular-mixpanel. This works great when testing locally with ionic serve, unfortunately it does not longer work when I run it on my Galaxy S3. Nothing is reported to the mixpanel server when I change views. I have tested the program with packet capture, and it does appear that no data is sent to the mixpanel servers at all, so the $mixpanel.track function calls do nothing, even though the rest of the controller code works just fine. Oddly enough, it did work earlier when I run the program with “ionic run android -l -s -c” with an added console.log for the $mixpanel.track output.

I’m running Ionic 1.5.0 and Cordova 5.1.1. The test phone is a standard Samsung Galaxy S3 with Android 4.3.

It appears that I have found a solution myself, it required a small change to an official Mixpanel Javascript file, more specifically mixpanel-jslib-snippet.js (or its minified version, but I’ll explain in the more readable version).

The file begins with

var MIXPANEL_LIB_URL = '//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js';

I hadn’t seen an URL begin with plain // before, so I tried changing to the more familiar

var MIXPANEL_LIB_URL = 'http://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js';

Now it works just fine.

2 Likes

This makes sense. Not including http/s will make the browser thing that this file is located on the device.

Host the mixpanel js locally https://github.com/mixpanel/mixpanel-js/blob/master/mixpanel.min.js

1 Like