nuxt-community / firebase-module

🔥 Easily integrate Firebase into your Nuxt project. 🔥
https://firebase.nuxtjs.org
MIT License
642 stars 98 forks source link

The measurement ID fetched from the server is undefined #337

Closed snorreks closed 4 years ago

snorreks commented 4 years ago

Version

@nuxtjs/firebase: 6.1.1 firebase: 7.24.0 nuxt: 2.14.7

Steps to reproduce

I have SSR enabled, and this is my Nuxt config:

{
  modern: true,
  pwa: {
    ...
    workbox: {
      importScripts: ['/firebase-auth-sw.js'],
      dev: !isProductionMode,
    },
  },
  firebase: {
    config: {
      production: {
        apiKey: process.env.FB_API_KEY || '',
        authDomain: process.env.FB_AUTH_DOMAIN || '',
        databaseURL: process.env.FB_DB_URL || '',
        projectId: process.env.FB_PROJECT_ID || '',
        storageBucket: process.env.FB_STORAGE_BUCKET || '',
        messagingSenderId: process.env.FB_MESSAGING_SENDER_ID || '',
        appId: process.env.FB_APP_ID || '',
        measurementId: process.env.FB_MEASUREMENT_ID || '',
      },
    },
    services: {
      firestore: true,
      functions: true,
      storage: true,
      performance: true,
      analytics: true,
      auth: {
        initialize: {
          onAuthStateChangedAction: 'auth/onAuthStateChanged',
        },
        ssr: true,
      },
    },

What is Expected?

Get the measurement ID from the server.

What is actually happening?

The measurement ID is undefined. But when i look at the "firebase-auth-sw.js" in the static folder it has the correct measurementId.

The console: [2020-10-19T10:02:21.359Z] @firebase/analytics: The measurement ID in the local Firebase config (G-D972LYZEZX) does not match the measurement ID fetched from the server (undefined). To ensure analytics events are always sent to the correct Analytics property, update the measurement ID field in the local config or remove it from the local config.

lupas commented 4 years ago

Hey @snorreks

May I ask why you are defining it as process.env.FB_MEASUREMENT_ID || ''?

The measurement ID is used for Google Analytics on client side. Can you test if it works if you hardcode the measurement id in your nuxt.config.js like so?

measurementId: 'yourMeasurementId',

If it works then, your problem is simply that the env variable is not available on the client where Google Analytics needs the ID - so you should make sure to pass it in differently. (BTW: the Firebase config is NOT sensitive data)

PS: The measurement ID has nothing to do with Google Auth and the `firebase-auth-sw.js, we just pass the entire Firebase config to the service worker that's why it shows up there.

snorreks commented 4 years ago

Yeah my bad, I fixed it now 👌