Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit e7c7fe7

Browse files
committed
fix: firebase analytics
1 parent 1eeca77 commit e7c7fe7

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

Diff for: app/_component/Analytics.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
'use client';
22

3-
import { logEvent } from 'firebase/analytics';
3+
import { getAnalytics, logEvent, isSupported } from 'firebase/analytics';
44
import { usePathname } from 'next/navigation';
55
import { useEffect } from 'react';
6-
import { analytics } from '../firebase';
6+
import { firebaseApp } from '@/const/firebase';
77

88
export default function Analytics() {
99
const pathname = usePathname();
1010

1111
useEffect(() => {
12-
if (!analytics) return;
12+
if (!isSupported()) return;
13+
14+
const analytics = getAnalytics(firebaseApp);
1315
logEvent(analytics, 'page_view', {
1416
page_location: pathname,
1517
});

Diff for: app/firebase.ts renamed to const/firebase.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
// Import the functions you need from the SDKs you need
2-
import { getAnalytics } from 'firebase/analytics';
31
import { initializeApp } from 'firebase/app';
42

5-
// Your web app's Firebase configuration
6-
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
73
const firebaseConfig = {
84
apiKey: process.env.NEXT_PUBLIC_API_KEY,
95
authDomain: process.env.NEXT_PUBLIC_AUTH_DOMAIN,
@@ -14,7 +10,4 @@ const firebaseConfig = {
1410
measurementId: process.env.NEXT_PUBLIC_MEASUREMENT_ID,
1511
};
1612

17-
const firebaseApp = initializeApp(firebaseConfig);
18-
const analytics = getAnalytics(firebaseApp);
19-
20-
export { firebaseApp, analytics };
13+
export const firebaseApp = initializeApp(firebaseConfig);

0 commit comments

Comments
 (0)