Skip to content

Commit a05f6f3

Browse files
committed
feat: integrate Google Analytics with Firebase
- Added Google Analytics support using Firebase SDK - Initialized Analytics conditionally based on support - Integrated with existing Firebase services (Firestore and Realtime Database)
1 parent c41639c commit a05f6f3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/lib/firebase.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { initializeApp } from 'firebase/app';
22
import { getDatabase } from 'firebase/database';
33
import { initializeFirestore, setLogLevel } from 'firebase/firestore';
4+
import { getAnalytics, isSupported } from 'firebase/analytics';
45

56
const firebaseConfig = {
67
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
@@ -26,5 +27,13 @@ if (process.env.NODE_ENV === 'development') {
2627
setLogLevel('error');
2728
}
2829

30+
let analytics;
31+
isSupported().then((supported) => {
32+
if (supported) {
33+
analytics = getAnalytics(app);
34+
}
35+
});
36+
2937
export const database = getDatabase(app);
3038
export const firestore = firestoreInstance;
39+
export const analyticsInstance = analytics;

0 commit comments

Comments
 (0)