我正在尝试使用 Expo Go 应用程序中的
expo-firebase-analytics
包作为第一步,以确保我的设置正确,然后再查看它是否可以在独立应用程序中运行。但它现在不起作用。我的 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"
}
},
}
这是我的 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>
}
任何人都可以帮助我理解我所缺少的吗?
我想通了。设置是正确的。我意识到,当您在 Expo Go 应用程序中使用此包时,您实际上不会在 Firebase 控制台中看到日志。相反,日志会显示在您的终端控制台中,以确认包正在运行。但是,一旦您构建了独立应用程序,日志就会出现在您的 Firebase 控制台中。
另一个潜在的错误是在世博文档中,它说使用将配置对象放入
expo.web.config.firebase
中的app.json
中,但我必须将其放在expo.web.config
中(如上面所写)并且not有一个firebase
关键字才能发挥作用。
对于 Expo Web,我正在尝试 Brave 中的分析调试视图。但没有成功。
我已经在 Brave 中安装了 Google Analytics 调试器,但没有成功。
然后我将浏览器从 Brave 更改为 Chrome 并安装了 Google Analytics Debugger。
现在它在 Firebase DebugView 中显示了预期的 Web 分析。