Mixpanel for existing web app user?

  • 14 August 2020
  • 3 replies

  • Frequent Contributor
  • 6 replies

I’ve seen somewhat similar questions all over the web but never with the exact answer I was looking for, so apologies in advance if this has been done before.

I’m trying to implement the JavaScript client SDK in a Laravel/Vue app, however I’m having trouble understanding when/where to call mixpanel.alias(‘<user_id>’) to override the anonymous disinct_id so that I’m able to identify the user with their own existing user_id from my database.

My issue is that majority of tutorials say to call mixpanel.alias() when the user first signs up/registers to our app and mixpanel.identify() thereafter, however we already have thousands of users with existing user_id’s that I would like to use as the ID alias instead of the anonymous distinct_id that they’d be assigned by default (note: this a completely fresh implementation of Mixpanel being added to an existing application with existing users).

My questions are:

  1. Where do I call mixpanel.alias() (or whatever method is needed) to track a new Mixpanel user if my users are already signed up to my app and I don’t want to use the anonymous disinct_idbut rather use their own pre-existing user_id ?
  2. If I called mixpanel.alias() at the start of every session and the user was already being identified using their user_id from a previous mixpanel.alias() callis that okay because it would be the same value (user_id) every time so it would still know who the user is on the Mixpanel side?
  3. Is there any kind of API method I can use to check if the current user already has a disinct_id so that I can only call mixpanel.alias(‘<user_id>’) if they’re using the anonymous disinct_id and not their user_id if writing my own logic for when to call or not call .alias()

Thank you in advance, hopefully that is clear!

3 replies


Spent some time this weekend looking over this and still slightly confused. I was reading that I only need to use alias if I’m trying to sync anonymous events to a new user. Considering this is a 100% fresh Mixpanel implementation with no history and all users in my app are already registered, can I solely use .identify() with their user ID right from the start and bypass .alias() all together?

@cherise if you could lend me a hand It would be much appreciated, thanks in advance and sorry to be annoying lol.

@jcq Did you ever get an answer to this? How did you proceed?

Userlevel 2
Badge +1

Hey @jcq ,

Alias is no longer needed. 

  1. Just do a mixpanel.identify(user_id) and your user will be identified. You will also see what they did before the identify()
  2. No need, alias is not useful
  3. There is no official API for this. If you look at mixpanel UI, you’ll find one on mixpanel explorer page. is the unofficial API.