Open sandorfr opened 9 years ago
Hi, thanks so much for pointing out the issues and potential solutions. Offline support and alternatives to cookie-based tracking would be awesome. Unfortunately there's nothing concrete currently on the roadmap, so pull requests are probably the quickest path to seeing the features you need. A few notes:
mixpanel.init(TOKEN, {storage: 'localStorage'});
Let us know if you have more questions!
Hi, yes there is one thing. I'm struggling running tests do you have any guidance on that? My issue seems to be related with cookie_included getJson calls (which are failing with a 404).
Update : I was able to run them using a basic nodejs server. I still have some tests failing because i'm not returning the expected value. So I guess there is actually something missing from this repository to enable testing.
Apologies for that; the tests do rely on an external server resource which wasn't included when the lib was open-sourced. I've been meaning to add a little Node server to the repo to handle that. The Django code for it looks basically like:
def test_cookie_included(request, cookie_name):
return json_response(request, 1 if cookie_name in request.COOKIES else 0)
so the response is 1 when the cookie has been set and 0 otherwise. Does that help?
It does help :) Actually I wrote a basic nodejs/express server which I will update with using that information. I can submit another PR for that too if you want.
That would be very welcome!
Just submitted a PR about the test server. I still have some work to do about localStorage to make it clean but I'm on it.
I've added a pull request with the localStorage alternative to cookies.
@sandorfr I see that you already solved one of the two problems for good cordova support. Did you also tackle the queue topic?
@KeKs0r I have not yet started it.
here's a queue implementation: http://meltuhamy.com/dev/offline-resilient-mixpanel-tracking-for-ionic-without-a-cordova-plugin/ https://github.com/meltuhamy/belfastsalah/blob/master/www/js/svc/mixpanel.js
@sandorfr @tdumitrescu any chance to take on this in the foreseeable future? similarly to what you did with the localstorage support?
alternative approach here: https://github.com/skotzko/mixpanel-event-queue
The best way to push a feature like this forward is with a pull request, otherwise it's largely a matter of us prioritizing the request against a whole pile of other internal development work, which means a longer wait. I'm happy to discuss ideas if you want to validate an approach before submitting code.
Hi @mobidev111, I don't MEQ is going to be of any help when it comes to offline support because this is using in Memory storage.
I was considering implementing a queue on top of IndexedDb and then batch the events. Since reinventing the wheel is not going to help I think it might be interresting to take a look at this : https://github.com/orthecreedence/hustle.
That being said there is some work and a lot of testing to be done to get something which could be merged here, and I'm also prioritizing things on my side. So unless someone makes it a priority for me I'm very short on time atm.
To add another consideration for Cordova support, it looks like in all scenarios mixpanel will default the protocol to 'http' rather than 'https', since the protocol is actually 'file'.
@jskrepnek interesting, and it looks like this is not configurable yet.
@sandorfr I've successfully patched it in place, but that's far from ideal.
It is currently configurable to the extent that you can specify the entire api host string in the config, though it's certainly not ideal:
mixpanel.init('MY TOKEN', {
api_host: 'https://api.mixpanel.com'
});
What would be the most useful means of configuration for you?
@tdumitrescu That's great, thanks. I'd suggest adding that configuration option to the Javascript Full API Reference.
Would it make sense to make 'https' the default, rather than 'http'? That way scenarios like cordova where the protocol is 'file' would default the safe way.
Good call, will need to add it here.
Yeah, we'll have to think about potential implications for backwards-compatibility with switching the default, though it seems safe to me off the top of my head.
I believe this issue can be closed. I am using Mixpanel in several Cordova apps at this point. If you are using bower and your app goes offline: notice the section titled: Using Bower to load the entire library which explains how to load Mixpanel without the CDN. This will allow it to pass the CSP for Chrome:extensions as well.
Side note: the instructions are slightly wrong. mixpanel.js
does not exist. It should be mixpanel.min.js
.
Do you have plans regarding cordova support?
There are two main concerns when it comes to cordova support using mixpanel-js:
There is a simple workaround for the first one which consists of replacing the current cookie implementation by a localstorage based implementation. Currently this is dirty but I can work on a pull request if you are interested.
I don't have worked yet on the second issue but I think we can build a local storage solution too. I think this would be awesome for cordova but this would help people who build websites with offline support too.