简体   繁体   English

如何在 React-Native 项目中实施和测试 Firebase Analytics?

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

I have learned from reading that Firebase officially supports react-native.我从阅读中了解到 Firebase 正式支持 react-native。

https://firebase.googleblog.com/2016/01/the-beginners-guide-to-react-native-and_84.html 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打开index.ios.js并导入index.ios.js

import * as firebase from 'firebase';从'firebase'导入*作为firebase;

  1. Initialise Firebase初始化 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.根据我的理解,这应该会在我的项目中启用 Firebase 分析,并且我应该会在 Firebase 控制台中看到会话报告。 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?还有什么方法可以让 Firebase 日志反应原生,以便我知道发生了什么?

The Firebase web SDK (including real-time database) works with React Native. Firebase Web SDK(包括实时数据库)与 React Native 配合使用。 However, Firebase does not currently offer analytics as part of the Web SDK.但是,Firebase 目前不提供分析作为 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 .要启用分析,您需要围绕本机 SDK 实施包装器或使用诸如https://github.com/fullstackreact/react-native-firestack 之类的库。

Firebase Analytics sends info every 24 hours. Firebase Analytics 每 24 小时发送一次信息。 you can enable Logcat for Firebase to check you're calls, add in terminal, and check it out in Android Studio logcat:您可以为 Firebase 启用 Logcat 来检查您的调用,在终端中添加,然后在 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:要立即在 Firebase 控制台中看到它们,您应该启用调试模式 - 立即发送它们:

To enable Analytics Debug mode on an Android device, execute the following commands:要在 Android 设备上启用 Analytics 调试模式,请执行以下命令:

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查看 Firebase 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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