We have an issue where we create our MixpanelAPI object when a user logs in and based on that we determine what server to send the data to and what token to use. I found an issue where if I log in as an EU user we call setServerURL for the EU endpoint and use our EU token. I log an event and everything looks great. If I then logout and log in as a US user and log the same event it will show up in US account as expected but the API endpoint will still be the EU endpoint. I can replicate the same thing in the opposite order if I do it the other way around.
To make this issue more confusing the below sample is C# as this is a .NET MAUI app so the code may not match for what you expect to see in a Java app. I have bindings for iOS and Android for us to use this native SDKs in our .NET app. Our iOS app does not have this issue. It should also be noted that my Android bindings only go up to v8.5.2 as the next version adds the common library and I have not added support for that version. It does not appear that anything in the changelog would indicate that it was fixed since then.
Here is an example of something I'd expect to work.
var token = "euToken";
var mixpanel = MixpanelAPI.GetInstance(Platform.CurrentActivity, token, false);
mixpanel.SetEnableLogging(true);
mixpanel.SetServerURL("https://api-eu.mixpanel.com");
mixpanel.Track("TEST: This should be in EU");
mixpanel.Flush();
mixpanel.Reset();
mixpanel.Dispose();
mixpanel = null;
token = "usToken";
mixpanel = MixpanelAPI.GetInstance(Platform.CurrentActivity, token, false);
mixpanel.SetEnableLogging(true);
mixpanel.SetServerURL("https://api.mixpanel.com");
mixpanel.Track("TEST: This should be in US");
mixpanel.Flush();
mixpanel.Reset();
mixpanel.Dispose();
mixpanel = null;
I did try to re-create this is kotlin using 8.8.0 but it appears to not send to the US region
val mixpanelOptionsEU: MixpanelOptions = MixpanelOptions.Builder()
.serverURL("https://api-eu.mixpanel.com")
.build()
var mixpanelEU: MixpanelAPI? = MixpanelAPI.getInstance(this, "yyyyyyyy", false, mixpanelOptionsEU)
mixpanelEU?.setEnableLogging(true)
mixpanelEU?.track("TEST 2: This should be in EU")
mixpanelEU?.flush()
mixpanelEU?.reset()
mixpanelEU = null
val mixpanelOptionsUS: MixpanelOptions = MixpanelOptions.Builder()
.serverURL("https://api.mixpanel.com")
.build()
var mixpanel2: MixpanelAPI? = MixpanelAPI.getInstance(this, "xxxxxxxx", false, mixpanelOptionsUS)
mixpanel2?.setEnableLogging(true)
mixpanel2?.track("TEST 2: This should be in US")
mixpanel2?.flush()
mixpanel2?.reset()
mixpanel2 = null;
What I did notice is that mixpanelEU and mixpanelUS are the same object. I think this is expected because it is a singleton. However what I don't think is expected is that the underlying HttpService object is not re-created after it is first created. If setServerUrl is called it does not pass that information through to the HttpService resulting in nothing actually changing after it is first set.
We have an issue where we create our
MixpanelAPIobject when a user logs in and based on that we determine what server to send the data to and what token to use. I found an issue where if I log in as an EU user we callsetServerURLfor the EU endpoint and use our EU token. I log an event and everything looks great. If I then logout and log in as a US user and log the same event it will show up in US account as expected but the API endpoint will still be the EU endpoint. I can replicate the same thing in the opposite order if I do it the other way around.To make this issue more confusing the below sample is C# as this is a .NET MAUI app so the code may not match for what you expect to see in a Java app. I have bindings for iOS and Android for us to use this native SDKs in our .NET app. Our iOS app does not have this issue. It should also be noted that my Android bindings only go up to v8.5.2 as the next version adds the common library and I have not added support for that version. It does not appear that anything in the changelog would indicate that it was fixed since then.
Here is an example of something I'd expect to work.
I did try to re-create this is kotlin using 8.8.0 but it appears to not send to the US region
What I did notice is that
mixpanelEUandmixpanelUSare the same object. I think this is expected because it is a singleton. However what I don't think is expected is that the underlying HttpService object is not re-created after it is first created. IfsetServerUrlis called it does not pass that information through to the HttpService resulting in nothing actually changing after it is first set.