feat(firebase): Add Firebase SDK and initialize Analytics

This commit integrates the Firebase SDK into the application to enable Firebase services, starting with Google Analytics.

Key changes include:
- Added the `firebase` package as a dependency.
- Included Firebase project configuration variables in the production environment file.
- Created a new `firebase.ts` utility to centralize Firebase app initialization.
- Integrated the `FirebaseAnalytics` component into the root layout to enable analytics tracking across the entire application.
This commit is contained in:
AmirReza Jamali
2025-10-04 09:28:40 +03:30
parent df8deaee9b
commit b58ea368ec
13 changed files with 1147 additions and 23 deletions
+35
View File
@@ -0,0 +1,35 @@
import { COOKIE_KEYS } from "@/lib/shared/cookies";
import { initializeApp } from "firebase/app";
import { getMessaging, getToken } from "firebase/messaging";
import Cookies from "js-cookie";
const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
};
const app = initializeApp(firebaseConfig);
export const messaging = getMessaging(app);
export const requestForToken = () => {
return getToken(messaging)
.then((currentToken) => {
if (currentToken) {
console.log("current token for client: ", currentToken);
Cookies.set(COOKIE_KEYS.device_token, currentToken);
} else {
// Show permission request UI
console.log(
"No registration token available. Request permission to generate one.",
);
// ...
}
})
.catch((err) => {
console.log("An error occurred while retrieving token. ", err);
// ...
});
};