A/B tests with consent: stable assignment, conversion goals and results with significance, no extra cookies
Install
genpm add @core/experimentsWhat you get
- Source in src/lib/experiments/, 8 files. (21.4 kB)
- AI rules in src/lib/experiments/AGENTS.md, plus IDE rule files.
- Env vars added to .env.example: EXPERIMENTS_SECRET.
- Resolves @core/consent, @core/contracts, @core/db, @core/jobs for you.
README
This package has no README.
This is exactly what your AI reads when it works in src/lib/experiments. Nothing else is added to its context.
@core/experiments — rules for AI agents
Purpose
A/B tests that respect consent. Visitors who accepted analytics cookies get a stable variant (deterministic hash of
the pseudonymous consent id, no extra cookie); everyone else always sees the control and nothing is stored.
Conversions are recorded once per visitor and goal; results show rates, lift, p-value and a 95 % confidence interval
(two-proportion z-test) and are frozen when the experiment stops. Tables: experiments, experiment_participants.
Map
index.ts—getVariant,recordConversion,upsertExperiment,setExperimentStatus,experimentResults,experimentsAdminResource,pruneExperimentsJob,compare.react.ts—<Experiment name cookieHeader variants={{ a, b }} />(server component).stats.ts— statistics without dependencies.schema.ts— tables.
Integration
- Requires @core/consent (the banner) and its cookie. Env:
EXPERIMENTS_SECRET(≥ 32 random chars). - Migrations as in
src/lib/db/AGENTS.md. AddexperimentsAdminResourcetosrc/genpm/admin.ts(with kit-landing: its "A/B tests (optional)" lines). - Create the experiment in the admin (key, goal, variants: the first is the control), then press "Start".
- Render:
const { variant } = await getVariant('hero-test', cookieHeader)(cookie header of the request) and show the matching content; or<Experiment name="hero-test" cookieHeader={…} variants={{ a: <A />, b: <B /> }} />. - Conversion: where the goal happens on the server,
await recordConversion('lead', req.headers.get('cookie')). - Schedule
experiments.prunedaily (@core/jobsschedule) to delete participants 30 days after an experiment stops (with kit-cms, itssetup-schedules.tsdoes it). - Verify: with analytics accepted the same browser always sees the same variant; with cookies rejected, always the control.
Conventions
- Decide only when
significantis true and the test ran at least one or two full weeks (weekday effects). - Change one thing per experiment; don't edit variants or weights while it runs (blocked; stop and create a new one).
Don't
- Don't assign or record visitors without analytics consent, and don't store emails or ids in experiments.
- Don't stop a test early because one variant "looks better" (peeking inflates false positives).
- Don't use experiments to show different prices to different people.
# @core/experiments — rules for AI agents
## Purpose
A/B tests that respect consent. Visitors who accepted analytics cookies get a stable variant (deterministic hash of
the pseudonymous consent id, no extra cookie); everyone else always sees the control and nothing is stored.
Conversions are recorded once per visitor and goal; results show rates, lift, p-value and a 95 % confidence interval
(two-proportion z-test) and are frozen when the experiment stops. Tables: `experiments`, `experiment_participants`.
## Map
- `index.ts` — `getVariant`, `recordConversion`, `upsertExperiment`, `setExperimentStatus`, `experimentResults`, `experimentsAdminResource`, `pruneExperimentsJob`, `compare`.
- `react.ts` — `<Experiment name cookieHeader variants={{ a, b }} />` (server component).
- `stats.ts` — statistics without dependencies. `schema.ts` — tables.
## Integration
1. Requires @core/consent (the banner) and its cookie. Env: `EXPERIMENTS_SECRET` (≥ 32 random chars).
2. Migrations as in `src/lib/db/AGENTS.md`. Add `experimentsAdminResource` to `src/genpm/admin.ts` (with kit-landing:
its "A/B tests (optional)" lines).
3. Create the experiment in the admin (key, goal, variants: the first is the control), then press "Start".
4. Render: `const { variant } = await getVariant('hero-test', cookieHeader)` (cookie header of the request) and show
the matching content; or `<Experiment name="hero-test" cookieHeader={…} variants={{ a: <A />, b: <B /> }} />`.
5. Conversion: where the goal happens on the server, `await recordConversion('lead', req.headers.get('cookie'))`.
6. Schedule `experiments.prune` daily (@core/jobs `schedule`) to delete participants 30 days after an experiment stops
(with kit-cms, its `setup-schedules.ts` does it).
7. Verify: with analytics accepted the same browser always sees the same variant; with cookies rejected, always the control.
## Conventions
- Decide only when `significant` is true and the test ran at least one or two full weeks (weekday effects).
- Change one thing per experiment; don't edit variants or weights while it runs (blocked; stop and create a new one).
## Don't
- Don't assign or record visitors without analytics consent, and don't store emails or ids in experiments.
- Don't stop a test early because one variant "looks better" (peeking inflates false positives).
- Don't use experiments to show different prices to different people.
The exact tree that will be injected, after .genpmignore. Pinned to
MIT License
Copyright (c) 2026 GenPM
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This package declares no MCP servers.
| Version | Commit | Published | Scan |
|---|---|---|---|
| 1.0.1 | c83c2b1 | 3 hours ago | scan passed |
- proposed
- GenPM proposes the npm command and runs it only if you say yes.
- Used by (1)
- @core/kit-landing ^1.0.0
- scan
- scan passed · 0 findings
- commit
- v1.0.1 → c83c2b1012acc5483bb03c0706dba0781378102b · verified after fetch
- scripts
- None. GenPM never runs package code.
- license
- MIT
- Quality
- 100/100
- Recognized licensepassed
- AGENTS.md explains its purposepassed
- AGENTS.md has integration stepspassed
- AGENTS.md lists conventions or don'tspassed
- Includes testspassed
- Security scan passedpassed
- Released in the last 6 monthspassed
- Verified publisherpassed
- Summary and keywordspassed
- report
- See something wrong?