Analytics with Sanity

Seif Ghezala's photo
Seif Ghezala
Updated 2023-11-13 · 2 min
Table of contents

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:

Tracking page views

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:

Tracking click events with Sanity and Amplitude

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

SEO best practices on Sanity

When we build a website with Sanity, we configure SEO best practices to rank higher on search engine result pages.
Omar Benseddik's photo
Omar Benseddik
2022-09-05 · 7 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