Skip to Content

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.

3 min read

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.

What runs on it

SlugKindWhereGoals
print-page-detailsTestIn code, the print pageStarts at view_item (product_page), converts at add_to_cart (product_form); also measures checkouts and purchases
home-introTestIn Content, the home pageStarts at the home page view, converts at view_item (product_page)
shipping-bannerFlagIn 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:

  1. The edge assigns. proxy.ts calls seedImproveCookies (lib/improve/request.ts) on every page request: the server SDK buckets the visitor with seedTestCookies and 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.
  2. The page carries every option. ImproveVariants (components/improve/improve-variants.tsx) renders each option of a test or flag, tagged with data-ob-imp and data-ob-opt. The page is the same bytes for every visitor and stays cached.
  3. 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.
  4. The exposure is recorded after paint, once per test, by the client SDK reading the value the edge already chose (lib/improve/client.ts).
  5. A change shows at once. A webhook to app/api/webhooks/improve/route.ts expires 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

  1. Clone the repository, then npm install and cp .env.example .env.local (npm 11 and Node.js 26).
  2. Set NEXT_PUBLIC_OBELISM_ORGANIZATION_ID, NEXT_PUBLIC_OBELISM_SPACE_ID and NEXT_PUBLIC_OBELISM_ENVIRONMENT: they turn on Improve and Numbers together. OBELISM_API_TOKEN lets the server read the datafile without the per-IP limit.
  3. Create the print-page-details test and the shipping-banner flag in that space, with options named like the ones in the code, and start them.
  4. Add the site's origin to the space's allowed origins for the environment (develop allows localhost), then npm run dev.
  5. Add a webhook to /api/webhooks/improve with IMPROVE_WEBHOOK_SECRET.

The README has the rest: the Shopify store, Content and Media.

On this page

Marks in the margin

  • Note
  • Watch out
  • Updated

Scribes marked doubtful lines in the margin. That practice is called obelism.