Is Firebase Analytics available? #1397
-
Hi! Is it possible to enable Firebase Analytics? I have not seen any VueFire documentation about it. Br, |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Jul 27, 2023
Replies: 1 comment 1 reply
-
You don't need anything specific in VueFire for this, initialize it next to your firebaseApp. In Nuxt, you do this in a client-only plugin, this might be added in the future: import type { FirebaseApp } from 'firebase/app'
import { isSupported, initializeAnalytics } from 'firebase/analytics'
import { defineNuxtPlugin, useAppConfig } from '#app'
/**
* Plugin to initialize the analytics module.
* @experimental: NOT YET RELEASED
*/
export default defineNuxtPlugin(async (nuxtApp) => {
const appConfig = useAppConfig()
// @ts-expect-error: not implemented yet
const options = appConfig.vuefireOptions.analytics
const firebaseApp = nuxtApp.$firebaseApp as FirebaseApp
if (await isSupported()) {
initializeAnalytics(firebaseApp, options)
} else {
console.info(
'[nuxt-vuefire]: Firebase Analytics is not supported on this platform.'
)
}
}) Within the script setup you can do: getAnalytics(useFirebaseApp()) And use the other analytics functions |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
posva
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't need anything specific in VueFire for this, initialize it next to your firebaseApp. In Nuxt, you do this in a client-only plugin, this might be added in the future: