Amplitude-ReactNative
Amplitude-ReactNative copied to clipboard
[iOS] After switching apiKey Amplitude still log events to previous project
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);
}
});
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);
}
});
Hi @yuhao900914 , for sure I tried it once, and issue still reproducing
@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 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
Dose this issue only on iOS, not android? Which amplitude react native version you are using?
@amplitude/react-native: "^2.5.0"
react-native: "0.68.1"