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
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
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.
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.
So here we have to use Measurement Protocol, In that we need to create a separate property in firebase app.
Steps for creating a property:
After the you will get a tracking info.In that a tracking code will be available.
Then use universal-analytics in main Processes.
Here is the complete implementation. https://kilianvalkhof.com/2018/apps/using-google-analytics-to-gather-usage-statistics-in-electron/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With