segmentio/analytics.js-core

React Native support?

Closed this issue · 6 comments

I'm currently stuck wrestling with react native mobile app and I'm currently trying to get some sort of analytics plugged into it. There are a few libs out there that help, but only partially:

image

Right now

import Analytics from 'analytics.js'
const analytics = Analytics({
  writeKey: process.env.SEGMENT_KEY,
  skipPageCall: true
})

Gives me a "cannot find module "771"" error. Any idea what's going on here?

@vkarpov15 Have you tried getting in touch with the developers of the react native + segment project at https://github.com/smore-inc/react-native-segment-io-analytics? Unfortunately, I don't think any of us are familiar too deeply with the project yet, but let me check in with the team and see we have any suggestions for you.

@vkarpov15 take a look at my module here. https://github.com/tonyxiao/react-native-analytics. it's not an official Segment library yet but I'm happy to help if you run into problems :)

It supports Android as well. And you would use it like so

import Analytics from 'react-native-analytics'
const analytics = Analytics({
  writeKey: process.env.SEGMENT_KEY,
  skipPageCall: true
})

@tonyxiao thanks for the excellent module! I'm unfortunately gonna have to pass though, looking to avoid dealing with native extensions as much as possible because my team doesn't really have anyone who's an expert with both iOS and android dev AFAIK. I ended up settling on hitting the Keen.IO API directly using superagent because keen-js also fails horribly on react native :(

@vkarpov15 there's actually very strong reason to use native modules on mobile in this case rather than using something like analytics-node. We do a lot of mobile specific work that we don't do in other SDKs, including but not limited to 1) batching requests and gzipping to save battery and bandwidth (difference here is more than an order of magnitude btw) 2) saving requests to disk when user is offline 3) auto measure key events essential to the mobile user lifecycle (See https://segment.com/blog/native-mobile-spec/) and collect device properties. You can build all of that yourself on top of something like superagent but it's a ton of work and not easy to get right.

I've shipped a few React Native apps before, it's generally pretty difficult to avoid native modules over time because they are essential for so many core functionalities. You might even have to write one of your own.

@vkarpov15 just curious, did you try using analytics-node by the way?

Nope. I'm sure the module does a lot of useful stuff, but none of what you listed matters to me because right now we're just using keen to track HTTP performance, not user behavior.