Analytics with Sanity

Seif Ghezala's photo
Seif Ghezala
Posted 2022-09-12 · 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:

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

Images and videos on Sanity

Images and videos have to be properly configured to rank in search engine result pages and not impact negatively page speed. In this piece we discuss how we leverage Sanity to easily...
Omar Benseddik's photo
Omar Benseddik
2022-09-18 · 7 min