Documentation menuContent management systems: Sanity

Content management systems

Add Loogika to Sanity

Sanity is a headless CMS (content management system). Content sits in the Content Lake, where your frontend fetches it with queries, and Sanity Studio serves only as the editing app. Because the frontend renders your site, the Loogika tag belongs there and not in Sanity.

Last updated .

What do you need before you start?

Copy your script tag from Site Settings in Loogika, under the Tracking Script tab. It looks like this, with your own site ID in place of YOUR_SITE_ID:

<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>

Where does the Loogika tag go on a Sanity site?

Place the tag in the <head> of whichever frontend application pulls its content from Sanity. Sanity itself has no template and no header setting to paste code into. Pick the guide for your framework:

How do you keep an embedded Sanity Studio out of your data?

Add a skip pattern for the Studio path to the script tag. Some projects mount Sanity Studio inside the frontend, and a Next.js app might serve it at /studio. A tag in the root layout then also runs on the Studio pages, and editor sessions count as visits.

The data-skip-patterns attribute takes a JSON array of paths that Loogika must not track. This tag skips every page under /studio:

<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID"
  data-skip-patterns='["/studio/**"]'
  defer></script>

A Studio that you deploy to a sanity.studio address is a separate app without the tag. Loogika never sees the time editors spend there.

How do you check that Loogika is installed?

Load the live frontend in a fresh browser tab and visit a few pages. Loogika's dashboard shows those pageviews within a few seconds.

If nothing arrives, look for script.js?siteId= in the page source. When the tag is on the page and the dashboard is still empty, work through the script troubleshooting page.