Add Privatus Analytics to Astro
Add privacy-friendly analytics to an Astro site with an is:inline script in your base layout. View transitions are supported and nothing is bundled.
Add the snippet to your base layout's <head>:
astro
---
// src/layouts/Base.astro
---
<html lang="en">
<head>
<script is:inline defer src="https://privatusstats.com/js/pa.js" data-site="pa_YOURSITEID" data-modules="engage,auto,vitals,clicks,ask"></script>
</head>
<body><slot /></body>
</html>
is:inline stops Astro from bundling the script, which would break the
data- attributes. It works with static and SSR output.
With <ViewTransitions /> / <ClientRouter />, navigations use
history.pushState, which the tracker follows. Don't add
data-astro-rerun to the tracker script: it would load the tracker again on
every navigation.