OnyxMetric
Integration Guides

Starlight

Add OnyxMetric 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. Use it, and no component overrides are required.

Copy your tracking snippet

In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:

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

YOUR_SITE_ID is the numeric ID of your site.

Add the snippet to Starlight

Open astro.config.mjs and add a script entry to the head array of starlight():

astro.config.mjs
export default defineConfig({
  integrations: [
    starlight({
      title: "My Docs",
      head: [
        {
          tag: "script",
          attrs: {
            src: "https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID",
            async: true,
          },
        },
      ],
    }),
  ],
});

Each head entry becomes an HTML element with those attributes, and async: true becomes a boolean attribute. Rebuild with npm run build and deploy dist/.

head entries are written to the page unchanged and skip Astro's script bundling, which is right for a remote tracker. Override the Head component only if you must import a local file.

Starlight serves each page as a full document, so every navigation is an ordinary pageview.

Check that it works

Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.

If nothing arrives:

  • View the page source and search for script.js?siteId= to confirm the tag is present.
  • In the browser's Network tab, check that script.js returns 200 and that requests go to /api/track.
  • Turn off ad blockers, or proxy the script through your own domain.
  • Read script troubleshooting for other causes.

Troubleshooting

  • Local previews are tracked: head also applies to astro dev. Read the ID from an environment variable that only your deploy sets (for example process.env.ONYXMETRIC_SITE_ID) and skip the entry when it is empty.
  • Tag missing after a config edit: the dev server restarts on config changes, but a deployed site needs a fresh build.
  • Custom Head override: if you already replaced Starlight's Head component, make sure it still renders the default head, or the config head entries disappear.

Next steps

On this page