Contentful
Add Rybbit analytics to your Contentful site
Contentful is a headless CMS: it stores content and delivers it over its APIs, but never renders your pages. The tracking snippet therefore goes into the frontend that consumes Contentful, not into Contentful itself.
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 Contentful
Contentful has no template or head setting to paste into. Add the snippet to the <head> of the frontend application that fetches content from Contentful.
Next.js is the most common Contentful 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.
- Gatsby, which pairs with the official
gatsby-source-contentfulplugin - Remix
- Vite + React
- Vite + Vue
- Astro
- SvelteKit
- Angular
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
- Editor previews count as visits: Contentful's content preview URLs open a preview or draft build of your frontend. Register that deployment as a separate site in Rybbit, or leave the snippet out of preview builds, so editors' previews are not mixed into your production data.
- The Contentful web app is not tracked: the snippet only runs on your frontend, so time spent editing in Contentful 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.