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 :)
4 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');
-
Is it possible to track multiple apps as one app using the Google Analytics Bridge?– RaunaqssCommented Sep 8, 2017 at 6:34
-
Unless I'm misunderstanding the question @Raunaqss, just use the same tracking id in all the apps? In that case, yes.– cbrevikCommented Sep 9, 2017 at 8:16
-
Yes, using the same tracking id across multiple apps, it's a weird use case but works perfect. Thanks!– RaunaqssCommented Sep 18, 2017 at 6:01
-
where did we place the last two line of code trackscreenview and rackevent ??– ManishCommented Apr 12, 2018 at 11:53
-
Wherever you need to use them @Manish. Typically
trackScreenView
is used when navigating to a certain screen, whiletrackEvent
is used alongside certain actions inside the app. It's up to you to decide your use-case.– cbrevikCommented Apr 12, 2018 at 12:26
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!
-
So, any other questions about the module without getting it working in the most basic form are null. We have tried
"^0.14.2"
and the "^0.13.0" versions of RN, and we are running on iOS 9, so I don't think it's specifically a problem with the iOS < 7 versions Commented Dec 7, 2015 at 12:07
I just set up mixpanel with this package: https://github.com/davodesign84/react-native-mixpanel
And then I have something like this in my main.js file that holds all my view components:
componentWillMount: function() {
this.loadData(this.setDataState);
// not sure if this is the best way to do it, but whatever
Mixpanel.identify(DeviceInfo.getUniqueID());
Mixpanel.set("$name", DeviceInfo.getDeviceName());
Mixpanel.track("App Loaded");
}
And then in my view.js that renders a component with data, I have something like this:
componentWillMount: function() {
Mixpanel.trackWithProperties("Definition Viewed",{word:this.state.word});
}
And then I also call mixpanel when a users adds/deletes data.
After all this, I just noticed that fabric does analytics so I will probably migrate to that because I use to to manage beta testers and its awesome so it'll be nice to have everything in 1 place
-
1
So this may be helpful to people, but I found Segment - https://segment.com/ - a lot easier to get setup. Segment has integration with Google Analytics and all the other analytics packages, so it easy once the connection is made. I had to follow some tutorials on creating a native bridge using the RCT_EXPORT_MODULE
technique, but once I established a connection to the client, I was able to pretty much plug in the Segment starter code. I linked specific event calls to different actions on the client side through NativeModules.AnalyticsHelper.openApp(clientId)
, NativeModules.AnalyticsHelper.shareContent(clientId)
, etc.. I think this is a good method to follow.
I also created a gist to show how to setup Segment Analytics for React native.
-
1Thanks for the tip on Segment, looks really interesting. Out of curiosity, why did you choose to use their iOS SDK rather than their JS code? Thanks. Commented Feb 3, 2016 at 18:49
pageview
when RN navigator performs a view transition. If this is write I'd be happy to submit a proper answer on SOreact-google-analytics
package as suggested, but that package seems to rely on DOM-like behavior and so is not compatible with RN.