简体   繁体   中英

How to implement and test Firebase Analytics in a React-Native project?

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:

  1. npm install firebase --save
  2. Opened index.ios.js and imported firebase

import * as firebase from 'firebase';

  1. 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?

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM