Install

Add analytics and revenue attribution to Astro

Astro ships almost no JavaScript by default, which is the point of Astro — so a 3KB analytics beacon is a real fraction of your page weight and worth installing deliberately. There's one wrinkle if you use view transitions.

Start a 14-day trialLast reviewed August 2026
  1. Add it to your base layout

    Astro layouts are shared HTML shells, so the tag belongs in the <head> of the layout every page uses — usually src/layouts/Layout.astro. Adding it to individual pages is how you end up with three pages that don't report.

    src/layouts/Layout.astro
    <head>
      <meta charset="utf-8" />
      <slot name="head" />
      <script defer src="https://revtrail.pyln.dev/track.js" data-site="SITE_KEY"></script>
    </head>
  2. If you use <ClientRouter />, check your pageviews

    Astro's client-side router (formerly <ViewTransitions />) swaps documents without a full reload, and scripts in the head aren't re-executed. Our script keeps running and reports the navigation via the History API, so pageviews do continue — but this is the first thing to verify in Realtime after installing, because a misconfigured transition setup is the one case where an SPA-style navigation goes uncounted.

  3. Confirm it's receiving

    Open your site in a normal browser tab, then check Realtime in the Revtrail dashboard — your own visit should appear within a few seconds. If nothing arrives, the usual causes are a mistyped site key, an ad blocker on your own browser, or a Content-Security-Policy that blocks the script origin.

  4. Instrument the conversion that matters

    Pageviews tell you traffic; a goal tells you whether the traffic worked. Call revtrail() at the moment of signup, trial start, or booking, then register it as a goal in the dashboard. This is the one step people skip, and it's the step that makes every other number worth reading.

    anywhere in your client code
    revtrail('signup')

Static output, dynamic numbers

Analytics runs in the browser, so it makes no difference whether a page was prerendered at build time, served from an edge cache, or rendered on demand. A fully static Astro site reports exactly the same data as an SSR one — there's no reason to opt a page out of static rendering for analytics.

Content collections and per-post reporting

Every post in a content collection is its own URL, so top-pages reporting works without any per-post configuration. If you sell something from a post — a course, a template, a sponsorship — instrument the click as a goal and you'll get revenue per post rather than pageviews per post.

Keeping the payload honest

If page weight is the reason you chose Astro, proxy the script through your own origin so it shares the connection you've already opened, rather than costing a fresh DNS lookup and TLS handshake to another domain. Any host that can rewrite a path can do this.

Questions people actually ask

Does it work with Astro's view transitions?
Yes — navigations are reported through the History API. Verify in Realtime after install, since view-transition setups vary.
Should I use an Astro integration?
There isn't one and you don't need one. The tag in your shared layout is the whole install.
Do I need a cookie banner for this?
Not for Revtrail. The default identity is a daily rotating hash — no cookies, no persistent identifier, nothing stored on the device. If you run ad pixels or other analytics that do use cookies, their obligations are unchanged.
Will this slow my site down?
The script is deferred, so it never blocks rendering, and it's about 3KB over the wire gzipped. It fires one beacon per pageview.

Install guides

All install guides