X Enterprises

nuxt-x-affiliate

Nuxt 4 layer for affiliate/referral program pages, tracking, and dashboard components — signup forms, referral link tracking, commission tiers, and a full affiliate dashboard built on Nuxt UI v4.

nuxt-x-affiliate

Affiliate/referral program layer for Nuxt 4. Provides 10 auto-imported XAF-prefixed components, 2 composables for state management and referral tracking, 2 pre-built pages, and a fully typed app.config.ts interface — all built on Nuxt UI v4. The consuming app is responsible for data fetching; the layer handles all UI, state, and referral tracking logic.

Installation

npm install @xenterprises/nuxt-x-affiliate
// nuxt.config.ts
export default defineNuxtConfig({
  extends: [['@xenterprises/nuxt-x-affiliate', { install: true }]],
})

Override defaults in app.config.ts:

export default defineAppConfig({
  xAffiliate: {
    referralParam: 'ref',
    referralBaseUrl: 'https://yoursite.com',
    cookieDays: 30,
    currency: 'USD',
    shareMessage: 'Check this out!',
  },
})

What the Layer Provides

Components (auto-imported, XAF prefix):

  • XAFBanner — Promotional hero banner with CTA and variant styling (gradient / primary / dark)
  • XAFCommissionTiers — Commission tier display with current-tier highlight and progress bar
  • XAFDashboard — Full affiliate dashboard composing all sub-components
  • XAFLeaderboard — Top affiliates ranking with earnings and referral counts
  • XAFPayoutHistory — Payout history table with status badges
  • XAFReferralLink — Referral link display with copy-to-clipboard
  • XAFReferralTable — Referral tracking table (source, status, commission, date)
  • XAFShareButtons — Social sharing buttons (Twitter, Facebook, LinkedIn, Email)
  • XAFSignupForm — Affiliate application form with configurable fields
  • XAFStatsCards — Stats overview cards (clicks, conversions, earnings, pending)

Composables:

  • useAffiliate() — SSR-safe state management for affiliate data, stats, referrals, payouts, and tiers
  • useReferralTracking() — Detects and persists referral codes via URL params and cookies

Pages:

  • /affiliate — Public landing page with hero, benefits, commission tiers, and signup form
  • /affiliate/dashboard — Authenticated affiliate dashboard with full metrics and tools

App Config Options

Configure under the xAffiliate key in app.config.ts:

OptionTypeDefaultDescription
referralParamstring'ref'URL query parameter for referral codes
referralBaseUrlstring''Base URL for generated referral links
cookieNamestring'x_affiliate_ref'Cookie name for storing referral codes
cookieDaysnumber30Cookie expiration in days
currencystring'USD'Default currency code for formatting
shareMessagestring'Check this out!'Default social share message
landing.heroobjectSee defaultsHero section (title, description, ctaLabel, highlightText, variant)
landing.benefitsarray3 defaultsBenefits cards (icon, title, description)
signup.*objectSee defaultsSignup form (title, subtitle, submitLabel, field visibility)

Minimal Usage Example

<script setup>
const { affiliate, stats, referralUrl, setAffiliate, setStats } = useAffiliate()

// Your app fetches data and populates state
onMounted(async () => {
  const data = await $fetch('/api/affiliate/me')
  setAffiliate(data.affiliate)
  setStats(data.stats)
})
</script>

<template>
  <XAFDashboard />
</template>

Component Props Reference

XAFBanner

PropTypeDefaultDescription
titlestringrequiredBanner headline text
descriptionstringSubtitle text
ctaLabelstring'Join Now'CTA button label
ctaTostring'/affiliate'CTA link destination
ctaColorstring'white'CTA button color
highlightTextstringHighlight badge text
variant'primary' | 'gradient' | 'dark''gradient'Visual style
showDecorationbooleantrueShow background decoration

XAFSignupForm

PropTypeDefaultDescription
titlestring'Join Our Affiliate Program'Form title
subtitlestring'Earn commissions...'Form subtitle
submitLabelstring'Apply Now'Submit button label
successMessagestring'Application submitted...'Success message after submit
showWebsitebooleantrueShow website URL field
showCompanybooleanfalseShow company name field
showMessagebooleantrueShow promotion strategy textarea

Emits: submit(data: AffiliateFormData)

XAFStatsCards

PropTypeDefaultDescription
statsAffiliateStats | nullrequiredStats data object
currencystring'USD'Currency code for formatting
PropTypeDefaultDescription
affiliateAffiliate | nullrequiredCurrent affiliate data
referralUrlstringrequiredFull referral URL to display and copy

XAFCommissionTiers

PropTypeDefaultDescription
tiersCommissionTier[]requiredArray of commission tier definitions
currentTierIdstring | nullnullID of the affiliate's current tier
nextTierCommissionTier | nullnullNext tier to reach
progressToNextTiernumber0Progress percentage (0–100)

XAFLeaderboard

PropTypeDefaultDescription
entries{ name, referrals, earnings }[]requiredLeaderboard entries
titlestring'Top Affiliates'Section title
periodstring'This Month'Time period badge
currencystring'USD'Currency code

Composables

useAffiliate()

SSR-safe state management using Nuxt useState. The consuming app calls setters after fetching data from its API.

const {
  affiliate,           // Affiliate | null
  stats,               // AffiliateStats | null
  referrals,           // Referral[]
  payouts,             // Payout[]
  tiers,               // CommissionTier[]
  isLoading,           // boolean
  error,               // string | null
  isAuthenticated,     // computed — whether affiliate is set
  isActive,            // computed — whether status is 'active'
  referralUrl,         // computed — full referral URL with code
  currentTier,         // computed — current CommissionTier
  nextTier,            // computed — next CommissionTier
  progressToNextTier,  // computed — progress % to next tier
  setAffiliate,
  setStats,
  setReferrals,
  setPayouts,
  setTiers,
  reset,
} = useAffiliate()

useReferralTracking()

Detects referral codes from URL query parameters and persists them in cookies. SSR-safe — cookie operations are guarded by import.meta.server checks.

const {
  referralCode,    // string | null
  referralSource,  // string | null (UTM source)
  detectReferral,  // () => void — detect from URL params or cookie
  clearReferral,   // () => void
  hasReferral,     // () => boolean
  getReferralCode, // () => string | null
} = useReferralTracking()

Environment Variables

This layer reads no environment variables directly. All configuration is through app.config.ts.

Layer Architecture

PathPurpose
nuxt.config.tsRegisters @nuxt/ui module and Tailwind CSS
app.config.tsAll configurable options under xAffiliate namespace with TypeScript type augmentation
app/composables/useAffiliate and useReferralTracking — all state and tracking logic
app/components/X/AF/10 auto-imported XAF-prefixed components built on Nuxt UI v4
app/pages/affiliate/Landing page and dashboard route
app/types/TypeScript interfaces: Affiliate, Referral, AffiliateStats, Payout, CommissionTier, AffiliateResource, SharePlatform

AI Context

package: "@xenterprises/nuxt-x-affiliate"
use-when: >
  Adding an affiliate/referral program to a Nuxt 4 app. Provides the full
  landing page (/affiliate), authenticated dashboard (/affiliate/dashboard),
  10 XAF* components, and 2 composables. The consuming app fetches data
  from its own API and populates useAffiliate() state via setters — the
  layer handles all UI, referral link generation, and social sharing.
  Call useReferralTracking().detectReferral() in a plugin or layout to
  capture ?ref= params and persist them in a cookie. Configure branding
  and form fields under xAffiliate in app.config.ts.
Copyright © 2026