Can I initialize multiple instances of Mixpanel on the same app?

It's entirely possible to initialize separate Mixpanel objects with different tokens to send Events and/or People Profile updates to separate projects. For example, you may want to see some events in your app appear in Project 1 and others appear in Project 2. The approach for how to accomplish this varies depending on the SDK you're using.


You can create multiple instances of the Mixpanel API and switch back and forth between two projects by using the initWithToken method. You can specify your second project token in this method.

Note that codeless events and A/B testing will always apply to the instance with sharedInstanceWithToken.

For example:

Mixpanel *master = [Mixpanel sharedInstanceWithToken:MASTER_TOKEN];

Mixpanel *publisher = [[Mixpanel alloc] initWithToken:PUBLISHER_TOKEN andFlushInterval: 60];

[master track:@"..."];

[publisher track:@"..."];

Learn more about the initWithToken method.


To initialize multiple instances of Mixpanel on Android, simply construct separate Mixpanel objects.

Note that codeless events and A/B testing will always apply to the most recent response from the decide server.

For example:

public class MainActivity extends AppCompatActivity {
    public MixpanelAPI mixpanel;
    public MixpanelAPI mMixpanel;

    private static final String projectToken = "TOKEN 1";
    private static final String projectToken_t = "TOKEN 2";
    private static Context context;

    protected void onCreate(Bundle savedInstanceState) {



        mixpanel = MixpanelAPI.getInstance(this, projectToken);
        mMixpanel = MixpanelAPI.getInstance(this, projectToken_t);

        try {
            JSONObject props = new JSONObject();
            props.put("Screen", "MainActivity");
            mixpanel.track("Viewed Screen", props);
            mMixpanel.track("Viewed Screen", props);
        } catch (JSONException e) {
            Log.e("MYAPP", "Unable to add properties to JSONObject", e);

You may also be interested in: Can I send data from one website to different Mixpanel projects?

Find your answer?
0 out of 0 found this helpful



Article is closed for comments.