|
| 1 | +// Firebase Analytics configuration |
| 2 | +// Replace these values with your actual Firebase project configuration |
| 3 | +const firebaseConfig = { |
| 4 | + apiKey: "AIzaSyA3bYqcrFsRh44h6b5Vy2ggaNJH-LxTwu4", |
| 5 | + authDomain: "dreamflow-docs-2c50c.firebaseapp.com", |
| 6 | + projectId: "dreamflow-docs-2c50c", |
| 7 | + storageBucket: "dreamflow-docs-2c50c.firebasestorage.app", |
| 8 | + messagingSenderId: "426377507105", |
| 9 | + appId: "1:426377507105:web:7e6356038b1ca17b73ce60", |
| 10 | + measurementId: "G-XJVXWZ37RP" |
| 11 | +}; |
| 12 | + |
| 13 | +// Initialize Firebase Analytics |
| 14 | +if (typeof window !== 'undefined') { |
| 15 | + // Load Firebase SDKs dynamically using script tags (compatible with Docusaurus) |
| 16 | + const loadFirebaseScript = (src) => { |
| 17 | + return new Promise((resolve, reject) => { |
| 18 | + const script = document.createElement('script'); |
| 19 | + script.src = src; |
| 20 | + script.onload = resolve; |
| 21 | + script.onerror = reject; |
| 22 | + document.head.appendChild(script); |
| 23 | + }); |
| 24 | + }; |
| 25 | + |
| 26 | + // Load Firebase scripts and initialize |
| 27 | + const initializeFirebase = async () => { |
| 28 | + try { |
| 29 | + // Load Firebase SDKs |
| 30 | + await loadFirebaseScript('https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js'); |
| 31 | + await loadFirebaseScript('https://www.gstatic.com/firebasejs/10.7.1/firebase-analytics.js'); |
| 32 | + |
| 33 | + // Wait a bit for the scripts to be available |
| 34 | + await new Promise(resolve => setTimeout(resolve, 100)); |
| 35 | + |
| 36 | + // Initialize Firebase using the global firebase object |
| 37 | + const app = firebase.initializeApp(firebaseConfig); |
| 38 | + const analytics = firebase.analytics(); |
| 39 | + |
| 40 | + // Log page views |
| 41 | + analytics.logEvent('page_view', { |
| 42 | + page_title: document.title, |
| 43 | + page_location: window.location.href |
| 44 | + }); |
| 45 | + |
| 46 | + console.log('Firebase Analytics initialized successfully'); |
| 47 | + |
| 48 | + // Make analytics available globally for custom events |
| 49 | + window.firebaseAnalytics = analytics; |
| 50 | + window.firebaseLogEvent = analytics.logEvent.bind(analytics); |
| 51 | + |
| 52 | + } catch (error) { |
| 53 | + console.error('Error initializing Firebase Analytics:', error); |
| 54 | + } |
| 55 | + }; |
| 56 | + |
| 57 | + // Initialize when DOM is ready |
| 58 | + if (document.readyState === 'loading') { |
| 59 | + document.addEventListener('DOMContentLoaded', initializeFirebase); |
| 60 | + } else { |
| 61 | + initializeFirebase(); |
| 62 | + } |
| 63 | +} |
0 commit comments