Codapult includes a lightweight A/B testing framework for pricing pages, onboarding flows, messaging, and product experiments.
Capabilities
- Weighted variants, such as 50/50 or 80/20.
- Deterministic bucketing so the same user keeps the same variant.
- Target percentage rollout.
- Conversion tracking.
- Experiment lifecycle: draft, running, paused, completed.
- Admin API and admin UI hooks.
Usage
import { getVariant, trackConversion } from '@/lib/experiments';
const variant = await getVariant('pricing-hero', userId);
if (variant === 'annual-first') {
// Render the annual-first UI.
}
await trackConversion('pricing-hero', userId);
Creating experiments
Create and start an experiment from the admin API. The id values in the
variants are the strings returned by getVariant; their weights should total 100.
curl -X POST https://your-app.example.com/api/admin/experiments -H 'Content-Type: application/json' -b '<admin-session-cookie>' -d '{"action":"create","key":"pricing-hero","name":"Pricing hero","variants":[{"id":"monthly-first","name":"Monthly first","weight":50},{"id":"annual-first","name":"Annual first","weight":50}],"targetPercentage":100,"goalEvent":"checkout_started"}'
curl -X POST https://your-app.example.com/api/admin/experiments -H 'Content-Type: application/json' -b '<admin-session-cookie>' -d '{"action":"start","key":"pricing-hero"}'
The API requires a platform administrator session. In the application, pass a
stable user ID to getVariant so assignment persists for that user. Call
trackConversion only for users who were assigned; it returns false when no
assignment exists. Read per-variant conversion counts from GET /api/admin/experiments.
Feature flag
ENABLE_EXPERIMENTS="false"
When disabled, experiment admin surfaces return 404.