Spaces:
Running
Running
Supabase Authentication & Analytics Setup
Quick Setup (5 minutes)
1. Create Supabase Project
- Go to https://app.supabase.com/
- Click "New Project"
- Choose organization, name your project (e.g., "ds-agent-analytics")
- Set a strong database password (save it!)
- Choose a region close to your users
- Click "Create new project" and wait ~2 minutes
2. Get Your API Keys
- Go to Settings β API
- Copy:
- Project URL:
https://xxxxx.supabase.co - anon/public key:
eyJhbGciOi...(long string)
- Project URL:
3. Configure Environment
Create .env file in FRRONTEEEND/:
VITE_SUPABASE_URL=https://your-project-id.supabase.co
VITE_SUPABASE_ANON_KEY=your-anon-key-here
For HuggingFace Spaces, add these as Secrets:
- Go to your Space β Settings β Repository secrets
- Add
VITE_SUPABASE_URLandVITE_SUPABASE_ANON_KEY
4. Set Up Database Tables
- Go to SQL Editor in Supabase dashboard
- Copy contents of
supabase_schema.sql - Click "Run" to create tables and policies
5. Enable Authentication Providers (Optional)
Email (enabled by default)
- Works out of the box
Google OAuth
- Go to Authentication β Providers β Google
- Enable it
- Create OAuth credentials at Google Cloud Console
- Add your Supabase callback URL:
https://your-project.supabase.co/auth/v1/callback - Copy Client ID and Secret to Supabase
GitHub OAuth
- Go to Authentication β Providers β GitHub
- Enable it
- Create OAuth App at GitHub Developer Settings
- Add callback URL:
https://your-project.supabase.co/auth/v1/callback - Copy Client ID and Secret to Supabase
Features Included
Authentication
- β Email/Password sign up & sign in
- β Google OAuth (optional)
- β GitHub OAuth (optional)
- β Persistent sessions
- β Guest mode (can use without signing in)
Analytics Tracking
- β Per-query tracking (user, session, query text, success/failure)
- β Session tracking (start time, end time, query count)
- β Browser info capture
- β Anonymous user support
Dashboard Views (in Supabase)
daily_active_users- DAU metricspopular_queries- Most common queriesagent_usage_stats- Which agents are used most
Viewing Analytics
Quick Stats in Supabase
- Go to Table Editor
- Select
usage_analyticsoruser_sessions - Use filters and sorting to analyze data
SQL Queries
-- Total users last 7 days
SELECT COUNT(DISTINCT user_id)
FROM usage_analytics
WHERE created_at > NOW() - INTERVAL '7 days';
-- Queries per day
SELECT DATE(created_at), COUNT(*)
FROM usage_analytics
GROUP BY DATE(created_at)
ORDER BY 1 DESC;
-- Success rate
SELECT
SUM(CASE WHEN success THEN 1 ELSE 0 END)::float / COUNT(*) * 100 as success_rate
FROM usage_analytics;
Free Tier Limits (Plenty for demos!)
- 50,000 monthly active users
- 500 MB database storage
- 1 GB file storage
- Unlimited API requests
- 2 projects
Troubleshooting
"Invalid API key"
- Check that your
.envfile has the correct values - Make sure you're using the
anonkey, not theservice_rolekey
OAuth not working
- Verify callback URL is correct in provider settings
- Check that the provider is enabled in Supabase
Data not appearing
- Check browser console for errors
- Verify RLS policies are created (run the SQL schema)
- Check Supabase logs for errors