astro:page-load events.
Install Bily
Set one public build value
Copy the complete tracking URL from Bily > Settings > Apps > More settings > Install tracking..env
PUBLIC_ values to browser code. The tracking URL is public installation data, not a private token. Rebuild and redeploy whenever it changes.
Add Bily to the shared layout
Add this processed script to the layout that wraps every tracked page. Keep the layout’s existing metadata, styles, and optionalClientRouter component.
src/layouts/BaseLayout.astro
ClientRouter is active, it swaps the page head during navigation. The same reserved element appears in every incoming layout, so transition:persist keeps the active browser script instead of removing or re-executing it.
astro:page-load then fires at the end of each client-side navigation. The URL guard skips its initial call and repeated notifications, including a route notification that leaves the complete URL unchanged.
Without client routing, every navigation loads a new document. The Bily browser script records that document’s page automatically, so the route callback has nothing extra to send.
Track successful actions
Framework islands and browser scripts can importtrack() directly.
src/scripts/newsletter.ts
Verify Astro tracking
Test direct loads, full reloads, client transitions, and browser history.
Replace the tracking URL
Rebuild once with the validated customer-subdomain URL.