An affiliate postback tracking system built with Node.js/Express backend, PostgreSQL database, and Next.js frontend with shadcn/ui components.
- Click Tracking: Track affiliate clicks with unique click IDs
- Postback Tracking: Receive and validate conversion postbacks
- Dashboard: View conversion data for each affiliate
- Postback URL Generator: Generate postback URLs for affiliates
- Backend: Node.js + Express
- Database: NeonDB (Serverless PostgreSQL)
- Frontend: Next.js 14 + shadcn/ui + Tailwind CSS
- Node.js 18+
- NeonDB account (free tier available)
- npm or yarn
-
Install dependencies:
npm run install:all
-
Setup NeonDB Database:
a. Create a free account at NeonDB
b. Create a new project and get your connection string
c. Run the schema using NeonDB's SQL Editor:
- Copy contents of
backend/database/schema.sql - Paste and run in NeonDB console
See
backend/database/neon-setup.mdfor detailed instructions. - Copy contents of
-
Configure Backend:
# Copy environment file cp backend/env.example backend/.env # Edit backend/.env with your NeonDB connection string DATABASE_URL=postgresql://username:[email protected]/neondb?sslmode=require PORT=3001
-
Start Development Servers:
# Terminal 1 - Backend npm run dev:backend # Terminal 2 - Frontend npm run dev:frontend
-
Access the Application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:3001
GET /click?affiliate_id=1&click_id=abc123
Records a click for tracking.
GET /postback?affiliate_id=1&click_id=abc123&amount=100¤cy=USD
Records a conversion if the click ID is valid for the affiliate.
GET /affiliate/:id/conversions
Returns all conversions for a specific affiliate.
GET /affiliates
Returns all available affiliates.
CREATE TABLE affiliates (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL
);
CREATE TABLE clicks (
id SERIAL PRIMARY KEY,
affiliate_id INT REFERENCES affiliates(id),
click_id VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE conversions (
id SERIAL PRIMARY KEY,
click_id VARCHAR(255) REFERENCES clicks(click_id),
amount FLOAT NOT NULL,
currency VARCHAR(10) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);- Homepage (
/): Select affiliate and navigate to dashboard or postback URL - Dashboard (
/dashboard?affiliate_id=1): View conversions table with stats - Postback URL (
/postback-url?affiliate_id=1): Display postback URL template
- Track Clicks: Send GET request to
/clickendpoint with affiliate_id and unique click_id - User Converts: When user completes desired action, fire postback
- Send Postback: Make GET request to
/postbackendpoint with conversion data - View Results: Check dashboard to see recorded conversions
// 1. Track click
fetch('/api/click?affiliate_id=1&click_id=user123_' + Date.now())
// 2. On conversion, send postback
fetch('/api/postback?affiliate_id=1&click_id=user123_1234567890&amount=99.99¤cy=USD')- 404: Click ID not found for affiliate
- 409: Duplicate click ID or conversion already recorded
- 400: Missing required parameters
- 500: Server errors
- Backend runs on port 3001
- Frontend runs on port 3000
- API calls are proxied from frontend to backend via Next.js rewrites
- Hot reloading enabled for both frontend and backend
- Set production NeonDB connection string in backend/.env
- Ensure NODE_ENV=production for proper SSL handling
- Build both applications:
npm run build
- Start production servers or deploy to your preferred platform
- NeonDB automatically handles SSL in production
- Free tier includes 3 GiB storage and 100 hours compute/month
- Scales to zero when not in use (cost-effective)
- Built-in connection pooling and backup
This is a minimal implementation. Feel free to extend with additional features like:
- Authentication
- Rate limiting
- Webhook signatures
- Real-time dashboard updates
- Advanced reporting