This guide will walk you through setting up the complete feedback system with Firebase Cloud Functions and SendGrid email notifications.
- Firebase Project - Already configured with Firestore
- Firebase Blaze Plan - Required for Cloud Functions (pay-as-you-go, free tier available)
- SendGrid Account - For email notifications
- Node.js 18+ - For Firebase Functions
- Firebase CLI - For deployment
Firebase Cloud Functions require the Blaze (pay-as-you-go) plan. The good news:
- Free tier included: 2 million function invocations per month
- Feedback system usage: Very minimal cost (likely free)
- Upgrade at: https://console.firebase.google.com/project/gardenguardian-de65c/usage/details
If you prefer not to upgrade, the feedback system will still work with:
- ✅ Frontend components - Feedback collection works perfectly
- ✅ Firestore storage - All feedback saved to database
- ✅ Admin dashboard - Full feedback viewing capability
- ❌ Email notifications - Manual checking via admin dashboard
Visit: https://console.firebase.google.com/project/gardenguardian-de65c/usage/details
- Click "Modify Plan"
- Select "Blaze (Pay as you go)"
- Note: Functions have generous free tier (2M invocations/month)
npm install -g firebase-tools
firebase login# From your project root
firebase init functions
# Select:
# - Use existing project (your GardenGuardian project)
# - TypeScript
# - ESLint: Yes
# - Install dependencies: Yes# Set your SendGrid API key in Firebase Functions config
firebase functions:config:set sendgrid.api_key="YOUR_SENDGRID_API_KEY_HERE"
# Verify the configuration
firebase functions:config:getcd functions
npm install
npm run build
firebase deploy --only functionsAfter deployment, make a GET request to set up the admin user:
# Replace YOUR_PROJECT_ID with your actual Firebase project ID
curl https://YOUR_PROJECT_ID-default-rtdb.firebaseio.com/setupAdminOr visit the URL in your browser:
https://YOUR_PROJECT_ID-default-rtdb.firebaseio.com/setupAdmin
If you prefer not to upgrade Firebase now, you can still use the complete feedback system:
firebase deploy --only firestore:rulesIn Firebase Console → Authentication → Users:
-
Find your user (
ashishithape.ai@gmail.com) -
Click on the user
-
In "Custom claims" section, add:
{"admin": true}
- Frontend feedback system: ✅ Fully functional
- Firestore storage: ✅ All feedback saved
- Admin dashboard: ✅ Available at
/admin/feedback - Email notifications: ❌ Manual dashboard checking instead
-
Verify Sender Email:
- Go to SendGrid Dashboard → Settings → Sender Authentication
- Verify
noreply@gardenguardian.com.au(or your domain) - Update the
fromfield infunctions/src/index.tsif needed
-
Email Template (Optional):
- The function uses inline HTML, but you can create SendGrid templates
- Update the function to use template IDs if preferred
The admin email ashishithape.ai@gmail.com is automatically granted admin access when you run the setupAdmin function.
- Log in with the admin email
- Navigate to
/admin/feedback - View all feedback and statistics
If you need to grant admin access to additional users:
// Call this from your app or Firebase Console
import { httpsCallable } from 'firebase/functions';
const setAdminStatus = httpsCallable(functions, 'setAdminStatus');
setAdminStatus({
email: 'another-admin@example.com',
isAdmin: true
});The feedback system is automatically integrated into:
- Diagnosis Complete Page - Shows after 5 seconds on
/diagnosis/[id] - Share/Save Actions - Can be triggered manually
- Exit Intent - Available for other pages
Add the ContextualFeedback component to any page:
import { ContextualFeedback } from '@/components/contextual-feedback';
// In your component JSX
<ContextualFeedback
context="page-name"
trigger="delayed"
delay={3000}
/>Trigger feedback programmatically:
// Trigger feedback after a specific action
const triggerFeedback = () => {
window.dispatchEvent(new CustomEvent('trigger-feedback', {
detail: { context: 'custom-action' }
}));
};{
id: string; // Auto-generated document ID
rating: 1-5; // Emoji rating
context: string; // Where feedback was given
page: string; // Page URL
diagnosisId?: string; // Related diagnosis (if applicable)
message?: string; // Optional user message
email?: string; // Optional contact email
userId: string; // Firebase user ID or 'anonymous'
userEmail?: string; // User's login email (if authenticated)
userAgent: string; // Browser info
timestamp: Date; // When feedback was given
createdAt: Timestamp; // Firestore timestamp
}-
Check Function Logs:
firebase functions:log
-
Verify Firestore Rules: Ensure your Firestore rules allow writing to the
feedbackcollection:// In firestore.rules match /feedback/{document} { allow read, write: if true; // Or your specific rules }
-
Verify API Key:
firebase functions:config:get sendgrid
-
Check Sender Authentication:
- Ensure your sender email is verified in SendGrid
- Update the
fromfield in the function if needed
-
Check SendGrid Activity:
- Go to SendGrid Dashboard → Activity
- Look for failed deliveries or bounces
-
Check Custom Claims:
// In Firebase Console → Authentication → Users // Click on user → Custom claims should show {"admin": true}
-
Force Token Refresh:
// In your app await auth.currentUser?.getIdToken(true);
-
Check Local Storage:
- Clear
feedback-*keys in localStorage to reset cooldown - Or test in incognito mode
- Clear
-
Verify Component Import:
import { ContextualFeedback } from '@/components/contextual-feedback';
- Admin Dashboard:
/admin/feedback - Firebase Console: Firestore →
feedbackcollection - SendGrid Analytics: Dashboard → Activity
// From Firebase Console or custom script
const feedback = await getDocs(collection(db, 'feedback'));
const data = feedback.docs.map(doc => ({ id: doc.id, ...doc.data() }));
console.log(JSON.stringify(data, null, 2));cd functions
npm run build
firebase deploy --only functionsThe feedback components are in:
hooks/use-feedback.tscomponents/ui/feedback-drawer.tsxcomponents/contextual-feedback.tsx
Changes to these files are deployed with your Next.js app (no separate deployment needed).
After setup, you should see:
- ✅ Feedback drawer appears on diagnosis pages
- ✅ Email notifications sent to
ashishithape.ai@gmail.com - ✅ Admin dashboard accessible at
/admin/feedback - ✅ Feedback data stored in Firestore
- ✅ Admin user has proper custom claims
If you encounter issues:
- Check Firebase Console logs
- Verify SendGrid activity
- Test in incognito mode to bypass localStorage cooldowns
- Ensure all environment variables are set correctly
The feedback system is now fully operational and will help you gather valuable user insights to improve GardenGuardian AI! 🌱