Send Data To Multiple Projects

It's entirely possible to initialize separate Mixpanel objects with different tokens to send Events and/or People Profile updates to separate projects. This is useful if you want to certain events to appear in one project and others events to appear in a different project.

Web

Sending Event data from a single website to multiple different Mixpanel projects is possible using the JavaScript library and modifying the mixpanel.init call.

The optional library_name parameter in the mixpanel.init function allows you to specify which library to write to in all tracking calls. For example, say you have project A with a token of "123abc" and project B with a token of "456def." After your initial Project A init call (with 123abc), you could set up a second instance of the initialization like this:

mixpanel.init("456def", {}, "project_b")

You would then send any project B calls like this:

mixpanel.project_b.track("Event name") 

Any standard track calls without a specified project name would go to the initial Mixpanel project.

Read additional documentation on mixpanel.library_name.

iOS

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.

Android

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;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_main);

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


        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);
        }
    }
}
Is this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.