Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google analytics on my React app with firebase SDK

I used Google Analytics a lot for many sites...

I'm just releasing a first app with Firebase (Firestore + Firebase SDK with reactjs).

Then, I activated GA from my Firebase dashboard... but I cannot see any activity !

enter image description here

I probably need not to add plugin like "autotrack" ?

import 'autotrack';
ga('create', 'UA-XXXXX-Y', 'auto');

It's not clear because, it's impossible to find out the track ID (UA-XXXXX-Y) from my dashboard !

Do I really need it ? Where can I find it ? enter image description here

like image 663
Damien Romito Avatar asked Oct 21 '19 09:10

Damien Romito


People also ask

How to add Firebase Analytics to your react app?

To add Firebase Analytics to our React app, we will use ga-4-react package. This package can be used to include Google Analytics tracking code in a website or app that uses React for its front-end codebase. This goes without saying but of course, we’ll need a react app to get started.

How to integrate rnfirebase with React Native?

Step 1: Assuming you have your React Native App up and running, open your terminal, redirect to your project directory, and run the following command to add RNFirebase to your project: Step 2: Go to console.firebase.google.com and create your Firebase Project.

What can you measure with Firebase Analytics?

Measure performance, and so much more, of your React App with Firebase Analytics. Data is everywhere. Being able to see how your website, or app, is doing in real-time is a blessing.

How do I collect data from Firebase?

Just add the Firebase SDK to your new or existing app, and data collection begins automatically. You can view analytics data in the Firebase console within hours. Log custom data. You can use Analytics to log custom events that make sense for your app, like E-Commerce purchases or achievements.


1 Answers

I did't correctly initialized Analytics... With firebase it's not a track ID but a measurementId

import app from 'firebase/app';
import 'firebase/analytics';

app.initializeApp({
   //other config
  measurementId : process.env.REACT_APP_MEASUREMENT_ID,
  appId : process.env.REACT_APP_DEV_ID
})

//put inside your constructor
app.analytics()

This will solve the following error:

Error: firebase__WEBPACK_IMPORTED_MODULE_8___default.a.analytics is not a function react

Documentation : https://firebase.google.com/docs/analytics/get-started?platform=web

like image 64
Damien Romito Avatar answered Sep 28 '22 11:09

Damien Romito