Example store
Photo Studio, a live Shopify storefront on Next.js that sends page views, block clicks and its shop events to Numbers, and each paid order from its server. With its source.
Photo 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 is public (MIT), with Content, Improve and Media set up as well.
Visit the store
Photo Studio, live on Vercel
Read the source
Next.js 16 and Shopify's Hydrogen SDK, with Numbers, Content, Improve and Media
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 stay the same for every print, with what varies in params. That is what lets a funnel run from view_item_list to purchase, and Improve use view_item and add_to_cart as a test's goals.
Where to look in the code
| File | What it shows |
|---|---|
components/analytics/numbers-tracker.tsx | autoTrack from the 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 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
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
- 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 Numbers and Improve together. - Add the site's origin to the space's allowed origins for the environment (develop allows localhost), then
npm run dev. - For purchases, set
OBELISM_API_TOKEN, and subscribe the store'sorders/paidwebhook to/api/webhooks/shopifywithSHOPIFY_WEBHOOK_SECRET.
The README has the rest: the Shopify store, Content and Media.