Add Bily through one Astro layout and support both document loads and client-side transitions.
Declare one reserved Bily browser script in the shared Astro layout, then initialize the SDK from that exact element. The SDK reuses it; it does not add a second loader. Full document loads record their initial page automatically. If the site uses Astro client routing, preserve the reserved script during document swaps and track later astro:page-load events.
Astro exposes PUBLIC_ values to browser code. The tracking URL is public installation data, not a private token. Rebuild and redeploy whenever it changes.
Add this processed script to the layout that wraps every tracked page. Keep the layout’s existing metadata, styles, and optional ClientRouter component.
Astro bundles the integration module and runs it once per document. When 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.
Keep the reserved id, transition:persist, and is:inline attributes on the external browser script. Do not add data-astro-rerun to the integration module. Re-running that module after each transition creates extra listeners and unclear ownership.