A/B tests
Tests you start in Convert › Tests are served to your site or app by the tracking code (0.5.0 or later): each visitor gets a stable variant, and showing it records the exposure, so the test page counts it.
Swap a whole block:
import { Experiment } from "@mrrocket/sdk/next";
<Experiment name="rr-home-logos" variants={{ control: <Hero />, a: <HeroWithLogos /> }} />;Ask for the variant:
const variant = useVariant("rr-pricing-annual-first"); // "control" | "a"Let tests change copy without a deploy by wrapping the text once. The id must be unique across your site:
<h1><Text id="home.headline">Sales training that sticks</Text></h1>With consent="cookies" every visitor stays in one variant (the ck_id cookie). In the default cookieless mode the variant holds for the page load; pass your own distinctId or call identify() to keep it across reloads (see Tracking). Exposures are recorded as $exposure.
Redirect tests#
A redirect test compares two whole pages: in Convert › Tests › New test pick the page under Runs on, Whole page under What it changes, and enter Variant A's page (/pricing-b or a full address). Build that page on your site first. Page redirects from Landing pages work the same way, for everyone.
Visitors of the test's page who get Variant A are sent to its page, with the page's UTM parameters and ck_x=<test>:a added. The SDK on that page records the exposure and takes ck_x out of the address bar; control stays and is recorded where it is. Needs SDK 0.7.0.
- Script tag: nothing to add. Use the hide snippet against a flash of the old page.
- Next.js:
<CockpitProvider>redirects after the first paint. To decide before the page renders, add the helper toproxy.ts(middleware.tsbefore Next.js 16):
import { NextResponse, type NextRequest } from "next/server";
import { experimentRedirect, getCockpitConfig } from "@mrrocket/sdk/next/proxy";
export async function proxy(request: NextRequest) {
const to = experimentRedirect(request, await getCockpitConfig({ timeoutMs: 800 }));
return to ? NextResponse.redirect(to, 307) : NextResponse.next();
}
export const config = { matcher: ["/pricing"] };A running test needs a stable id on the server: the ck_id cookie (consent="cookies", with withCockpitId once the visitor agreed) or your signed-in user id as experimentRedirect(request, config, { distinctId }). Without one the proxy leaves the test to the provider. Keep the matcher to the pages with a test or a redirect: each matched request waits for the config, at most timeoutMs.
Redirect tests are for websites; React Native apps have no pages to redirect.