ignitionstack.pro v1.0 is out! Read the announcement →
Skip to Content

Affiliate Program

IgnitionStack ships a full affiliate program with public signup (/[locale]/affiliates), a logged-in dashboard (/[locale]/affiliates/dashboard), Supabase-backed tracking tables, and GA4 instrumentation. This guide explains how the feature is wired so future changes stay aligned with the architecture playbook.

Page Overview

LayerFileResponsibility
Landing Routesrc/app/[locale]/(pages)/affiliates/page.tsxSets locale, SEO metadata, and redirects existing affiliates to the dashboard. Renders hero/benefits plus AffiliateSignupForm or login CTA. Includes <AffiliateLandingAnalytics locale={locale} /> for client-only GA tracking.
Dashboard Routesrc/app/[locale]/(pages)/affiliates/dashboard/page.tsxAuth-guarded page that loads the current affiliate + stats via server queries and renders <AffiliateDashboard />. Marked dynamic = "force-dynamic" to allow cookie reads.
Componentssrc/app/components/affiliates/*Dashboard widgets (AffiliateDashboard, AffiliateLinkShare, AffiliateRecentConversions), signup form, and AffiliateTracker (global referral tracker injected in src/app/[locale]/layout.tsx).
Server Queriessrc/app/server/affiliates/*Read-only helpers: getCurrentUserAffiliate, getAffiliateStats, isAffiliateCodeValid, etc.
Server Actionssrc/app/actions/affiliates/*Mutations such as becomeAffiliate, updateAffiliate, recordAffiliateClick/Conversion, and requestPayout. All use ActionResult + validation wrappers.
Repository + Mappersrc/app/lib/repositories/affiliate-repository.ts, src/app/lib/mappers/affiliate.tsCentralized Supabase access, type mapping, cache revalidation tags.
Supabase Schemasupabase/migrations/schema/66-72_*.sqlTables (affiliates, affiliate_clicks, affiliate_conversions, affiliate_payouts), RLS, indexes, triggers, auto-code generator, and seed script (seed/05_seed_affiliates.sql).

Data Model

Types live in src/app/types/affiliate.ts and mirror the Supabase schema:

Supabase Policies & Triggers

Key migrations:

  1. 66_affiliates.sql – base table with affiliate_code, commission/discount ranges, and counter columns updated by triggers.
  2. 67-69_* – click/conversion/payout tables with foreign keys and indexes.
  3. 70_affiliate_rls_enable.sql + 71_affiliate_policies.sql – enforce RLS: users read/update their own records, anonymous visitors can insert clicks, only service-role inserts conversions.
  4. 72_affiliate_triggers.sql – auto-increment stats, keep updated_at fresh, generate codes, and sync payouts. Remember to update supabase/migrations/roolback/06_drop_tables.sql when adding new functions/triggers.
  5. seed/05_seed_affiliates.sql – demo records for local testing (admin user + sample activity).

After editing migrations run:

npm run db:push npm run db:gen

Tracking & Analytics

GA4 events live in src/app/lib/analytics-events.ts under affiliateEvents:

Emitters:

For any new interaction, extend affiliateEvents instead of scattering trackGAEvent calls.

Internationalization

All copy sits under the Affiliates namespace inside src/i18n/messages/{locale}.json with the following structure:

Affiliates: { meta, landing, signup, linkShare, dashboard: { meta, title, subtitle, stats.*, commissionInfo.*, payout.* }, conversions, settings }

When adding new UI, add keys to pt.json (source), then mirror en/es. Use npm run i18n:check before committing.

Extending the Feature

  1. New payout methods – add enum entries to paymentMethodSchema, update Supabase column checks, extend repository createPayout, and surface UI in AffiliateSignupForm + translations.
  2. Additional dashboard widgets – expand AffiliateRepository.getStats to return aggregated data, update AffiliateDashboard to render cards, and document metrics here.
  3. Webhook automation – record conversions via recordAffiliateConversion from Stripe webhooks, then call completeConversion once payment settles.
  4. Cookie window – adjust AFFILIATE_COOKIE_DAYS in affiliate-tracker.tsx and ensure marketing copy (landing stats) matches.
  5. Admin tooling – use AffiliateRepository.findAll/count from a protected admin route; reuse adminUpdateAffiliateSchema for moderation.

Testing Checklist

Operations

Document updates here whenever the affiliate experience changes (pricing, payout logic, dashboard metrics, analytics schema, etc.).