Lovablefeatureadvanced

Add Affiliate Tracking to Lovable App

Add referral tracking with unique links, conversion logging, and affiliate dashboard.

What you'll get

An affiliate tracking system with referral links, click/conversion tracking, affiliate dashboard, and admin management.

The Prompt

Add an affiliate/referral tracking system to my Lovable app.

REQUIREMENTS:
1. Generate unique referral links for each affiliate (e.g., yoursite.com?ref=ABC123). Store the referral code in a cookie lasting 30 days.
2. Create an affiliate signup form for new affiliates: name, email, website, payment method (PayPal email). Save to a Supabase "affiliates" table.
3. Track clicks: when a user visits with a ref parameter, log the click in a "referral_clicks" table with timestamp, IP (hashed), and user agent.
4. Track conversions: when a referred user completes a purchase or signup, log it in a "referral_conversions" table linked to the affiliate.
5. Create an affiliate dashboard showing: total clicks, conversions, conversion rate, earnings, and payout history.
6. Support configurable commission rates (flat fee or percentage) stored in the affiliates table.
7. Admin panel for managing affiliates: approve/reject applications, view performance, process payouts.

DATABASE:
- "affiliates" table: id, user_id, name, email, website, referral_code (unique), commission_type, commission_rate, status (pending/active/suspended), payout_email, created_at
- "referral_clicks" table: id, affiliate_id, ip_hash, user_agent, page_url, created_at
- "referral_conversions" table: id, affiliate_id, order_id, amount, commission_earned, status (pending/paid), created_at
- RLS: Affiliates see only their own data. Admins see all.

ENVIRONMENT VARIABLES:
- COOKIE_DOMAIN (for referral cookie)

SECURITY:
- Hash IP addresses — never store raw IPs.
- Validate referral codes server-side.
- Prevent self-referrals by checking affiliate email against buyer email.

Replace these variables

VariableReplace with
[COMMISSION_RATE]Default commission rate (e.g., 20% or $10 flat)
[COOKIE_DURATION]Referral cookie duration in days (e.g., 30)

Tips for best results

Set the referral cookie duration to at least 30 days — shorter windows lose conversions.

Hash IP addresses for privacy compliance and never store raw user IPs.

Prevent self-referrals by comparing affiliate and buyer email addresses.

Follow-up prompts

Add payout automation

Add automated monthly payouts via Stripe Connect. Calculate earnings, generate invoices, and process payments to affiliate bank accounts.

Add leaderboard

Add an affiliate leaderboard showing top performers by conversions and earnings. Gamify with badges for milestones.

Related prompts