File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
packages/nuxt/src/runtime/analytics Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { getAnalytics } from 'firebase/analytics'
2
+ import { useFirebaseApp } from '../app/composables'
3
+
4
+ /**
5
+ * Retrieves the Firebase analytics instance. **Returns `null` on the server** and when the platform isn't supported.
6
+ *
7
+ * @param name - name of the application
8
+ * @returns the Analytics instance
9
+ */
10
+ export function useAnalytics ( ) {
11
+ return process . client ? getAnalytics ( useFirebaseApp ( ) ) : null
12
+ }
Original file line number Diff line number Diff line change
1
+ import type { FirebaseApp } from 'firebase/app'
2
+ import { isSupported , initializeAnalytics } from 'firebase/analytics'
3
+ import { defineNuxtPlugin , useAppConfig } from '#app'
4
+
5
+ /**
6
+ * Plugin to initialize the analytics module.
7
+ * @experimental : NOT YET RELEASED
8
+ */
9
+ export default defineNuxtPlugin ( async ( nuxtApp ) => {
10
+ const appConfig = useAppConfig ( )
11
+ // @ts -expect-error: not implemented yet
12
+ const options = appConfig . vuefireOptions . analytics
13
+ const firebaseApp = nuxtApp . $firebaseApp as FirebaseApp
14
+
15
+ if ( await isSupported ( ) ) {
16
+ initializeAnalytics ( firebaseApp , options )
17
+ } else {
18
+ console . info (
19
+ '[nuxt-vuefire]: Firebase Analytics is not supported on this platform.'
20
+ )
21
+ }
22
+ } )
You can’t perform that action at this time.
0 commit comments