Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up analytics on React Native for iOS

So I have a completed React Native project for iOS but I want to put analytics in it. I tried the react-native-google-analytics package, but issues prevent it from working properly. Also, the react-native-cordova-plugin package is only working on Android, so the ability to plug in a Cordova plugin for analytics is out of the question for now. I also do not have Swift / objective C experience, so would be completely lost pluggin in GA that way. Does anyone have any suggestions on how to hook up Google Analytics (or any other analytics) for React Native for iOS? If so, please give some detailed instructions on doing so. I, and I'm sure, many others will appreciate it :)

like image 945
Tom Goldenberg Avatar asked Dec 07 '15 03:12

Tom Goldenberg


People also ask

Can you use Google Analytics on react native?

Formerly known as simply Firebase Analytics, Google Analytics for Firebase supports React Native as well. It tracks the user behavior using custom and predefined events and can be integrated with the Firebase SDK.

How do I track user activity on react native app?

To track events you can use google analytics in react-native either as a javascript or a native implementation. The key difference is that in the native implementation you get a some metadata handled automatically. ( such as device UUID, device model, viewport size, OS version ).

How do I add Firebase analytics to react native app?

Add it to the native project inside the app folder from the Android project folder. For React Native, there's the official Firebase package. It contains all of the Firebase services, and we'll be installing and using the one. Install the core and analytics packages.


2 Answers

I am the author of a Google Analytics package for React Native: https://github.com/idehub/react-native-google-analytics-bridge

Since it is a pretty simple native bridge to the official Google Analytics libraries, it should not give you any issues related to the platform. Also, it will handle a lot of the metadata automatically, like the device UUID, device model, viewport size, OS version etc.

Because of that last part, the calls can be pretty simple, like tracking a new screen view:

import { GoogleAnalyticsTracker } from 'react-native-google-analytics-bridge';
let tracker = new GoogleAnalyticsTracker('UA-12345-1');
tracker.trackScreenView('Home')

Or an event:

tracker.trackEvent('testcategory', 'testaction');
like image 148
cbrevik Avatar answered Oct 05 '22 12:10

cbrevik


I'm the author of react-native-google-analytics -- the problem with it has been with React Native's lack of support for GIF data in XHR responses on iOS 7. I'm still trying to figure out if the problem people are experiencing is still limited to iOS 7. The bug was reported as fixed by the RN team for iOS > 7, however if that is not the case then there must be a regression. Tracking for the React Native issue is here: https://github.com/facebook/react-native/issues/1780

If you have any other questions regarding the module specifically, please don't hesitate to ask on GitHub!

like image 39
iLoch Avatar answered Oct 05 '22 11:10

iLoch