Skip to content
Install guide · Frameworks

Install Linqry on Astro

To add Linqry to an Astro site, paste the snippet into the `<head>` of the base layout every page uses, and add `is:inline` to both `<script>` tags so Astro leaves them exactly as written. Page views, including navigations through Astro's client router, are then recorded automatically.

Updated · 2 min read

Install in your base layout

  1. Add your site to Linqry

    Start a free trial, add your production domain and copy your site ID from the Install page.

  2. Paste the snippet with is:inline

    Open the layout that wraps every page (often src/layouts/BaseLayout.astro or Layout.astro) and add both tags inside <head>.

    ---
    // src/layouts/BaseLayout.astro
    const { title } = Astro.props;
    ---
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        <title>{title}</title>
        <script is:inline>window.linqry=window.linqry||function(){(window.linqry.q=window.linqry.q||[]).push(arguments)}</script>
        <script is:inline defer data-website-id="YOUR_SITE_ID" data-domain="yourdomain.com" src="https://linqry.com/t.js"></script>
      </head>
      <body>
        <slot />
      </body>
    </html>
  3. Build, deploy and check Realtime

    Deploy, open a few pages of the live site and watch Realtime in Linqry. Each page shows up as a pageview in the live event stream.

Why is:inline matters

By default, Astro processes <script> tags: it bundles them with your other code and turns them into type="module" scripts. That isn't what you want here: the queue stub should run immediately, exactly as written, and the tracker must stay a classic script loaded from linqry.com with its data-* attributes intact.

Astro skips processing for any script with an attribute other than src, so the tracker tag (with defer and data-*) would be left alone anyway. The queue stub has no attributes, so it needs is:inline. Adding it to both makes the intent obvious and keeps working if someone later trims the attributes.

What a static Astro site gets without extra code

  • Page views with the referrer and UTM parameters of the landing page, so you can see which posts, newsletters and campaigns bring people in.
  • Time on page, sent when the visitor leaves, switches tabs or navigates.
  • Outbound link clicks, recorded as outbound events with the destination, which is useful for docs and content sites that link out a lot.
  • Country, device and browser, worked out on the server. No cookies are set and raw IP addresses are never stored; see the privacy model.

Astro's client router (view transitions)

On a static Astro site, every navigation is a full page load and is counted as one. If you enable the <ClientRouter />, Astro swaps pages without a reload and updates the URL with history.pushState or replaceState. The tracker hooks both, so each swap is recorded as a page view and the time on the previous page is reported.

During a swap Astro keeps head scripts that also exist on the new page, which is why the snippet belongs in the shared layout used by every page. Don't add data-astro-rerun to the tracker: that forces it to run again after every transition, and each run would count navigations again.

Custom events

The quickest option needs no JavaScript: put data-linqry-event on a link or button, plus optional data-linqry-event-* properties. From your own scripts or a framework island, call window.linqry:

<a href="/signup" data-linqry-event="signup-clicked" data-linqry-event-location="header">Sign up</a>

<script>
  document.querySelector("#newsletter")?.addEventListener("submit", () => {
    window.linqry?.("newsletter-subscribed");
  });
</script>

With TypeScript, add the declaration below to src/env.d.ts or another .d.ts file. See custom events for limits on names and properties, and funnels for turning events into conversion steps.

// linqry.d.ts (anywhere your tsconfig includes)
export {};

declare global {
  interface Window {
    linqry?: (
      event: string,
      props?: Record<string, string | number | boolean>,
      revenueCents?: number,
    ) => void;
  }
}

Exclude your own visits

astro dev serves on localhost, which Linqry ignores. On the live site, run this once in your browser's console:

localStorage.setItem('linqry_ignore', 'true')

Troubleshooting

  • The built HTML has `type="module"` on the stub, or no stub at all? is:inline is missing from that tag.
  • Some pages aren't tracked? They use a different layout. Add the snippet to every layout, or have them share one head component.
  • Navigations counted twice with the client router? Remove any data-astro-rerun attribute and any second copy of the snippet.

Frequently asked questions

Do I need an Astro integration or the Partytown integration?

No. Linqry has no Astro integration; the two inline tags are the whole install. Running the tracker in a web worker isn't needed, since it's small and loads with defer.

Does it work with server-rendered Astro pages?

Yes. Whether a page is prerendered or rendered on demand, the browser receives the same tags from your layout.

Sources

  1. Astro: Scripts and event handling (script processing, is:inline) (checked Nov 9, 2026)
  2. Astro: View transitions (ClientRouter script behavior) (checked Nov 9, 2026)

Start measuring your Astro site

No card required · 30-day trial · No cookies