# Example store (/docs/examples/example-store)

[Photo Studio](https://photo-studio.obelism.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](https://github.com/Obelism/example-shopify-store) is public (MIT), with Content, Numbers and Media set up around Improve.

<Cards>
	<Card
		title="Visit the store"
		href="https://photo-studio.obelism.studio"
		description="Photo Studio, live on Vercel"
	/>
	<Card
		title="Read the source"
		href="https://github.com/Obelism/example-shopify-store"
		description="Next.js 16 and Shopify's Hydrogen SDK, with Improve, Content, Numbers and Media"
	/>
</Cards>

## What runs on it [#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](https://numbers.obelism.studio/docs/example-store) 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 [#how-it-decides-before-the-first-paint]

This is the setup of [server-side tests on static pages](/docs/guides/static-server-side-tests), on Next.js:

1. **The edge assigns.** `proxy.ts` calls `seedImproveCookies` (`lib/improve/request.ts`) on every page request: the [server SDK](/docs/sdk/javascript#server) 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](/docs/sdk/javascript#client) reading the value the edge already chose (`lib/improve/client.ts`).
5. **A change shows at once.** A [webhook](/docs/integrations/webhooks) 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 [#tests-written-by-editors]

The `home-intro` test lives in a Content page. An editor adds Content's [improve block](https://content.obelism.studio/docs/guides/ab-tests) 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 [#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.
