davide-scalzo / react-native-mixpanel

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

integrate addPushDeviceToken for iOS and Android #40

Open ms88privat opened 8 years ago

ms88privat commented 8 years ago

Would be awesome if somebody could implement addPushDeviceToken 👍

I think this is an essential feature of mixpanel.

ms88privat commented 8 years ago

I got this to work by sending the device token manually to the mixpanel api.

console.log('TOKEN:', token);
  let params = {
    '$distinct_id': 'xxx',
    '$token': 'apiTokenMixpanel',
    '$union': {},
  };
  if(Platform.OS === 'ios') {
    params['$union']['$ios_devices'] = [token.token];
  } else {
    params['$union']['$android_devices'] = [token.token];
  }
  const query = {
    data: base64.encode(JSON.stringify(params)),
  };

GET Request to http://api.mixpanel.com/engage?data=...

PS: To get the Notfication to show up on Android devices you need to specify extra data fields in mixpanel. E.g.

{
   "data": {
       "title" : "TitleOfNotification"
    },
    "message": "hello"
 }

image

nazywamsiepawel commented 8 years ago

simple way if you're doing iOS, mixpanel shared instance can be accessed from AppDelegate too :

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  Mixpanel *mixpanel = [Mixpanel sharedInstance];
  [mixpanel.people addPushDeviceToken:deviceToken];
  [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
Abanoub-Emil commented 2 years ago

is that still available?