在 Expo Go 应用程序中使用 Expo Firebase Analytics 无法正常工作

Sco*_*ott 7 firebase react-native firebase-analytics expo

我尝试expo-firebase-analytics在 Expo Go 应用程序中使用该包作为第一步,以确保在查看它是否在独立应用程序中工作之前设置正确。但它现在不起作用。我的 Firebase 分析控制台上未记录事件。我正在遵循此安装指南:https ://docs.expo.io/versions/latest/sdk/firebase-analytics/

我跑了expo install expo-firebase-analytics。我也跑过expo install firebase。我已经设置了一个 Firebase Web 项目并将配置添加到我的app.json.

{
  "expo": {
    ...
    "web": {
      "config": {
        "apiKey": "AIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "authDomain": "my-app.firebaseapp.com",
        "projectId": "my-app",
        "storageBucket": "my-app.appspot.com",
        "messagingSenderId": "mySenderId",
        "appId": "1:myApp:web:myAppId",
        "measurementId": "G-MYMEASUREMENTID"
      }
    },
  }
Run Code Online (Sandbox Code Playgroud)

这是我的 App.js 文件

import React, { useEffect } from "react";
import { Text, View } from "react-native";
import * as Analytics from 'expo-firebase-analytics';

export default function App() {
  useEffect(() => {
    (async() => {
      console.log("App.js useEffect");
      await Analytics.logEvent('ScreenLoaded');
    })();
  }, []);

  return <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}><Text>MAIN SCREEN</Text></View>
}
Run Code Online (Sandbox Code Playgroud)

谁能帮助我理解我所缺少的东西?

Sco*_*ott 3

我想到了。设置是正确的。我意识到,当您在 Expo Go 应用程序中使用此包时,您实际上不会在 Firebase 控制台中看到日志。相反,日志会显示在您的终端控制台中以确认包正在运行。但是,一旦您构建了独立应用程序,日志就会出现在您的 Firebase 控制台中。

另一个潜在的错误是在 Expo 文档中,它说使用 put your config object in in expo.web.config.firebaseapp.json但我必须将它放入expo.web.config(如上面所写)并且没有关键字firebase才能工作。