9

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

Damien Romito
  • 9,801
  • 13
  • 66
  • 84

5 Answers5

13

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

Damien Romito
  • 9,801
  • 13
  • 66
  • 84
  • 2
    that worked! If anyone else gets the following error, to uninstall and reinstall the package ypeError: firebase__WEBPACK_IMPORTED_MODULE_8___default.a.analytics is not a function react – Chris Evans Nov 18 '19 at 09:30
4

The previous answer should be corrected like this:

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

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Hashan Shalitha
  • 835
  • 8
  • 15
1

My issue was the same as listed above:

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

But the resolution was that I forgot to import the analytics module: import 'firebase/analytics';

Jeremy
  • 3,438
  • 3
  • 34
  • 57
0

If you are using Typescript:

// On index.tsx
import { initializeApp } from 'firebase/app';
import { initializeAnalytics } from 'firebase/analytics';

const firebaseConfig = {
 ... your config object ...
};

const app = initializeApp(firebaseConfig);
initializeAnalytics(app);
Anderson Laverde
  • 316
  • 1
  • 4
  • 15
0

Firebase gone through a lot of new updates. Change imports like this;

import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
import 'firebase/compat/analytics';
Akshay K Nair
  • 1,107
  • 16
  • 29