mirror of
https://github.com/Vikeo/LifeTrinket.git
synced 2025-11-18 16:58:01 +00:00
Compare commits
2 Commits
bugfix/ext
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b94cd5efc0 | ||
|
|
d5aa60f0b3 |
@@ -1,11 +1,7 @@
|
|||||||
{
|
{
|
||||||
"hosting": {
|
"hosting": {
|
||||||
"public": "dist",
|
"public": "dist",
|
||||||
"ignore": [
|
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
|
||||||
"firebase.json",
|
|
||||||
"**/.*",
|
|
||||||
"**/node_modules/**"
|
|
||||||
],
|
|
||||||
"rewrites": [
|
"rewrites": [
|
||||||
{
|
{
|
||||||
"source": "**",
|
"source": "**",
|
||||||
|
|||||||
@@ -1,17 +1,30 @@
|
|||||||
import { initializeApp } from 'firebase/app';
|
import { initializeApp } from 'firebase/app';
|
||||||
import { getAnalytics, logEvent } from 'firebase/analytics';
|
import { Analytics, getAnalytics, logEvent } from 'firebase/analytics';
|
||||||
|
|
||||||
const firebaseConfig = {
|
const firebaseConfig = {
|
||||||
apiKey: 'AIzaSyCZ1AHMb5zmWS4VoRnC-OBxTswUfrJ0mlY',
|
apiKey: 'AIzaSyCZ1AHMb5zmWS4VoRnC-OBxTswUfrJ0mlY',
|
||||||
authDomain: 'life-trinket.firebaseapp.com',
|
authDomain: 'life-trinket.firebaseapp.com',
|
||||||
projectId: 'life-trinket',
|
projectId: 'life-trinket',
|
||||||
storageBucket: 'life-trinket.appspot.com',
|
storageBucket: 'life-trinket.firebasestorage.app',
|
||||||
messagingSenderId: '508011650619',
|
messagingSenderId: '508011650619',
|
||||||
appId: '1:508011650619:web:bdc7d0b6f8707b1f9e861e',
|
appId: '1:508011650619:web:bdc7d0b6f8707b1f9e861e',
|
||||||
|
measurementId: 'G-BE86QSSG14',
|
||||||
};
|
};
|
||||||
|
|
||||||
const app = initializeApp(firebaseConfig);
|
const app = initializeApp(firebaseConfig);
|
||||||
const analytics = getAnalytics(app);
|
let analytics: Analytics | null = null;
|
||||||
|
|
||||||
|
const getAnalyticsInstance = () => {
|
||||||
|
if (!analytics) {
|
||||||
|
try {
|
||||||
|
analytics = getAnalytics(app);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to initialize Firebase Analytics:', error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return analytics;
|
||||||
|
};
|
||||||
|
|
||||||
export const useAnalytics = () => {
|
export const useAnalytics = () => {
|
||||||
const trackEvent = (
|
const trackEvent = (
|
||||||
@@ -23,12 +36,18 @@ export const useAnalytics = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const analyticsInstance = getAnalyticsInstance();
|
||||||
|
if (!analyticsInstance) {
|
||||||
|
console.warn('Analytics not available');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const paramsWithVersion = {
|
const paramsWithVersion = {
|
||||||
...eventParams,
|
...eventParams,
|
||||||
app_version: import.meta.env.VITE_APP_VERSION,
|
app_version: import.meta.env.VITE_APP_VERSION,
|
||||||
};
|
};
|
||||||
|
|
||||||
logEvent(analytics, eventName, paramsWithVersion);
|
logEvent(analyticsInstance, eventName, paramsWithVersion);
|
||||||
};
|
};
|
||||||
|
|
||||||
return { trackEvent };
|
return { trackEvent };
|
||||||
|
|||||||
Reference in New Issue
Block a user