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:
- 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_id, but rather use their own pre-existing user_id ?
- 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() call, is 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?
- 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!