Skip to main content
Sanity → MatomoIntegration guide

Connecting Sanity to Matomo

Sanity is a headless content platform, which means like every headless CMS it holds no commercial record and the tracking question lives elsewhere. Matomo can be self-hosted with no third party in the chain, which makes it the one analytics destination where the data genuinely never leaves infrastructure you control. The join between them succeeds or fails on one thing: whether the first-party visitor ID reaches the front-end conversion, not a Sanity record before the conversion happens, because Matomo can only match a conversion it can tie back to a click it recognizes.

Free30 minutesNo obligation

Specific to this pair

Self-hosted Matomo with Sanity: block-level content tracking

Mark Sanity page-builder blocks with Matomo content attributes holding block type and document _id to see which modules are seen and clicked. On each route change set URL and title, track the page view and rescan content. Skip preview mode, and send orders from commerce via the HTTP Tracking API with order ID and visitor ID.

Matomo's content tracking, which records impressions and interactions on marked-up blocks, maps well onto Sanity page builders. Each block rendered from a Sanity array item can carry Matomo's content attributes with the block type and the document _id, so you can see which modules on a page are seen and clicked. That is the question editors ask after rebuilding a page, and page-level views cannot answer it.

On a client-routed front end, both page views and content tracking need help. On each route change set the custom URL and title, track the page view, and rescan the new page for content blocks; otherwise Matomo reports one long page and only the first page's blocks. Exclude preview: Sanity's Presentation tool loads the live site inside the Studio, so detect draft mode and skip the tracker there.

Orders come from commerce, sent through the Matomo HTTP Tracking API with the order ID and the visitor ID captured in the front end, so a refreshed confirmation page does not record a second sale. Running Matomo yourself next to a Sanity front end means you own archiving load too: content-block tracking multiplies stored events, so check archive processing time after enabling it on high-traffic pages.

Sanity → Matomo · what breaks

Why this join usually fails — Sanity → Matomo

  1. 01

    The first-party visitor ID never reaches Sanity

    The front-end application does the routing, the caching and the identifier capture. Single-page navigation is the usual failure and it belongs to the framework rather than to Sanity.

  2. 02

    A headless stack diagnosed at the wrong layer

    Route changes not tracked, identifiers lost between pages — these are front-end framework problems that get filed against the CMS because that is the name everyone knows.

  3. 03

    Owning the pipeline means owning the outage

    The advantage is that nothing blocks it. The cost is that when the tracking database fills or falls behind on a weekend, the data is gone and no vendor is paging anyone. Hosted tools fail more visibly.

  4. 04

    Nothing reconciles afterwards

    Matomo exposes raw visit logs, so you can inspect the actual hit rather than an aggregate. Check the log, and check ingestion lag alongside it.

Sanity → Matomo · the fix

What working looks like — Sanity → Matomo

  • The first-party visitor ID on every conversion

  • Conversions arriving in Matomo

    The event lands in your own database and is queryable directly, including the raw log, which most analytics products do not expose.

  • Reconciled against the source

Sanity → Matomo · architecture

How Sanity and Matomo actually connect

  1. 1

    Sanity holds the truth

    Sanity's real-time content APIs make it excellent at what it does and irrelevant to conversion measurement. Establishing that early saves the client money.

  2. 2

    Matomo needs a click to match

    The site ID, the visitor identifier and the event or ecommerce order. Self-hosted instances additionally need the tracker endpoint reachable and the database keeping up, which hosted tools do not fail at.

  3. 3

    The identifier is the bridge

    The first-party visitor ID, captured at the visit and carried into the front-end conversion, not a Sanity record.

  4. 4

    The event source decides reliability

    Send from wherever the money is recorded, not from the content layer.

  5. 5

    Deduplication at the destination

    Matomo deduplicates ecommerce orders on order ID. Without one, a refreshed confirmation page records a second order.

Sanity → Matomo · normal or broken

Working vs. broken, side by side — Sanity → Matomo

Normal, not a fault

  • The first-party visitor ID present on the conversion

  • Sent from your commerce or CRM system

  • Deduplicated correctly

    Matomo deduplicates ecommerce orders on order ID. Without one, a refreshed confirmation page records a second order.

  • Reconciles with the source

Actually broken

  • The first-party visitor ID missing on most records

    The front-end application does the routing, the caching and the identifier capture. Single-page navigation is the usual failure and it belongs to the framework rather than to Sanity.

  • Sent from the browser

    Route changes not tracked, identifiers lost between pages — these are front-end framework problems that get filed against the CMS because that is the name everyone knows.

  • Counted twice, or not at all

    The advantage is that nothing blocks it. The cost is that when the tracking database fills or falls behind on a weekend, the data is gone and no vendor is paging anyone. Hosted tools fail more visibly.

  • Nobody has reconciled it

Sanity → Matomo · diagnose

Diagnostic order — Sanity → Matomo

  1. 01

    Count conversions carrying the first-party visitor ID

  2. 02

    Follow one real conversion end to end

  3. 03

    Identify the front-end framework, not the CMS

    The routing behaviour that breaks tracking belongs to Next.js, Nuxt or whatever renders the site.

  4. 04

    Check tracker reachability and database lag before debugging any tag

    On self-hosted analytics the answer is infrastructure more often than instrumentation.

  5. 05

    Read the match rate, not the success message

    Matomo exposes raw visit logs, so you can inspect the actual hit rather than an aggregate. Check the log, and check ingestion lag alongside it.

Sanity → Matomo · prove

How it gets proven — Sanity → Matomo

Source of truth

Your commerce, CRM or billing system — Sanity has no orders and no customers.

  • The first-party visitor ID confirmed present on a live conversion.
  • Orders reconciled against the Matomo ecommerce log with order-ID deduplication verified.
  • The conversion confirmed sourced from the commerce system, with front-end routing verified separately.

Sanity → Matomo · free audit

What we check in the free audit

  • Count conversions carrying the first-party visitor ID
  • Follow one real conversion end to end
  • Identify the front-end framework, not the CMS
  • Check tracker reachability and database lag before debugging any tag
  • Read the match rate, not the success message

Checked against

Your commerce, CRM or billing system — Sanity has no orders and no customers.

Get my free conversion tracking audit

Free30 minutesNo obligation

Sanity → Matomo · when not to buy

When you don't need this — Sanity → Matomo

  • Measure identifier coverage yourself first — pull your last hundred conversions and count how many carry the first-party visitor ID.
  • There is no Sanity-specific build. Fix the front end and the commerce integration; the CMS is not in the path.
  • If you have no privacy or ownership requirement and no team to run it, a hosted product removes the only real cost of this one.

Sanity → Matomo · what we deliver

What gets built — Sanity → Matomo

  • Identifier capture into Sanity

    Capture and persist the identifier server-side in the front-end application, then carry it into the system that records the sale.

  • Event source: your commerce or CRM system

    Send from wherever the money is recorded, not from the content layer.

  • Dispatch to Matomo

    The Matomo HTTP Tracking API, posted server-side from your order system.

  • Reversals where they exist

    Handled by the commerce system.

Written guarantee

95%+ tracking accuracy

Measured against Your commerce, CRM or billing system — Sanity has no orders and no customers.. Miss it and we keep working at no cost.

Get my free conversion tracking audit

From $400 · See packages

FAQ

Sanity → Matomo questions, answered

Render Matomo's content-tracking attributes on each block with its type and document ID, and rescan for blocks after every route change.

Free · 30 min

Get Sanity and Matomo joined properly

Free30 minutesNo obligation