mixpanel / mixpanel-react-native

Official React Native Tracking Library for Mixpanel Analytics
https://mixpanel.com
Apache License 2.0
108 stars 48 forks source link

The init events are send not through the proxy #155

Closed oskar-juszczyk closed 2 years ago

oskar-juszczyk commented 2 years ago

We're not able to send the init events also through the proxy 😢 Is it possible?

We need this because the API is behind a firewall and we have to use the proxy. Also if the initial request to api.mixpanel.com fail, we're not able to send anything through proxy.

Screenshot 2022-09-06 at 17 25 37 Initial events always call the api.mixpanel.com

Initialization code:

    this.mixpanel = new Mixpanel(TOKEN);
    this.mixpanel.init(false, {
      api_host: 'https://proxy.###',
      property_blacklist: [...],
      ignore_dnt: true,
    });
    this.mixpanel.setServerURL('https://proxy.###');
    this.mixpanel.identify(XYZ);
    this.mixpanel.getPeople().set({ $email: XYZ, id: XYZ, name: XYZ });
oskar-juszczyk commented 2 years ago

I see that swift sdk accepts:

initialize(token apiToken: String,
                           trackAutomaticEvents: Bool,
                           flushInterval: Double = 60,
                           instanceName: String? = nil,
                           optOutTrackingByDefault: Bool = false,
                           useUniqueDistinctId: Bool = false,
                           superProperties: Properties? = nil,
                           serverURL: String? = nil)

But react native library doesn't pass serverURL to init

  Mixpanel.initialize(token: token, flushInterval: Constants.DEFAULT_FLUSH_INTERVAL,
                            instanceName: token, optOutTrackingByDefault: optOutTrackingByDefault,
                            superProperties: MixpanelTypeHandler.processProperties(properties: properties, includeLibInfo: true))
zihejia commented 2 years ago

hi @oskar-juszczyk , we will add the serverURL to init, thanks for bringing it up.

oskar-juszczyk commented 2 years ago

@zihejia np.

The lack of the serverURL parameter in the init call for react native library is not the problem. Please contact "Eric Nague" from your support maybe you can help me with my issue, he has the debug logs which I don't want to paste here.

Because of our restrictions, the api.mixpanel.com is blocked and those initial requests fail thus we cannot send any other events after it through the proxy (the requests go through with a response but they don’t appear in the mixpanel).

I would be really grateful if you could investigate it because otherwise, we won't be available to use your product for a long time in our mobile app.

We're already using it in the web app and it works great, there are no initial calls to the api.mixpanel.com, they have the api_host property which does all the magic we need 😄

I've tested your obj-c, swift, and react native SDKs and all of them sent initial calls to api.mixpanel.com even though they had the server URL set to our proxy. The proxy was used only when I called the track event.

I've even tested the obj-c and swift SDK on a new iOS app.

Mixpanel *mixpanel = [Mixpanel sharedInstanceWithToken:@"###" trackAutomaticEvents:TRUE optOutTrackingByDefault:FALSE ];
    mixpanel.enableLogging = YES;
    mixpanel.serverURL = @"https://proxy.###.com/";
    mixpanel.flushInterval= 60.0;
Mixpanel.initialize(token: "###", trackAutomaticEvents: true, flushInterval:60.0, instanceName: "###", optOutTrackingByDefault: false, serverURL: "https://proxy.###.com/")
        Mixpanel.mainInstance().loggingEnabled = true

        Mixpanel.mainInstance().track(event: "TEST", properties: [
            "source": "TEST SWIFT APP",
            "###": true
        ])
jaredmixpanel commented 2 years ago

@oskar-juszczyk serverURL can now be set as a parameter in the init call in v2.1.0 and you should see that all API requests go through your proxy...

const token = "6d83a31dc13733h89gra3d087084721";
const trackAutomaticEvents = true;
const mixpanel = new Mixpanel(token, trackAutomaticEvents);
const optOutTrackingDefault = false; 
const superProperties = {};
const serverURL = "https://proxy.###.com/";
mixpanel.init(optOutTrackingDefault, superProperties, serverURL);