Analytics with Sanity

Seif Ghezala's photo
Seif Ghezala
Posted 2022-09-12 · Updated 2023-04-09 · 2 min

At Tinloof, we aim to create websites that retain users, and tracking their interactions is key to making that happen.

We’ll explain in this article the analytics possibilities with Sanity and how we make them possible in our projects.

The concepts discussed here apply to any Analytics tool like Google Analytics, Fathom, or Amplitude.

Page view events

Each page has a unique URL, so you don’t need any extra Sanity set up to track their page views.

Since the websites we build are SPAs (Single Page Applications), we make sure to track the page view on page transition as well.

Here's an example of what such events look like when visiting Zego's website:

Click events

We add an optional “Tracking name” field to CTA schemas on Sanity.

We then add a global listener in the frontend to trigger click events on buttons that have the “Tracking name” field set.

This allows marketers to control 100% which buttons are tracked and the event names.

Here's a screenshot showing both the "Tracking name" field set on Sanity and the resulting event on Amplitude when a user clicks on the CTA:

Endless analytics possibilities

Because Sanity is fully customizable and because the websites we build are modular, tracking possibilities are endless.

For example, if we have a form module, we can add Sanity fields to track the form submission and both the success and error states of the form.

Recent articles

10 Shopify SEO best practices with Sanity and Remix

Ecommerce competition keeps increasing - for each product you now have dozens of alternatives. As a result, CAC (Customer Acquisition Cost) increases, pushing ecommerce business owners...
Omar Benseddik's photo
Omar Benseddik
2023-02-01 · 10 min

Translating Shopify stores with Sanity

At Tinloof, we have an internal library that does a lot of heavy lifting when it comes to building fast Remix websites that have their content managed from Sanity. A while ago, we...
Seif Ghezala's photo
Seif Ghezala
2023-01-31 · 4 min