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.
The browser script records the initial page and supported client-side navigation automatically. Do not add manual PageView calls for those navigations; use track() for business events.
Without client routing, every navigation loads a new document. The Bily browser script records that document’s page automatically, so no route callback is needed.
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.