Amplitude-ReactNative icon indicating copy to clipboard operation
Amplitude-ReactNative copied to clipboard

[iOS] After switching apiKey Amplitude still log events to previous project

Open Deodes opened this issue 3 years ago • 6 comments
trafficstars

We have an environment switcher in our application. On env switch, we restart our app and initialize Amplitude with a new apiKey. But, no matter how many envs we switch, the events still log to the first project

AsyncStorage.getItem('API').then(env => {
        const ampInstance = Amplitude.getInstance();
        if (env && env !== PROD_API) {
            ampInstance.init(DEV_ANALYTICS_KEY);
            ampInstance.trackingSessionEvents(true);
        } else {
            ampInstance.init(PROD_ANALYTICS_KEY);
            ampInstance.trackingSessionEvents(true);
        }
    });

Deodes avatar Jun 13 '22 09:06 Deodes

Hi @Deodes , can you try to give a different instance id? Like

AsyncStorage.getItem('API').then(env => {
        let ampInstance;
        if (env && env !== PROD_API) {
            ampInstance = ampInstance.getInstance();
            ampInstance.init(DEV_ANALYTICS_KEY);
            ampInstance.trackingSessionEvents(true);
        } else {
            ampInstance = ampInstance.getInstance('prodInstance');
            ampInstance.init(PROD_ANALYTICS_KEY);
            ampInstance.trackingSessionEvents(true);
        }
    });

yuhao900914 avatar Jun 15 '22 06:06 yuhao900914

Hi @yuhao900914 , for sure I tried it once, and issue still reproducing

Deodes avatar Jun 15 '22 12:06 Deodes

@Deodes , have a stupid question, but still want to make sure. Did you try to print out something to make sure it goes to each different statement when you switch the envs?

yuhao900914 avatar Jun 15 '22 23:06 yuhao900914

@yuhao900914 yeah, I logged multiple times to be sured. Therefore, I tried not to initialize Amplitude on envs switch, but Amplitude still sending events.. It seems to me that the problem is under the hood of @amplitude/react-native on iOS

Deodes avatar Jun 16 '22 07:06 Deodes

Dose this issue only on iOS, not android? Which amplitude react native version you are using?

yuhao900914 avatar Jun 16 '22 14:06 yuhao900914

@amplitude/react-native: "^2.5.0"
react-native: "0.68.1"

Deodes avatar Jun 17 '22 11:06 Deodes