Firebase分析日志事件在电子生产版本中不起作用 [英] Firebase analytics log event not working in production build of electron
问题描述
我使用了 firebase 软件包来使用实时数据库,并且我想实现Firebase分析,所以我使用相同的程序包并编写代码进行分析
I used a firebase package for using realtime DB and I want to implement firebase analytics so I used the same package and write code for analytics
import * as firebase from 'firebase'
import 'firebase/analytics'
import { fireBase } from 'configs/config'
const config = {
apiKey: fireBase.REACT_APP_FIREBASE_API_KEY,
authDomain: fireBase.REACT_APP_FIREBASE_AUTH_DOMAIN,
databaseURL: fireBase.REACT_APP_FIREBASE_DATABASE_URL,
projectId: fireBase.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: fireBase.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: fireBase.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
appId: fireBase.REACT_APP_FIREBASE_APP_ID,
measurementId: fireBase.REACT_APP_MEASUREMENT_ID,
}
firebase.initializeApp(config)
export const defaultAnalytics = firebase.analytics()
export default firebase
此后,我在需要的文件中导入了 defaultAnalytics ,并使用该代码记录了事件以进行分析
after that, I imported defaultAnalytics in the file where I needed it and put that code to log the event for analytic purposes
defaultAnalytics.logEvent('profile_update')
它可以完美地在开发中工作,但不能在生产模式下工作
It is working in development perfectly but not working in the production mode
推荐答案
有类似电子的问题,当我们在开发模式下运行应用程序时,由于该应用程序在localhost:3000上运行,因此它将轻松记录firebase事件.工作.
There is issue like in electron, When we run app in development mode it will log firebase event easily because the app is run on localhost:3000 so a event will work.
但是当我们为mac/windows创建构建时,它不会记录该事件,因为 firebase 当构建运行在 http 协议上并且我们的电子应用产品构建运行 file://协议
But when we create a build for mac/windows it will not log the event because firebase package work when a build run on http protocol and our electron app production build run a file:// protocol.
因此,在这里我们必须使用Measurement Protocol,因为我们需要在firebase应用中创建一个单独的属性.
So here we have to use Measurement Protocol, In that we need to create a separate property in firebase app.
创建属性的步骤:
- 转到analytics.google.com,然后创建一个Firebase应用.
- 单击创建属性",然后选择网站选项.
- 提供网站URl和财产名称.
之后,您将获得跟踪信息.因此,跟踪代码将可用.
After the you will get a tracking info.In that a tracking code will be available.
然后在主要流程中使用通用分析.
Then use universal-analytics in main Processes.
这是完整的实现. https://kilianvalkhof.com/2018/apps/using-google-analytics-to-gather-usage-statistics-in-electron/
这篇关于Firebase分析日志事件在电子生产版本中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!