Integration Guides

Starlight

Add Rybbit analytics to your Starlight docs

Starlight, the documentation theme for Astro, has a head option in its integration config that adds tags to every page. The snippet goes there, in astro.config.mjs, so no component overrides are needed.

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 Starlight

Open astro.config.mjs at the root of your project and add a script entry to the head array of the starlight() integration:

astro.config.mjs
import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";

export default defineConfig({
  integrations: [
    starlight({
      title: "My Docs",
      head: [
        {
          tag: "script",
          attrs: {
            src: "https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID",
            defer: true,
          },
        },
      ],
    }),
  ],
});

Each head entry becomes an HTML element with the given attributes; defer: true renders as a boolean attribute. Rebuild with npm run build and deploy the dist/ directory.

Entries in head are written to the page as-is and skip Astro's script bundling, which is what you want for a remote tracker. Only override the Head component if you need to import a local asset.

Starlight serves each page as a full document, so every navigation is a normal pageview and no route-change handling is needed.

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.js returns 200 and that POST requests 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

  • Local previews are tracked: head applies to astro dev as well as astro build. Read the site ID from an environment variable that only your deploy sets (process.env.RYBBIT_SITE_ID) and push the entry only when it is present, or keep a separate site in Rybbit for development.
  • Tag missing after editing the config: the dev server restarts itself when astro.config.mjs changes, but a deployed site needs a fresh build.
  • Head component override: if your project already overrides Starlight's Head component, make sure it still renders the default head (the override docs show how), otherwise config head entries are dropped with it.

Next steps

On this page