This project implements a proper server-side remote experiment using Amplitude's Node.js SDK, following the official documentation.
- Backend: Node.js server with Amplitude Experiment Node.js SDK
- Frontend: HTML/CSS/JS client that calls backend API
- Experiment:
test-sever-side-remotewithcontrolandtreatmentvariants - Tracking: Automatic exposure tracking via server-side Amplitude Analytics
npm install# Development (with auto-restart)
npm run dev
# Production
npm startOpen your browser to: http://localhost:3000
- User clicks property → Frontend sends request to
/api/experiment - Backend fetches variants → Uses
Experiment.initializeRemote()with server deployment key - Backend tracks exposure → Automatically sends
$exposureevent to Amplitude - Backend returns variants → Frontend applies styling based on variant
- Exposure data appears → In Amplitude Experiment dashboard
GET /api/experiment- Fetch experiment variants for a userGET /api/health- Health check endpointGET /- Serve frontend application
PORT=3000 # Server port (optional, defaults to 3000)- Server Key:
server-J2Hw5SNQsPvvJFgOqjeQfecowTIoxD3X(used by Node.js SDK) - Analytics Key:
a3f7a8d1c910f8fabc60dd7e947438f1(used for tracking)
- Flag:
test-sever-side-remote - Variants:
control(blue buttons),treatment(red buttons) - Tracking: Automatic exposure events via server-side Analytics SDK
The server logs will show:
- Experiment SDK initialization
- Variant fetch requests
- Exposure event tracking
- Any errors
In browser dev tools, verify:
- Calls to
/api/experimentare successful - Variants are returned correctly
- No CORS errors
- Exposure events should appear in Experiment dashboard
- Events should have correct
flag_keyandvariantvalues - User properties should be populated correctly
server.js- Node.js backend with Experiment SDKpackage.json- Dependencies and scriptsindex.html- Frontend HTML with API clientscript.js- Frontend JavaScript with experiment logicstyle.css- CSS styling