Documentation menuDocumentation tools: Starlight

Documentation tools

Add Loogika to Starlight

You add Loogika to Starlight with the head option of the Starlight integration in astro.config.mjs. Starlight is the documentation theme for Astro, and its head option adds tags to every page. You do not need to override a component.

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 12-character site ID in place of YOUR_SITE_ID:

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

In Starlight you describe the tag as a config entry. You copy the address from the src attribute into that entry.

How do you add Loogika in astro.config.mjs?

The file to edit is astro.config.mjs in your project root. Inside starlight(), the head array gets a new script entry:

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.loogika.com/api/script.js?siteId=YOUR_SITE_ID",
            defer: true,
          },
        },
      ],
    }),
  ],
});

Each head entry becomes one HTML element with the attributes you list. The value defer: true is printed as a plain defer attribute. Run npm run build for a new build, then deploy what lands in the dist/ directory.

Why use the head option and not a component override?

Starlight writes head entries to the page exactly as you list them, and Astro does not bundle them. A script that loads from another domain, such as the Loogika script, needs that treatment. Override the Head component only when you must import a local asset.

Does Starlight need special handling for page changes?

No. Starlight serves every page as a full document, so each click on a link loads a new page. Loogika records a normal pageview for each of them.

How do you check that Loogika is installed?

Bring up your deployed docs in a separate browser tab and browse a few pages. The pageviews show up in the Loogika dashboard within a few seconds. If nothing arrives, open the page source and find script.js?siteId=.

Why is the Loogika tag missing or tracking too much?

ProblemCause and fix
Local previews show up in your reportsBoth astro dev and astro build apply the head option. Use one of the two fixes below the table
The tag is missing after a config changeA change to astro.config.mjs makes the dev server restart without your help. For a deployed site you must build again
The tag is missing and the project overrides HeadAn override that does not render the default head drops the head entries from the config. The Starlight documentation on overrides shows how to keep the default

You can keep local previews out of your data in two ways. Let only your deploy set an environment variable with the site ID, for example process.env.LOOGIKA_SITE_ID, and add the entry only when the variable exists. Or add a second site in Loogika and use its ID during development, as the page on localhost tracking describes.