Skip to Content

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.

3 min read

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.

What it sends

EventScopeSent from
Page viewsThe browser, on every navigation
ClicksThe browser, on any element with a data-numbers-id
outbound_clickThe destinationThe browser, on a link to another site
view_item_listcollection_pageThe browser, on a series
view_itemproduct_pageThe browser, on a print, with its price and ids
add_to_cartproduct_formThe browser, from the print's buy button
begin_checkoutcartThe browser, on the way to Shopify's checkout
purchasecheckoutThe 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

FileWhat it shows
components/analytics/numbers-tracker.tsxautoTrack from the SDK: page views, tagged clicks and outbound links
lib/numbers/client.tsOne client for the browser, and trackEvent; nothing is sent while an editor works in Content
components/analytics/trackers.tsxview_item_list and view_item, deduplicated per series and print
components/product-detail/buy-buttons.tsxadd_to_cart, and the visitor's id on the cart line
lib/cart/client.tsbegin_checkout
app/api/webhooks/shopify/route.tspurchase, sent with the log API once Shopify reports the order paid
components/cms/cms-body-client.tsxEach 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

  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.

On this page

Marks in the margin

  • Note
  • Watch out
  • Updated

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