Analytics with Sanity

Seif Ghezala's photo
Seif Ghezala
Posted 2022-09-12 · Updated 2022-12-14 · 3 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.

Sanity web development with Tinloof

Tinloof is a web development agency home to experienced developers who create powerful websites, apps and ecommerce solutions. We offer a wide range of web development, mobile development and design services specialising in headless CMS development and headless commerce development with Sanity. So, whether you’re starting from scratch or looking for optimisations, we can offer the support you need. Get in touch with us today to discuss your project goals with a member of our team.

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 as a CMS...
Omar Benseddik's photo
Omar Benseddik
2022-09-18 · 7 min