samzilverberg/cordova-mixpanel-plugin

Set `serverURL` param (for EU Data Residency)

Opened this issue ยท 8 comments

Is it somehow possible to set the server URL as configuration of this plugin?

Mixpanel explains it in the Objective-C documentation like this:

[Mixpanel sharedInstanceWithToken:@"xxx"];
self.mixpanel.serverURL = @"https://api-eu.mixpanel.com";

See here: https://developer.mixpanel.com/docs/ios#eu-data-residency

For Android, I should be able to do it with AndroidManifest.xml adjustments:
https://developer.mixpanel.com/docs/android#eu-data-residency

This sounds nice but I don't have the time to try it out myself atm.
I spent 5-10 mins to read a little and write down some pointers in case you want to try it out on your own (and possibly contribute it back :) ).

cordova plugins can use some user input variables, documented here:
https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html#preference

you can add another variable for your server URL in the same way and then adjust android manifest file using one of the following:

this plugin has an example for FIREBASE_VERSION you can look up.

for ios it looks more tricky because this url needs to be set in-code (not in config like android) on the mixpanel instance after its initialized.
so maybe some specific function needs to be created for this in src/www/mixpanel.js and in src/ios/MixpanelPlugin.h (and .m).

๐Ÿ™ for your investigation . I'll give it a shot ๐Ÿ‘

Have you found a solution how to do it on iOS?

@klemensz We moved away from this plugin, as the Mixpanel SDK is not updated and it's also not possible to override the IOS version, since the IOS SDK is packed in the code instead of installing it as a Cocoa pod. There were some major changes in the SDK so I would highly recommend to update.

Nevertheless, it's fairly easy to implement this and we did for the plugin we use now (see merge request: https://github.com/houseninjadojo/capacitor-mixpanel/pull/8/files). The plugin is for Ionic Capacitor and not Cordova, though.
So passing the serverUrl to init and adjust that function to set it on initialisation would be enough. Also cleaner for Android.

@chvonrohr Thanks, I need the plugin for Capacitor anyway. So you suggest it's better to use https://github.com/houseninjadojo/capacitor-mixpanel instead?

The features I need are:

  • .track()
  • .identify()
  • .reset()
  • setting serverUrl (for EU) - the MR you linked is still open?

I prefer Capacitor plugins, as they are bit more lightweight and additionally support PWA (what we don't need at the moment, but you never know ;))

Your needs are covered, as you wrote except the serverUrl. We hope our PR is merged soon, otherwise we propose this fork for the @capacitor/community and maintain it our selfs

I don't think that you will get PWA support with Capacitor plugins because they usually only support Android and iOS platforms. Some Cordova plugins support a "browser" platform but this has become obsolete (with newer versions of Ionic and Cordova). I know it because we build for all three platforms (web/PWA, Android, iOS). The route that I went for PWA is to additionally include the mixpanel-browser library and then have platform checks in the code to either call the native or browser plugin.

The good thing on capacitor is that it supports Android, IOS and PWAs.
And this plugin has the mixpanel-browser library already included and implemented (see also package.json), so it works the same way as you use it on IOS and Android

BTW: just tested and works. only difference for browser is, that you need to do Mixpanel.initialize