A Next.js-based affiliate hub that dynamically generates tracked affiliate links using UTM parameters and integrates with Supabase for product management.
- Dynamic product review pages with slug-based routing
- Automatic UTM parameter tracking and mapping to ClickBank HopLinks
- Google Analytics 4 integration for CTA click tracking
- Supabase-backed product data management
- TypeScript for type safety
- Tailwind CSS for styling
- Node.js 18+
- npm or yarn
- Supabase account and project
- Install dependencies:
npm install- Set up environment variables:
Create a
.env.localfile in the root directory:
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
NEXT_PUBLIC_AFFILIATE_NICKNAME=danaipro
NEXT_PUBLIC_DEFAULT_LANDING_PAGE=Default
NEXT_PUBLIC_GA4_MEASUREMENT_ID=your_ga4_measurement_id-
Set up Supabase database:
- Run the migration file
supabase/migrations/001_create_products_table.sqlin your Supabase SQL editor to create the products table. - Run
supabase/migrations/002_add_admin_policies.sqlto set up admin access policies.
- Run the migration file
-
Set up Admin Authentication:
- In your Supabase dashboard, go to Authentication > Users
- Click "Add User" and create an admin account with email/password
- This account will be used to access the admin panel at
/admin/login
-
Run the development server:
npm run devOpen http://localhost:3000 to see the application.
├── app/ # Next.js App Router pages
│ ├── actions/ # Server actions
│ │ ├── auth.ts # Authentication actions
│ │ └── products.ts # Product CRUD actions
│ ├── admin/ # Admin panel routes
│ │ ├── login/ # Admin login page
│ │ └── products/ # Product management
│ ├── layout.tsx # Root layout with GA4
│ ├── page.tsx # Homepage
│ ├── review/[slug]/ # Dynamic product review pages
│ └── globals.css # Global styles
├── components/ # React components
│ ├── admin/ # Admin components
│ │ ├── ProductForm.tsx
│ │ ├── ProductEditForm.tsx
│ │ ├── ProductList.tsx
│ │ └── SignOutButton.tsx
│ ├── CTASection.tsx # Buy button with tracking
│ ├── GoogleAnalytics.tsx # GA4 script loader
│ └── ProductHero.tsx # Product hero section
├── lib/
│ ├── auth.ts # Authentication utilities
│ ├── hooks/
│ │ └── useHopLink.ts # Hook for UTM → HopLink mapping
│ ├── repositories/
│ │ └── products.ts # Supabase product queries
│ ├── supabase/
│ │ ├── client.ts # Client-side Supabase client
│ │ └── server.ts # Server-side Supabase client
│ └── analytics.ts # Analytics helper functions
├── config/
│ └── site.ts # Site configuration
└── supabase/
└── migrations/ # Database migrations
Access the admin panel at /admin/login using the credentials you created in Supabase.
Admin Features:
- Product Management: Add, edit, and delete products through the web interface
- Product List: View all products in a table with quick actions
- Product Form: Easy-to-use form for adding/editing products with all required fields
Admin Routes:
/admin/login- Admin login page/admin/products- Product list and management dashboard/admin/products/new- Add new product form/admin/products/[id]/edit- Edit existing product
- Log in at
/admin/login - Click "Add Product" on the products page
- Fill in the form:
- Slug: URL-friendly identifier (e.g., "ai-tool")
- Product Name: Display name
- HopLink: Your ClickBank HopLink URL
- Review Title: Title for the review page
- Review Body: HTML content for the review
- Image URL: Optional product image
- Affiliate Nickname: Your ClickBank affiliate nickname (defaults to "danaipro")
- Landing Page: Landing page type (defaults to "Default")
- Click "Create Product"
You can also add products directly to your Supabase products table with the following fields:
slug(unique): URL-friendly identifier (e.g., "ai-tool")product_name: Display name of the producthoplink: Base ClickBank HopLink URLreview_title: Title for the review pagereview_body: HTML content for the reviewimage_url(optional): Product image URLaffiliate_nickname: Your ClickBank affiliate nickname (default: "danaipro")landing_page: Landing page type (default: "Default")
When linking to your review pages from external sources, use UTM parameters:
https://yourdomain.com/review/ai-tool?utm_source=youtube&utm_campaign=ai-review-video
The system will automatically:
- Capture the UTM parameters
- Map them to ClickBank tracking parameters:
utm_source→traffic_sourceutm_campaign→campaignutm_medium→traffic_typeutm_term→adutm_content→creative
- Append them to the HopLink when users click "Buy Now"
- Google Analytics 4: Tracks page views and CTA clicks
- ClickBank: Tracks conversions with full attribution via tracking parameters
Run tests:
npm testRun tests in watch mode:
npm run test:watchnpm run build
npm startISC