Astro integration package for Basicrum
Published

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.

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-astroAdd 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.
Consent management
Consent mode
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.
Non-consent mode
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.
| Option | Default | Meaning |
|---|---|---|
brumSiteId | Required | Public identifier sent as brum_site_id. |
beaconEndpoint | Required | Absolute HTTP or HTTPS collector URL. Omit credentials and fragments. |
loader | Required | Choose "consent" or "non-consent". |
enabled | true in builds, false in dev | Controls script injection and the route that serves Boomerang. |
debug | false | Use the unminified loader. |
pageType | "page" | Fallback page type sent as p_type. |
stripQueryString | true | Enable Boomerang’s URL query stripping. |
waitAfterOnloadMs | 0 | Delay the first beacon after page load, or after Boomerang initializes when consent arrives late. Leaving during the delay sends the pending beacon immediately. |
resourceTiming | true | Enable the ResourceTiming plugin. |
continuity | true | Enable 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.