Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase analytics log event not working in production build of electron

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

like image 717
Hardik Kothari Avatar asked Oct 15 '22 09:10

Hardik Kothari


1 Answers

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:

  1. Go to analytics.google.com then create a firebase app.
  2. click on Create property and choose website option.
  3. The provide a website URl and name of property name.

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/

like image 92
Hardik Kothari Avatar answered Oct 26 '22 23:10

Hardik Kothari