# Example store (/docs/example-store)

[Photo Studio](https://photo-studio.obelism.studio) is a print shop for a fictional photographer, built on Next.js and Shopify. Numbers counts it from the first page view to the paid order: page views, clicks on every Content block, the shop's events from the browser, and each purchase from the server. Its [source](https://github.com/Obelism/example-shopify-store) is public (MIT), with Content, Improve and Media set up as well.

<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 Numbers, Content, Improve and Media"
	/>
</Cards>

## What it sends [#what-it-sends]

| Event | Scope | Sent from |
| --- | --- | --- |
| Page views | | The browser, on every navigation |
| Clicks | | The browser, on any element with a `data-numbers-id` |
| `outbound_click` | The destination | The browser, on a link to another site |
| `view_item_list` | `collection_page` | The browser, on a series |
| `view_item` | `product_page` | The browser, on a print, with its price and ids |
| `add_to_cart` | `product_form` | The browser, from the print's buy button |
| `begin_checkout` | `cart` | The browser, on the way to Shopify's checkout |
| `purchase` | `checkout` | The server, from Shopify's `orders/paid` webhook |

The names are GA4's and the [scopes](/docs/tracking/events) stay the same for every print, with what varies in `params`. That is what lets a [funnel](/docs/reports#funnels) run from `view_item_list` to `purchase`, and Improve use `view_item` and `add_to_cart` as a [test's goals](https://improve.obelism.studio/docs/examples/example-store).

## Where to look in the code [#where-to-look-in-the-code]

| File | What it shows |
| --- | --- |
| `components/analytics/numbers-tracker.tsx` | `autoTrack` from the [SDK](/docs/sdk): page views, tagged clicks and outbound links |
| `lib/numbers/client.ts` | One client for the browser, and `trackEvent`; nothing is sent while an editor works in Content |
| `components/analytics/trackers.tsx` | `view_item_list` and `view_item`, deduplicated per series and print |
| `components/product-detail/buy-buttons.tsx` | `add_to_cart`, and the visitor's id on the cart line |
| `lib/cart/client.ts` | `begin_checkout` |
| `app/api/webhooks/shopify/route.ts` | `purchase`, sent with the [log API](/docs/api/log) once Shopify reports the order paid |
| `components/cms/cms-body-client.tsx` | Each Content block's `_uid` as its `data-numbers-id`, which Content's canvas shows click rates for |

## A purchase that counts for the right visitor [#a-purchase-that-counts-for-the-right-visitor]

Checkout happens on Shopify, where the site's script doesn't run. So the buy button adds the visitor's id to the cart line as a hidden attribute, `_obelism_visitor_id`. When Shopify sends `orders/paid`, the webhook reads it back from the order and sends `purchase` with the environment's API token: the order's value, currency, items, tax and shipping, counted for the visitor who placed it. The webhook answers Shopify first and sends after, so a slow request can't make Shopify retry and count the order twice.

## 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 Numbers and Improve together.
3. Add the site's origin to the space's allowed origins for the environment (develop allows localhost), then `npm run dev`.
4. For purchases, set `OBELISM_API_TOKEN`, and subscribe the store's `orders/paid` webhook to `/api/webhooks/shopify` with `SHOPIFY_WEBHOOK_SECRET`.

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