Astro integration package for Basicrum

Published

Astro and Basicrum logos with a stream of coloured performance samples between them.
On this page

One goal of the free Basicrum public beta was to see how people would use it in ways we hadn’t anticipated. My background was in PHP, so WordPress, Magento, and Shopware were the first integrations that came to mind.

When we reviewed a few beta installations, we found people running Basicrum on platforms we hadn’t built integrations for. One was the content-driven JavaScript framework Astro.

Astro’s Largest Contentful Paint was 1.6 seconds versus 2.1 for other sites. Interaction to Next Paint was 66 versus 109 milliseconds. Cumulative Layout Shift was 0.00 for both.
When we looked at the Core Web Vitals for Astro compared to other websites, we noticed that Astro performs betteer.

Some beta users had used AI coding tools to set up Boomerang JS and point it at our collector. In the setups we reviewed, Boomerang was part of the site’s main JavaScript bundle, blocked rendering, and ran without an opt-in or opt-out mechanism.

We want to keep monitoring out of the page’s render path. That’s why we built Basicrum for Astro. It serves Boomerang as a separate same-origin asset, loads it asynchronously, and lets you connect your site’s consent manager.

Installation and setup

The package supports Astro 7 on Node.js 22.12 or later. Install it from your Astro project directory.

npm install @basicrum/basicrum-astro

Add the integration to astro.config.mjs. Use your site’s Brum Site ID and Beacon Endpoint in place of the placeholders. Remove any existing Basicrum or Boomerang bootstrap to avoid loading it twice.

import { defineConfig } from "astro/config";
import basicrum from "@basicrum/basicrum-astro";

export default defineConfig({
  integrations: [
    basicrum({
      brumSiteId: "YOUR_BASICRUM_SITE_ID",
      beaconEndpoint: "https://YOUR_COLLECTOR/beacon/catcher",
      loader: "consent",
    }),
  ],
});

To check collection with astro dev, point the integration at a test collector and set enabled: true. In consent mode, grant analytics permission before looking for the beacon in your browser’s Network panel.

With loader: "consent", Boomerang waits for analytics permission before it loads, sets cookies, or sends beacons. Connect your consent manager’s initial decision and subsequent changes to the client helper. Pass true for a grant and false for a denial, expiry, or withdrawal.

import { setConsent } from "@basicrum/basicrum-astro/client";

function onAnalyticsConsent(granted) {
  setConsent(granted);
}

For a consent manager that works outside JavaScript modules, use the corresponding global callback.

function onAnalyticsConsent(granted) {
  if (granted) {
    window.OPT_IN_BASICRUM_LOADER_WRAPPER();
  } else {
    window.OPT_OUT_BASICRUM_LOADER_WRAPPER();
  }
}

Apply the saved decision after the loader in the page head runs on every full page load. A regular Astro module script runs after the loader. The helper returns false on the server or when the consent callbacks are unavailable, including when the integration is disabled or uses non-consent mode. An early call is dropped. The client import also includes TypeScript types for the global callbacks.

Withdrawing permission stops collection and clears Boomerang’s RT and BA cookies. If loading had already started, save any later grant in your consent manager and reload the page to resume collection.

With loader: "non-consent", the integration starts loading Boomerang immediately. Boomerang can set cookies and send beacons without waiting for a consent manager’s decision.

Configuration

Scroll across the table for option descriptions.

Basicrum Astro integration options
OptionDefaultMeaning
brumSiteIdRequiredPublic identifier sent as brum_site_id.
beaconEndpointRequiredAbsolute HTTP or HTTPS collector URL. Omit credentials and fragments.
loaderRequiredChoose "consent" or "non-consent".
enabledtrue in builds, false in devControls script injection and the route that serves Boomerang.
debugfalseUse the unminified loader.
pageType"page"Fallback page type sent as p_type.
stripQueryStringtrueEnable Boomerang’s URL query stripping.
waitAfterOnloadMs0Delay the first beacon after page load, or after Boomerang initializes when consent arrives late. Leaving during the delay sends the pending beacon immediately.
resourceTimingtrueEnable the ResourceTiming plugin.
continuitytrueEnable the Continuity plugin.

The integration measures full document loads. On sites that use ClientRouter, add data-astro-reload to links you want to measure as full page loads.

For deployment details and source code, see the Basicrum for Astro repository on GitHub.

Basicrum is now in public betaTo try Basicrum, sign up and join our public beta.Free during beta testing