This guide will help you set up the complete backend for your AI Portfolio using Supabase.
- Go to https://supabase.com
- Click "Start your project"
- Sign up with GitHub (recommended) or email
- Create a new organization (free tier is perfect)
- Click "New Project"
- Fill in the details:
- Project Name:
ai-portfolio(or your choice) - Database Password: Create a strong password (save it!)
- Region: Choose closest to your target audience
- Pricing Plan: Free (includes 500MB database, 50MB file storage)
- Project Name:
- Click "Create new project"
- Wait 2-3 minutes for setup to complete
- In your Supabase dashboard, go to SQL Editor (left sidebar)
- Click "New query"
- Open the file
supabase-setup.sqlfrom your project - Copy ALL the SQL code
- Paste it into the SQL Editor
- Click "Run" (or press Ctrl+Enter)
- You should see success messages
5 Tables:
visitor_sessions- Track visitor sessionspage_views- Track page viewschat_messages- Store all chat conversationscontact_submissions- Store contact form datauser_interactions- Track user actions (clicks, etc.)
4 Analytics Views:
daily_visitors- Daily visitor statisticspopular_questions- Most asked questionscontact_summary- Contact form summaryinteraction_summary- User interaction summary
2 Functions:
get_chat_statistics()- Get chat statscleanup_old_data()- Clean old records
- Go to Settings → API (in left sidebar)
- You'll see two important values:
https://xxxxxxxxxxxxx.supabase.co
- anon/public key (safe to use in frontend)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
- ✅ USE the anon/public key in your frontend
- ❌ NEVER use the service_role key in frontend
- The service_role key bypasses all security
- Open
config.jsin your project - Replace the placeholder values:
const SUPABASE_CONFIG = {
url: 'https://xxxxxxxxxxxxx.supabase.co', // Your Project URL
anonKey: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' // Your anon/public key
};- Save the file
- Open
index.htmlin your browser - Open browser console (F12)
- You should see:
✅ Supabase connected successfully - Try chatting with the AI
- Check your Supabase dashboard → Table Editor
- You should see new records in:
visitor_sessionschat_messagesuser_interactions
- Go to Table Editor in Supabase dashboard
- Select any table to view data
- Use filters and search
Run these queries to see analytics:
-- Recent chat messages
SELECT * FROM chat_messages
ORDER BY timestamp DESC
LIMIT 20;
-- Daily visitors
SELECT * FROM daily_visitors
LIMIT 30;
-- Popular questions
SELECT * FROM popular_questions;
-- Chat statistics
SELECT * FROM get_chat_statistics();
-- Recent contact submissions
SELECT name, email, message, submitted_at
FROM contact_submissions
ORDER BY submitted_at DESC;- Unique visitor ID (stored in localStorage)
- Session ID for each visit
- User agent (browser info)
- Screen resolution
- Referrer (how they found you)
- Landing page
- User questions
- AI responses
- Timestamps
- Session info
- Theme toggles
- Social link clicks
- Suggestion button clicks
- Chat cleared events
- Which pages visitors view
- Time spent on each page
- Name, email, message
- Submission timestamp
- Status tracking (new/read/replied)
All tables have RLS enabled:
- ✅ Anyone can INSERT (submit data)
- ✅ Only authenticated users (you) can READ
- ✅ Public data is protected
- ✅ No one can delete data from the frontend
- Go to Supabase Dashboard
- View tables in Table Editor
- Run queries in SQL Editor
CREATE TABLE newsletter_subscribers (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
email TEXT UNIQUE NOT NULL,
name TEXT,
subscribed_at TIMESTAMP DEFAULT NOW(),
status TEXT DEFAULT 'active'
);CREATE TABLE project_reactions (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
visitor_id TEXT NOT NULL,
project_name TEXT NOT NULL,
reaction_type TEXT NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);CREATE TABLE blog_comments (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
post_id TEXT NOT NULL,
visitor_id TEXT,
name TEXT NOT NULL,
email TEXT,
comment TEXT NOT NULL,
approved BOOLEAN DEFAULT false,
created_at TIMESTAMP DEFAULT NOW()
);CREATE TABLE site_feedback (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
visitor_id TEXT,
rating INTEGER CHECK (rating >= 1 AND rating <= 5),
feedback TEXT,
page_url TEXT,
created_at TIMESTAMP DEFAULT NOW()
);CREATE TABLE chat_feedback (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
message_id UUID REFERENCES chat_messages(id),
visitor_id TEXT NOT NULL,
helpful BOOLEAN NOT NULL,
feedback_text TEXT,
created_at TIMESTAMP DEFAULT NOW()
);- Get notified when someone submits contact form
- Daily analytics summary emails
- Use Supabase Realtime for live updates
- See visitors typing in real-time
- Create a separate admin page to view analytics
- Respond to contact submissions
- Monitor chat conversations
- Export chat data to improve AI responses
- Identify common questions
- Add new knowledge base entries
- Track which UI variations perform better
- Test different AI responses
- Review contact submissions
- Check popular questions
- Monitor visitor trends
- Clean old data (optional):
SELECT cleanup_old_data(90); -- Keep last 90 days- Check if
config.jsis loaded beforescript.js - Verify URL and API key are correct
- Make sure there are no spaces in the keys
- Check RLS policies in Supabase dashboard
- Verify table names match exactly
- Check browser console for detailed errors
- Open browser console (F12)
- Look for error messages
- Verify Supabase connection message appears
- Supabase handles CORS automatically
- Make sure you're using the anon key, not service_role
- Supabase Docs: https://supabase.com/docs
- Supabase Discord: https://discord.supabase.com
- Stack Overflow: Tag with
supabase
- Created Supabase account
- Created new project
- Ran SQL setup script
- Got API keys
- Updated config.js
- Tested in browser
- Verified data in tables
- Checked browser console for errors
- Reviewed analytics views
Your AI portfolio now has a complete backend with:
- ✅ Visitor tracking
- ✅ Chat history storage
- ✅ Contact form database
- ✅ Analytics and insights
- ✅ User interaction tracking
Start promoting your portfolio and watch the data flow in! 🚀