Note: This documentation uses Next.js App Router. If you're still on Pages Router, see the migration guide.

Analytics SaaS

Create a SaaS application with user analytics, feature flags, and A/B testing capabilities.

Steps in the UI

  1. Start with "Supabase + Stripe SaaS" Quick Start
  2. Add the "Analytics" module for user tracking
  3. Add the "Feature Flags" module for A/B testing
  4. Add the "S3 Storage" module for file uploads
  5. Configure PostHog and feature flag settings

Modules included: analytics, feature-flags, s3-storage, auth-supabase, stripe-core

Routes générées

  • /dashboard- Tableau de bord avec analytics
  • /dashboard/analytics- Page d'analytics détaillée
  • /dashboard/features- Gestion des feature flags
  • /dashboard/experiments- A/B testing
  • /upload- Page de téléchargement de fichiers
  • /files- Gestion des fichiers
  • /api/analytics/route.ts- API d'analytics
  • /api/analytics/events/route.ts- API d'événements
  • /api/features/route.ts- API des feature flags
  • /api/features/[flagId]/route.ts- API d'un feature flag
  • /api/upload/route.ts- API de téléchargement
  • /api/files/route.ts- API de gestion des fichiers
  • /api/experiments/route.ts- API des expériences A/B
  • /api/experiments/[experimentId]/route.ts- API d'une expérience
  • /api/webhooks/posthog/route.ts- Webhook PostHog
  • /api/webhooks/plausible/route.ts- Webhook Plausible

.env minimal

# Database
DATABASE_URL="postgresql://user:password@localhost:5432/analytics-saas"

# NextAuth
NEXTAUTH_SECRET="your-secret-key-here"
NEXTAUTH_URL="http://localhost:3000"

# Supabase
NEXT_PUBLIC_SUPABASE_URL="https://your-project.supabase.co"
NEXT_PUBLIC_SUPABASE_ANON_KEY="your-anon-key"
SUPABASE_SERVICE_ROLE_KEY="your-service-role-key"

# Stripe
STRIPE_SECRET_KEY="sk_test_..."
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_..."
STRIPE_WEBHOOK_SECRET="whsec_..."

# Analytics
NEXT_PUBLIC_POSTHOG_KEY="phc_..."
POSTHOG_SECRET="phx_..."
NEXT_PUBLIC_PLAUSIBLE_DOMAIN="yourdomain.com"
PLAUSIBLE_API_KEY="your-plausible-api-key"

# Feature Flags
FEATURE_FLAG_PROVIDER="posthog"
POSTHOG_FEATURE_FLAGS_SECRET="phx_..."

# S3 Storage
AWS_ACCESS_KEY_ID="AKIA..."
AWS_SECRET_ACCESS_KEY="your-secret-key"
AWS_REGION="us-east-1"
AWS_S3_BUCKET="your-bucket-name"
NEXT_PUBLIC_S3_BUCKET_URL="https://your-bucket.s3.amazonaws.com"

Smoke test

curl -I http://localhost:3000

Expected: HTTP/1.1 200 OK

curl -I http://localhost:3000/dashboard/analytics

Expected: HTTP/1.1 302 Found (redirection) ou 200 OK (si authentifié)

curl -X GET "http://localhost:3000/api/analytics" \
  -H "Content-Type: application/json"

Expected: HTTP/1.1 401 Unauthorized (sans token) ou 200 OK (avec token)

curl -X GET "http://localhost:3000/api/features" \
  -H "Content-Type: application/json"

Expected: HTTP/1.1 200 OK avec liste des flags

curl -X POST "http://localhost:3000/api/upload" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@test.txt"

Expected: HTTP/1.1 401 Unauthorized (sans token) ou 200 OK (avec token)

curl -X POST "https://app.posthog.com/capture" \
  -H "Content-Type: application/json" \
  -d '{"api_key":"phc_...","event":"test","distinct_id":"test-user"}'

Expected: HTTP/1.1 200 OK

Actions déclenchées

Tracking d'événements

Quand : Actions utilisateur (page view, click, conversion)

Voir le résultat :
  • Dashboard PostHog > Events
  • Dashboard Plausible > Events
  • Base de données : table `analytics_events`
  • Console de développement (mode debug)

Feature flag evaluations

Quand : Chargement de page ou action utilisateur

Voir le résultat :
  • Dashboard PostHog > Feature Flags
  • Base de données : table `feature_flag_evaluations`
  • Console de développement (mode debug)
  • API `/api/features/[flagId]/evaluate`

A/B test assignments

Quand : Nouvel utilisateur ou nouvelle session

Voir le résultat :
  • Dashboard PostHog > Experiments
  • Base de données : table `experiment_assignments`
  • Console de développement (mode debug)

Uploads de fichiers

Quand : Téléchargement de fichier

Voir le résultat :
  • Bucket S3 > Fichiers uploadés
  • Base de données : table `files`
  • URL publique accessible via CDN

Webhooks analytics

Quand : Événements importants (conversion, erreur)

Voir le résultat :
  • Logs dans la console de développement
  • Base de données : table `webhook_events`
  • Dashboard PostHog > Webhooks

Need help?

If you need assistance with this example or have questions about boiler.plate modules, check out our documentation.