A/B Testing

A/B testing plugin that creates page variants in Payload collections and routes traffic at the edge via Next.js middleware.

Community 16 179/wk MIT v2.10.0

Installation

pnpm add @focus-reactive/payload-plugin-ab

About

The plugin adds A/B (split) testing to Payload CMS v3 projects running on Next.js. Editors create page variants directly inside the same collection as the original page, set a traffic percentage for each, and the plugin handles the rest. No separate variants collection or manual wiring is needed. On every save or delete, injected `beforeChange`, `afterChange`, and `afterDelete` hooks recompute a variant manifest (a path-keyed JSON object) and write it to a pluggable storage adapter. Two adapters ship with the package: `payloadGlobalAdapter` stores the manifest in a Payload global, while `vercelEdgeAdapter` writes it to Vercel Edge Config for sub-millisecond reads. Next.js middleware then reads the manifest at the edge and rewrites the incoming request to the assigned variant before any rendering happens, with no database round-trip. Variant documents are distinguished by an injected `_abVariantOf` relationship field. The plugin hides variants from the collection list view, makes the slug and tenant fields read-only on variants, and validates that the sum of variant pass percentages cannot exceed 100 (leaving the original at least 1%). Traffic percentages are versioned with the draft and publish lifecycle, so editing a percentage in the sidebar Variants panel stages it without affecting live traffic until the original page is published. Locale-aware manifest entries are generated automatically when Payload localization is enabled, and an optional `tenantField` supports multi-tenant setups. For measurement, an `ExperimentTracker` React client component reads the bucket and visitor cookies set by the middleware and pushes them to Google Analytics via `gtag` as custom dimension parameters. A `POST /api/_ab/duplicate` endpoint clones an existing page into a new variant with a hashed slug such as `about--4ji9`.

Package info

Package name
@focus-reactive/payload-plugin-ab
Latest version
2.10.0
Unpacked size
181 kB
License
MIT
Weekly downloads
179
Last publish
Aug 12, 2026

More from focusreactive

View profile

Similar plugins

More in Content