Sanity
Add Rybbit analytics to your Sanity site
Sanity is a headless CMS: your frontend queries content from the Content Lake and Sanity Studio is only the editing app. The tracking snippet therefore goes into the frontend that renders your site, not into Sanity.
Get your tracking snippet
In your Rybbit dashboard, open Site Settings → Tracking Script and copy your snippet. It looks like this:
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>YOUR_SITE_ID is the numeric ID of your site. If you self-host Rybbit, app.rybbit.io is the domain of your own instance.
Add the snippet to Sanity
Sanity has no template or head setting to paste into. Add the snippet to the <head> of the frontend application that fetches content from Sanity.
Next.js is the most common Sanity frontend. Add the snippet with next/script in your root layout so it loads on every route. Follow the Next.js guide.
Add the snippet under app.head.script in nuxt.config.ts. Follow the Nuxt guide.
Verify installation
Open your live site in a new tab and click through a few pages. Within a few seconds the pageviews appear in the Rybbit dashboard.
If nothing shows up:
- View the page source and search for
script.js?siteId=to confirm the snippet is on the page. - Open the browser Network tab and check that
script.jsreturns200and thatPOSTrequests go to/api/track. - Disable ad blockers, or set up a proxy so the script loads from your own domain.
- See the script troubleshooting guide for other common causes.
Troubleshooting
- Embedded Studio pageviews: if Sanity Studio is mounted inside your frontend (for example at
/studioin a Next.js app), the snippet in your root layout also runs there. Adddata-skip-patterns='["/studio/**"]'to the script tag so editor sessions are not counted as visits. - Hosted Studio is not tracked: a Studio deployed to
*.sanity.studiois a separate app without the snippet, so time spent editing never appears in Rybbit.
Next steps
- Track custom events such as signups, purchases and button clicks.
- Identify users to connect sessions to accounts.
- Proxy the script through your own domain to bypass ad blockers.
- Script attributes let you skip or mask URLs and tag events.