This repository was archived by the owner on Feb 2, 2025. It is now read-only.
File tree 2 files changed +6
-11
lines changed
2 files changed +6
-11
lines changed Original file line number Diff line number Diff line change 1
1
'use client' ;
2
2
3
- import { logEvent } from 'firebase/analytics' ;
3
+ import { getAnalytics , logEvent , isSupported } from 'firebase/analytics' ;
4
4
import { usePathname } from 'next/navigation' ;
5
5
import { useEffect } from 'react' ;
6
- import { analytics } from '.. /firebase' ;
6
+ import { firebaseApp } from '@/const /firebase' ;
7
7
8
8
export default function Analytics ( ) {
9
9
const pathname = usePathname ( ) ;
10
10
11
11
useEffect ( ( ) => {
12
- if ( ! analytics ) return ;
12
+ if ( ! isSupported ( ) ) return ;
13
+
14
+ const analytics = getAnalytics ( firebaseApp ) ;
13
15
logEvent ( analytics , 'page_view' , {
14
16
page_location : pathname ,
15
17
} ) ;
Original file line number Diff line number Diff line change 1
- // Import the functions you need from the SDKs you need
2
- import { getAnalytics } from 'firebase/analytics' ;
3
1
import { initializeApp } from 'firebase/app' ;
4
2
5
- // Your web app's Firebase configuration
6
- // For Firebase JS SDK v7.20.0 and later, measurementId is optional
7
3
const firebaseConfig = {
8
4
apiKey : process . env . NEXT_PUBLIC_API_KEY ,
9
5
authDomain : process . env . NEXT_PUBLIC_AUTH_DOMAIN ,
@@ -14,7 +10,4 @@ const firebaseConfig = {
14
10
measurementId : process . env . NEXT_PUBLIC_MEASUREMENT_ID ,
15
11
} ;
16
12
17
- const firebaseApp = initializeApp ( firebaseConfig ) ;
18
- const analytics = getAnalytics ( firebaseApp ) ;
19
-
20
- export { firebaseApp , analytics } ;
13
+ export const firebaseApp = initializeApp ( firebaseConfig ) ;
You can’t perform that action at this time.
0 commit comments