Using mixpanel with angular.js

2.3k views Asked by At

How can I use mixpanel in SPA? I want to track some events created by user. When user opens page first time randomly generated ID is given to him. After signing in this action is executed.

mixpanel.alias(data.id);
mixpanel.track('Sign In', {
    'Email': response.data.email
});

user.setCurrent(data);

In user.setCurrent function I do this:

mixpanel.identify(data.id);

But in my mixpanel account random ID still given to user? What should I do to prevent this?

1

There are 1 answers

0
Matt Zeunert On

Using mixpanel.identify doesn't actually change the ID Mixpanel uses:

On the signup confirmation page, you call mixpanel.alias("[email protected]"). This doesn't actually change his ID - he is still being identified using the random ID we originally assigned him.

What you can do is to add the ID you use in your database to the Mixpanel Person, just like you do with the email at the moment. Then configure the Mixpanel UI to show that column in your reports.

mixpanel.track('Sign In', {
    'Email': response.data.email,
    'UserId': response.data.id
});