Astro's official Partytown integration can load the Hardal tracker in a web worker. Install @astrojs/partytown, mark the tracker script as type="text/partytown", and test the full event request. A loaded script is only the first check. Worker compatibility, consent behavior, and page navigation must also pass.
Install the integration
Use Astro's integration command:
yarn astro add partytown
Or configure it manually in astro.config.mjs:
import { defineConfig } from "astro/config";
import partytown from "@astrojs/partytown";
export default defineConfig({
integrations: [partytown()],
});
Astro maintains the current installation and configuration details in the @astrojs/partytown guide.
Add the tracker to a shared layout
Copy the website ID and endpoint from your Hardal signal setup. Put the script in a layout used by every page that should be measured:
---
const websiteId = import.meta.env.PUBLIC_HARDAL_WEBSITE_ID;
const endpoint = import.meta.env.PUBLIC_HARDAL_ENDPOINT;
---
<script
type="text/partytown"
src={`${endpoint}/hardal`}
data-website-id={websiteId}
data-host-url={endpoint}
data-auto-track="true"
></script>
Set PUBLIC_HARDAL_WEBSITE_ID and PUBLIC_HARDAL_ENDPOINT in the deployment environment. Values with Astro's PUBLIC_ prefix are exposed to the browser, so do not place secrets in them.
Verify more than the script file
- Open DevTools and check that the Partytown worker initializes.
- Confirm the Hardal script is requested through the worker.
- Confirm an event reaches the configured endpoint.
- Check the URL, referrer, timestamp, and signal ID in Hardal.
- Navigate between Astro pages and repeat the event check.
- Test the denied and granted states if the tracker is consent-gated.
If the tracker or another third-party script depends on a browser API Partytown cannot proxy, load that script normally and measure the performance difference. Do not keep a worker setup that silently drops events.
For the wider migration sequence, use the server-side tracking checklist.