davide-scalzo / react-native-mixpanel

A React Native wrapper for Mixpanel tracking
MIT License
455 stars 195 forks source link

`alias` method should accept 2 params #205

Closed derekmisler closed 4 years ago

derekmisler commented 5 years ago

Mixpanel's documentation show 2 params for the alias method, for associating pre-identification events with an existing user: https://developer.mixpanel.com/docs/javascript-full-api-reference#section-mixpanel-alias

Example:

mixpanel.alias('new_id', 'existing_id');

Currently, the createAlias and alias methods of this package only allows a single param:

createAlias(alias: string) {
  if (!defaultInstance) throw new Error(NO_INSTANCE_ERROR)
  defaultInstance.alias(alias)
}

// and

alias(alias: string): Promise<void> {
  if (!this.initialized) throw new Error(uninitializedError('createAlias'))
  return RNMixpanel.createAlias(alias, this.apiToken)
}

The issue with defaulting to the distinctId (as seen here), is that Mixpanel creates a new distinctId for every pre-identified user, which prevents tracking across devices.

I'm proposing we add support for the second alias param.

lorenc-tomasz commented 5 years ago

@derekmisler Could you test "react-native-mixpanel": "github:lorenc-tomasz/react-native-mixpanel#1.1.12", please?

PR: https://github.com/davodesign84/react-native-mixpanel/pull/207

derekmisler commented 4 years ago

YES. Thank you, @lorenc-tomasz, that worked!