Mixpanel - Linking pre login and post login events to user on android

317 Views Asked by At

We have followed the guidance in the linked article and Mixpanel documentation as well.

As per mixpanel, set alias on sign up

MixpanelAPI mixpanelAPI = MixpanelAPI.getInstance(context, MixPanelConstants.MIX_PANEL_TOKEN);
mixpanelAPI.alias("myAlias", mixpanelAPI.getDistinctId());

and then set identifier/distinct-id on login

MixpanelAPI mixpanelAPI = MixpanelAPI.getInstance(context, MixPanelConstants.MIX_PANEL_TOKEN);
mixpanelAPI.identify("[email protected]");

However this approach doesn't support linking of pre-login and post-login events if user doesn't sign up and logs in directly. Alias is set when user signs up and then identify is called on login. Mixpanel recommended to set Alias once during the life time of the user. But in case of existing user, when he tries to login, events won't be linked.

2

There are 2 best solutions below

0
On BEST ANSWER

As per MixPanel guidance events can be linked if alias is set first and then identifier.

//set alias when user signs up

MixpanelAPI mixpanelAPI = MixpanelAPI.getInstance(context, MixPanelConstants.MIX_PANEL_TOKEN);
mixpanelAPI.alias("myAlias", mixpanelAPI.getDistinctId());


//set identifier when user logs in
mixpanelAPI.identify("user.alias");

Alias is set when user performs registration, right? Mixpanel recommends to set Alias once during the life time of the user. However this guidance doesn't support linking of pre-login and post-login events if user doesn't perform registration and logins directly (Existing user scenario)

0
On

When you use alias with "myAlias" you linked the user with "myAlias". After that when a use login and you identify with "myAlias" mixpanel understand it is the same user.
So it should be like this :
MixpanelAPI mixpanelAPI = MixpanelAPI.getInstance(context, MixPanelConstants.MIX_PANEL_TOKEN); mixpanelAPI.alias("user.alias", mixpanelAPI.getDistinctId());

and

MixpanelAPI mixpanelAPI = MixpanelAPI.getInstance(context, MixPanelConstants.MIX_PANEL_TOKEN);
mixpanelAPI.identify("user.alias");