Solved

Good practice for adding mixpanel.people.set() after mixpanel.alias()?

  • 4 September 2020
  • 1 reply
  • 47 views

According to Adding Tracking Code lecture in Mixpanel Implementation Course, the following code should create user profile when the user signs up:

function accountCreated(user) {
mixpanel.alias(user.email);
mixpanel.people.set({
"Plan Type": user.plan,
"$name": user.name,
"$email": user.email
});
}

However it won’t create user profile. Furthermore Storing User Profiles section of JavaScript API Integration docs is saying:

Note

The Mixpanel library does not automatically create user profiles for any user that performs an event. In order to send profile updates, you must call mixpanel.identify in addition to mixpanel.people.set, which empowers you to create profiles for only the users of your choice.

So I think mixpanel.people.set() should be called with mixpanel.identify(). I want to ask that the following code is good practice for dealing with user signup:

function accountCreated(user) {
mixpanel.alias(user.email);
mixpanel.identify(user.email);
mixpanel.people.set({
"Plan Type": user.plan,
"$name": user.name,
"$email": user.email
});
}

 

icon

Best answer by Cassandra 4 September 2020, 20:37

Hi @halfwindow,


If your project has ID Merge enabled, the identify method will connect pre- and post-authentication events when appropriate. You can avoid using alias, and call identify at signup and login. This should simplify your code.

function accountCreated(user) {
mixpanel.identify(user.email);
mixpanel.people.set({
"Plan Type": user.plan,
"$name": user.name,
"$email": user.email
});
}

 

If possible, I would suggest using a user id as an identifier, instead of an email address. Theres two reasons this can be helpful:

  1. User IDs don’t change over time, but users may want to update their email addresses
  2. Mixpanel identifiers are case sensitive, so a user who enters an email address equal to “halfwindow@gmail.com” would appear to be a different user than on who entered “Halfwindow@gmail.com”
View original

1 reply

Userlevel 1
Badge +1

Hi @halfwindow,


If your project has ID Merge enabled, the identify method will connect pre- and post-authentication events when appropriate. You can avoid using alias, and call identify at signup and login. This should simplify your code.

function accountCreated(user) {
mixpanel.identify(user.email);
mixpanel.people.set({
"Plan Type": user.plan,
"$name": user.name,
"$email": user.email
});
}

 

If possible, I would suggest using a user id as an identifier, instead of an email address. Theres two reasons this can be helpful:

  1. User IDs don’t change over time, but users may want to update their email addresses
  2. Mixpanel identifiers are case sensitive, so a user who enters an email address equal to “halfwindow@gmail.com” would appear to be a different user than on who entered “Halfwindow@gmail.com”

Reply