Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Deodes opened this issue Jun 13, 2022 · 6 comments
Open

Comments

@Deodes
Copy link

Deodes commented Jun 13, 2022

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);
        }
    });
@yuhao900914
Copy link
Contributor

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);
        }
    });

@Deodes
Copy link
Author

Deodes commented Jun 15, 2022

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

@yuhao900914
Copy link
Contributor

@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?

@Deodes Deodes changed the title After switching apiKey Amplitude still log events to previous project [iOS] After switching apiKey Amplitude still log events to previous project Jun 16, 2022
@Deodes
Copy link
Author

Deodes commented Jun 16, 2022

@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

@yuhao900914
Copy link
Contributor

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

@Deodes
Copy link
Author

Deodes commented Jun 17, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants