samzilverberg/cordova-mixpanel-plugin

Alias still requires two arguments

Closed this issue · 8 comments

mixpanel.alias() requires two argument, which is not the case in the mixpanel website, maybe it was this way long time ago.
the current signature:
mixpanel.alias(aliasId: string, originalId: string)
the expected one:
mixpanel.alias(aliasId: string)

thanks in advance

Thank you for the reply, as per https://mixpanel.com/help/reference/javascript#user-identity the alias requires only one parameter (javascript, not iOS/Android).
As only one argument is required (my_introduced_id) and the other one can be obtained from Mixpanel shouldn't the function (alias) be abstracted from the blugin leve?

@samzilverberg
I just checked the code, Android SDK seems accepting (null) and it will generate an original id, but it is not the case with iOS SDK

In the example here I see the email is not provided, null is supplied instead:
https://github.com/samzilverberg/cordova-mixpanel-plugin-testapp/blob/master/www/js/controllers.js#L58

I would appreciate having an example on how to use it 👍

dya wanna create a small PR to introduce alias with 1 argument?
I didnt look at the js sdk code but i'm guessing that calling the one arg alias fn will internally just fetch the distinctId and then internally call the alias with the 2 args.

his can pretty easily be done in the android/ios plugin code or even in the javascript code

it sounds like a good improvement to me, but i will only have time to do this in 2-3 weeks

What I did:

this.mixpanel.init(Constants.mix_panel_token)
    .then(()=>{
        this.mixpanel.distinctId().then((distinct_id) => {
        // Store the variable in some accessible class
        Class_XYZ.mix_panel_distinct_id = distinct_id;
    });
})

I make sure to make this call early enough before this code is called,

self.mixpanel.alias( self.email, CLASS_XYZ.mix_panel_distinct_id);

However, the way you suggested is more robust.

v4.2.0 has this improvement for alias, done directly in the JS bridge:
https://github.com/samzilverberg/cordova-mixpanel-plugin/blob/master/www/mixpanel.js#L17-L42