问题
I have learned from reading that Firebase officially supports react-native.
https://firebase.googleblog.com/2016/01/the-beginners-guide-to-react-native-and_84.html
I have followed the above link and performed these steps:
npm install firebase --save
- Opened
index.ios.js
and imported firebase
import * as firebase from 'firebase';
- Initialise Firebase
const firebaseConfig = {
apiKey: "<your-api-key>",
authDomain: "<your-auth-domain>",
databaseURL: "<your-database-url>",
storageBucket: "<your-storage-bucket>",
,
};
const firebaseApp = firebase.initializeApp(firebaseConfig);
I have put all the right values in the above fields. From my understanding, this should enable Firebase analytics in my project and I should see session reporting in Firebase console. But I can't see anything.
Am I missing anything here? Also is there any way to get Firebase logs in react native so that I can know what's happening?
回答1:
The Firebase web SDK (including real-time database) works with React Native. However, Firebase does not currently offer analytics as part of the Web SDK. To enable analytics, you would need to implement a wrapper around the native SDKs or use a library such as https://github.com/fullstackreact/react-native-firestack.
回答2:
Firebase Analytics sends info every 24 hours. you can enable Logcat for Firebase to check you're calls, add in terminal, and check it out in Android Studio logcat:
adb shell setprop log.tag.FA VERBOSE adb shell setprop log.tag.FA-SVC VERBOSE adb logcat -v time -s FA FA-SVC
And to see them right away in the Firebase console you should enable debug mode - that sends them right away:
To enable Analytics Debug mode on an Android device, execute the following commands:
adb shell setprop debug.firebase.analytics.app <package_name>
This behavior persists until you explicitly disable Debug mode by executing the following command:
adb shell setprop debug.firebase.analytics.app .none.
checkout the Firebase documentation
来源:https://stackoverflow.com/questions/40703123/how-to-implement-and-test-firebase-analytics-in-a-react-native-project