Skip to content

A package for Astro

Cookie-free analytics for Astro. One component.

Install @crustat/astro, put one component in your layout’s head, and deploy. It works for static and server-rendered sites, and counts view transitions on its own.

  • Astro 3+
  • Static and server-rendered
  • View transitions counted
src/layouts/Layout.astro
---
import Crustat from '@crustat/astro';
---
<html>
  <head>
    <Crustat siteId="YOUR-SITE-ID" />
  </head>
  <body>
    <slot />
  </body>
</html>
npm install @crustat/astro

Made for Astro

Works the way your Astro site works

Nothing to configure per rendering mode, and no code to run on each page change.

How page changes are counted
  • Static or server-rendered

    The component works the same way in both.

  • View transitions, counted

    Page changes without a reload still show up as page views.

  • Quiet on localhost

    Local visits are skipped, so astro dev never shows up in your numbers.

  • Ready for a Content-Security-Policy

    If you send one, allow https://stats.crustat.com in script-src and connect-src.

Setup

Set it up in three steps

About two minutes, start to finish. You need an Astro project and your Crustat site ID.

Read the full setup guide
  1. Install the package

    Add it to your project like any other npm package.

    npm install @crustat/astro
  2. Add it to your layout

    Put the component once in the <head> of the layout your pages share, with your site ID. You’ll find the ID in Crustat under Site settings → Install.

    src/layouts/Layout.astro
    ---
    import Crustat from '@crustat/astro';
    ---
    <html>
      <head>
        <Crustat siteId="YOUR-SITE-ID" />
      </head>
      <body>
        <slot />
      </body>
    </html>

    More than one layout? Add it to each, or to a shared head component. Only once per page: two copies would count every view twice.

  3. Deploy and visit your site

    Build and deploy as usual, then open a page. Your first visit shows up about a minute later.

    Visits from localhost are skipped on purpose, so astro dev won’t show up in your stats. On a preview address that isn’t your site’s domain, visits are recorded but left out of your stats.

Under the hood

No magic. One line of HTML.

The component prints the same line you’d paste by hand. Astro leaves it exactly as it is, without bundling or moving it.

You write
<Crustat siteId="YOUR-SITE-ID" />
Your page gets
<script defer src="https://stats.crustat.com/script.js"
  data-site="YOUR-SITE-ID"></script>
PropTypeWhat it does
siteId required string Your site ID, from the Install page of your Crustat dashboard.
src optional string Where the tracker loads from. Leave it out.

Beyond page views

Track clicks and forms from your components

Page views, links to other sites and file downloads are counted with nothing to set up. For the moments you care about, add an attribute or one call.

All the ways to track events

A button or link

Add data-crustat-event with a name. Every click on it, or on anything inside it, is recorded.

Any .astro file
<button data-crustat-event="Sign up">Sign up</button>

A form

Put the attribute on the form itself. It’s recorded when the form is sent. What people type is never read.

Any .astro file
<form action="/contact" data-crustat-event="Contact">
  …
</form>

Anything else

Call crustat with a name where it happens, after checking that Crustat is there.

In a click handler
window.crustat && crustat("Purchase");

Rather not touch code? Pick the button on your site from the Events tab instead.

At a glance

The package, in short

Package
@crustat/astro
Needs
Astro 3 or newer
Rendering
Static and server-rendered
Adds to your pages
One deferred script line, no cookies
Bundling
Left as it is, not bundled or moved
View transitions
Counted on their own
Local development
Visits from localhost are skipped
Licence
MIT

Questions and answers

Good to know

Read the full setup guide
Do I still need to paste a script tag?

No. The component prints it for you, once it’s in your layout.

Does it work with server-rendered and static Astro sites?

Yes. The component works the same way whichever rendering mode your project uses.

Where do I find my site ID?

In Crustat, open your site, go to Site settings → Install and click Copy ID next to Site ID.

Why don’t I see my visits from astro dev?

Visits from localhost are skipped on purpose. Deploy, or open a preview on a real address, then visit a page and wait about a minute.

I have several layouts. Where does the component go?

In each layout, or in a shared head component they all use. Only once per page: two copies would record every view twice.

Does it work with Astro’s view transitions?

Yes. Crustat follows page changes on its own, so each new page shows up as a page view. You don’t need to run anything again on each page.

My site sends a Content-Security-Policy. What do I allow?

Allow https://stats.crustat.com in script-src and connect-src.

Start counting today.

Try Crustat free for 14 days. No card needed.

See what you'll pay

Every feature is on every plan, with no extras. Try it free for 14 days, no card needed.

Pricing details

Install in a minute

Paste one line in your site, or use our WordPress plugin or the Astro and Next.js packages.

Integration options