Skip to content

Commit fde64b5

Browse files
committed
add firebase integration for analytics & hosting
1 parent 9ae27cd commit fde64b5

File tree

4 files changed

+71
-11
lines changed

4 files changed

+71
-11
lines changed

.firebaserc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"projects": {
3-
"default": "flutterflow-docs-82026"
4-
}
3+
"default": "dreamflow-docs-2c50c",
4+
"prod": "dreamflow-docs-2c50c",
5+
"dreamflow-docs": "dreamflow-docs-2c50c"
6+
},
7+
"targets": {},
8+
"etags": {}
59
}

docusaurus.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const config: Config = {
1414

1515
clientModules: [
1616
require.resolve('./src/js/table-helpers.js'),
17+
require.resolve('./src/js/firebase-analytics.js'),
1718
],
1819
i18n: {
1920
defaultLocale: 'en',

firebase.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@
1111
"source": "**",
1212
"destination": "/index.html"
1313
}
14-
],
15-
"redirects": [
16-
{
17-
"source": "/blog/**",
18-
"destination": "/",
19-
"type": 301
20-
}
21-
2214
]
2315
}
24-
}
16+
}

src/js/firebase-analytics.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)