nuxt-community / firebase-module

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

this.$fire.analytics is null #403

Closed RodrigoBertotti closed 3 years ago

RodrigoBertotti commented 3 years ago

Version

@nuxtjs/firebase: ^7.1.1 firebase: 8.1.2 nuxt: 2.14.9

Reproduction Link

https://codesandbox.io/s/peaceful-goldwasser-g7nkk?file=/pages/index.vue

Steps to reproduce

this.$fire.analytics.logEvent("page_view", {
    foo: 'foo'
})

What is Expected?

Save the log event

What is actually happening?

Cannot read property 'logEvent' of undefined

lupas commented 3 years ago

Hey @DesiredApp

Analytics is a client-only service and won't be initialized on the server. The created() lifecycle method gets triggered on the server - therefore the error message.

If I were you I would put the analytics code in the mounted() lifecycle hook, or you can wrap the code in if (process. isClient) {}

Hope that makes sense. Pascal

RodrigoBertotti commented 3 years ago

got it! thank you very much!