Examples
Example store
Photo Studio, a live Shopify storefront on Next.js whose prerendered pages run tests and flags decided before the first paint, in code and in Content's pages. With its source.
Photo Studio is a print shop for a fictional photographer, built on Next.js and Shopify. Every page is prerendered, yet each visitor's tests and flags are decided before the page paints: no layout shift, no flash of the control, no deploy per test. Its source is public (MIT), with Content, Numbers and Media set up around Improve.
Visit the store
Photo Studio, live on Vercel
Read the source
Next.js 16 and Shopify's Hydrogen SDK, with Improve, Content, Numbers and Media
What runs on it
| Slug | Kind | Where | Goals |
|---|---|---|---|
print-page-details | Test | In code, the print page | Starts at view_item (product_page), converts at add_to_cart (product_form); also measures checkouts and purchases |
home-intro | Test | In Content, the home page | Starts at the home page view, converts at view_item (product_page) |
shipping-banner | Flag | In code, above the nav |
The goals are Numbers events by name and scope, the same ones the store's reports and funnels count. A purchase comes from Shopify's orders/paid webhook and still counts for the visitor who was in the test.
How it decides before the first paint
This is the setup of server-side tests on static pages, on Next.js:
- The edge assigns.
proxy.tscallsseedImproveCookies(lib/improve/request.ts) on every page request: the server SDK buckets the visitor withseedTestCookiesand sets one cookie per test. Bots keep the defaults. The datafile is kept for 30 seconds, and a failed fetch is remembered as long, so an Improve outage can't hold up every page. - The page carries every option.
ImproveVariants(components/improve/improve-variants.tsx) renders each option of a test or flag, tagged withdata-ob-impanddata-ob-opt. The page is the same bytes for every visitor and stays cached. - The head shows one.
ImproveHead(components/improve/improve-head.tsx) puts an inline script and a stylesheet in the root layout's<head>: the script marks<html>with the option from each running test's cookie, and the CSS shows that option and hides the others, before the body paints. A stopped test, or a cookie naming an unknown option, shows the default. - The exposure is recorded after paint, once per test, by the client SDK reading the value the edge already chose (
lib/improve/client.ts). - A change shows at once. A webhook to
app/api/webhooks/improve/route.tsexpires the cached datafile the head is built from, so starting or stopping a test doesn't wait for the cache; the edge's own copy is at most 30 seconds old.
Editors and the canvas never count: a request with Content's editor token or site-editing cookie sends no exposure and no events.
Tests written by editors
The home-intro test lives in a Content page. An editor adds Content's improve block to the page, picks the test and writes the blocks for each option; the store renders it through the same ImproveVariants, so it is decided before paint like a test in code. A block below the page type's fold renders only the default and swaps in the visitor's option after it loads.
Run it on your own space
- Clone the repository, then
npm installandcp .env.example .env.local(npm 11 and Node.js 26). - Set
NEXT_PUBLIC_OBELISM_ORGANIZATION_ID,NEXT_PUBLIC_OBELISM_SPACE_IDandNEXT_PUBLIC_OBELISM_ENVIRONMENT: they turn on Improve and Numbers together.OBELISM_API_TOKENlets the server read the datafile without the per-IP limit. - Create the
print-page-detailstest and theshipping-bannerflag in that space, with options named like the ones in the code, and start them. - Add the site's origin to the space's allowed origins for the environment (develop allows localhost), then
npm run dev. - Add a webhook to
/api/webhooks/improvewithIMPROVE_WEBHOOK_SECRET.
The README has the rest: the Shopify store, Content and Media.