Để Gemini giải thích lỗi và gợi ý cách sửa
Firebase Crashlytics + Gemini = Debug thông minh không cần đọc stack trace dài dòng.
Thiết lập Crashlytics:
- Cài đặt SDK:
npm install firebase
- Khởi tạo trong app:
import { initializeApp } from 'firebase/app';
import { getAnalytics } from 'firebase/analytics';
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
- Bật Crashlytics trong Console: Firebase Console > Crashlytics > Enable
Sử dụng Gemini để debug:
Khi có crash report, thay vì tự đọc, bạn hỏi Gemini:
Prompt: "Giải thích crash này cho người mới học:
TypeError: Cannot read properties of undefined (reading 'map')
at CommunityFeed (CommunityFeed.tsx:45)
at renderWithHooks (react-dom.development.js:...)
Và đề xuất cách fix phù hợp với React best practices"
Gemini trả lời: "Lỗi này xảy ra vì bạn đang gọi .map() trên một biến chưa được khởi tạo (undefined).
Nguyên nhân có thể:
- Data chưa load xong từ API nhưng component đã render
- API trả về null thay vì array rỗng
Cách fix:
// Trước
{posts.map(post => <PostCard />)}
// Sau - thêm optional chaining và fallback
{(posts ?? []).map(post => <PostCard />)}
// Hoặc kiểm tra loading state
{loading ? <Spinner /> : posts.map(...)}
```"
**Analytics Insights:**
- Xem user behavior: pages visited, time spent
- Funnel analysis: đăng ký → đăng nhập → mua khóa học
- Hỏi Gemini: "Phân tích dữ liệu Analytics này và gợi ý cách tăng conversion rate"
