Code Monkey home page Code Monkey logo

Comments (22)

tdumitrescu avatar tdumitrescu commented on June 14, 2024 1

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?

from mixpanel-js.

tdumitrescu avatar tdumitrescu commented on June 14, 2024

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:

  • if you do implement both of these, please keep them in separate pull requests
  • for localStorage vs cookie stores, maintain backwards compatibility by offering localStorage as a config option and keeping cookie as the default; so you would init the lib somewhat like: mixpanel.init(TOKEN, {storage: 'localStorage'});
  • for offline support, you'll want to queue up requests and then send batched updates (https://mixpanel.com/help/reference/http#batch-requests) of max 40 events at a time. the code of our ios lib offers a good model.

Let us know if you have more questions!

from mixpanel-js.

sandorfr avatar sandorfr commented on June 14, 2024

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.

from mixpanel-js.

tdumitrescu avatar tdumitrescu commented on June 14, 2024

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?

from mixpanel-js.

sandorfr avatar sandorfr commented on June 14, 2024

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.

from mixpanel-js.

tdumitrescu avatar tdumitrescu commented on June 14, 2024

That would be very welcome!

from mixpanel-js.

sandorfr avatar sandorfr commented on June 14, 2024

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.

from mixpanel-js.

sandorfr avatar sandorfr commented on June 14, 2024

I've added a pull request with the localStorage alternative to cookies.

from mixpanel-js.

KeKs0r avatar KeKs0r commented on June 14, 2024

@sandorfr I see that you already solved one of the two problems for good cordova support. Did you also tackle the queue topic?

from mixpanel-js.

sandorfr avatar sandorfr commented on June 14, 2024

@KeKs0r I have not yet started it.

from mixpanel-js.

mobidev111 avatar mobidev111 commented on June 14, 2024

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?

from mixpanel-js.

mobidev111 avatar mobidev111 commented on June 14, 2024

alternative approach here:
https://github.com/skotzko/mixpanel-event-queue

from mixpanel-js.

tdumitrescu avatar tdumitrescu commented on June 14, 2024

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.

from mixpanel-js.

sandorfr avatar sandorfr commented on June 14, 2024

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.

from mixpanel-js.

jskrepnek avatar jskrepnek commented on June 14, 2024

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'.

See:

var HTTP_PROTOCOL = (('https:' === document.location.protocol) ? 'https://' : 'http://');

from mixpanel-js.

sandorfr avatar sandorfr commented on June 14, 2024

@jskrepnek interesting, and it looks like this is not configurable yet.

from mixpanel-js.

jskrepnek avatar jskrepnek commented on June 14, 2024

@sandorfr I've successfully patched it in place, but that's far from ideal.

from mixpanel-js.

jskrepnek avatar jskrepnek commented on June 14, 2024

@tdumitrescu That's great, thanks. I'd suggest adding that configuration option to the Javascript Full API Reference.

from mixpanel-js.

jskrepnek avatar jskrepnek commented on June 14, 2024

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.

from mixpanel-js.

tdumitrescu avatar tdumitrescu commented on June 14, 2024

Good call, will need to add it here.

from mixpanel-js.

tdumitrescu avatar tdumitrescu commented on June 14, 2024

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.

from mixpanel-js.

jfbloom22 avatar jfbloom22 commented on June 14, 2024

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.

from mixpanel-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.