react-native-mixpanel icon indicating copy to clipboard operation
react-native-mixpanel copied to clipboard

integrate addPushDeviceToken for iOS and Android

Open ms88privat opened this issue 9 years ago • 3 comments

Would be awesome if somebody could implement addPushDeviceToken 👍

I think this is an essential feature of mixpanel.

ms88privat avatar Jun 05 '16 11:06 ms88privat

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

ms88privat avatar Jun 05 '16 14:06 ms88privat

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];
}

nazywamsiepawel avatar Sep 15 '16 16:09 nazywamsiepawel

is that still available?

Abanoub-Emil avatar Apr 24 '22 14:04 Abanoub-Emil