Setting up analytics for your React Native app

React Native Analytics

When I finally got my iOS app (Sprinkles) to a good point and wanted to start testing it on real devices, I did a bunch of research and looked at things like TestFlight but eventually decided on Fabric because of the added analytics support and the idea of cross-platform support if I decided to also use it for Android as well (and this was also around the time React Native rolled out support for Android). Another positive for Fabric was the installation process. Once you created an account, you install Fabric and it walks you through how to add Fabric to your existing projects. They made it pretty simple and the instructions were really easy to follow. And once installed, I could then build the app and distribute it to people by email and it also tracked some basic analytics like number of active users, number of session and average session length. And it also tracked exceptions/errors and provides a stack-trace if available. For example:

Thread : Crashed: com.twitter.crashlytics.ios.exception
0 Sprinkles 0x10013a0c0 CLSProcessRecordAllThreads + 4296466624
1 Sprinkles 0x10013a0c0 CLSProcessRecordAllThreads + 4296466624
2 Sprinkles 0x10013a4e0 CLSProcessRecordAllThreads + 4296467680
3 Sprinkles 0x10012b42c CLSHandler + 4296406060
4 Sprinkles 0x100138a00 __CLSExceptionRecord_block_invoke + 4296460800
5 libdispatch.dylib 0x197d516a8 _dispatch_client_callout + 16
6 libdispatch.dylib 0x197d5c954 _dispatch_barrier_sync_f_invoke + 100
7 Sprinkles 0x1001384ac CLSExceptionRecord + 4296459436
8 Sprinkles 0x1001382e8 CLSExceptionRecordNSException + 4296458984
9 Sprinkles 0x100137f48 CLSTerminateHandler() + 4296458056
10 libc++abi.dylib 0x196bd6f44 std::__terminate(void (*)()) + 16
11 libc++abi.dylib 0x196bd685c __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*) + 134
12 libobjc.A.dylib 0x197534094 _objc_exception_destructor(void*) + 330
13 Sprinkles 0x1000e0f4c -[RCTBatchedBridge _handleRequestNumber:moduleID:methodID:params:] + 4296101708
14 Sprinkles 0x1000e0930 __33-[RCTBatchedBridge handleBuffer:]_block_invoke + 4296100144
15 libdispatch.dylib 0x197d516e8 _dispatch_call_block_and_release + 24
16 libdispatch.dylib 0x197d516a8 _dispatch_client_callout + 16
17 libdispatch.dylib 0x197d5d6ec _dispatch_queue_drain + 864
18 libdispatch.dylib 0x197d551ac _dispatch_queue_invoke + 464
19 libdispatch.dylib 0x197d5f5bc _dispatch_root_queue_drain + 728
20 libdispatch.dylib 0x197d5f2dc _dispatch_worker_thread3 + 112
21 libsystem_pthread.dylib 0x197f65470 _pthread_wqthread + 1092
22 libsystem_pthread.dylib 0x197f65020 start_wqthread + 4

Fabric also emails you each day with some basic stats with analytics and number of crashes if any. Unfortunately, my app doesn’t really have that many users, but I imagine if I had 100s of beta users, I would be able to see how many use the app daily and if there were any problems/errors.

Now Fabric isn’t the only solution, doing some searching, I stumbled upon the following StackOverflow article:

How to set up analytics on React Native for iOS

The interesting answer included a link to a react-native-mixpanel project on GitHub. For my next project, I might have to give this a try as I’ve used Mixpanel for web projects and really liked it.

And another interesting project worth looking at is the react-native-fabric project on GitHub. I haven’t given it a try yet, but I might start using it to track specific user events. I have been meaning to actually try building something like this since Fabric provides the the calls to make from XCode but a bridge needed to be created so you could call it from the JS. I still might try implementing this myself since I haven’t tried using RCTBridgeModule yet.