Skip to main content
For astroJs we recommend using the web integration by placing the code somewhere in the layout, before the closing </body> tag. Here is an example:
layout.astro
The main takeaway here is that you need to use the astro:page-load event to run the script. This will ensure that the script runs after the page has loaded and triggers a check after each page load. If you don’t need page views and you want to run the script only once, you can use the window.onload event instead.