Open-source web analytics and RUM for Astro
High-performance, cookieless analytics tailored for Astro's content-driven architecture. Full compatibility with Astro View Transitions, zero JS bloat, and automated Core Web Vitals.
Add deferred script to src/layouts/Layout.astroComplete Astro Integration Guide
Follow these steps to track pageviews, custom events, Core Web Vitals, and errors.
1Add Script to Base Layout Component
Use the `is:inline` directive in your primary `Layout.astro` file to prevent Astro from bundling or renaming the external analytics script.
<!-- src/layouts/Layout.astro --> <script is:inline defer src="https://api.openanalytics.org.in/open.js" data-project-id="prj_your_project_id" ></script>
2Supporting Astro View Transitions
If your Astro application uses `<ViewTransitions />`, listen to `astro:page-load` to ensure smooth client-side transition reporting.
<!-- src/components/AnalyticsWatcher.astro -->
<script>
document.addEventListener("astro:page-load", () => {
if (window.OpenAnalytics) {
window.OpenAnalytics.page(window.location.pathname);
}
});
</script>3Client Island Custom Events
Dispatch custom business conversions from within interactive React, Vue, or Svelte client islands.
export default function Newsletter() {
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (window.OpenAnalytics) {
window.OpenAnalytics.track("newsletter_submitted", {
form_location: "blog_sidebar",
});
}
};
return <form onSubmit={handleSubmit}><button type="submit">Subscribe</button></form>;
}Tracking Astro Content Reading & Downloads
Capture documentation reading completions and code copy events.
document.querySelectorAll("[data-copy-button]").forEach((btn) => {
btn.addEventListener("click", () => {
if (window.OpenAnalytics) {
window.OpenAnalytics.track("code_snippet_copied", {
code_language: btn.getAttribute("data-lang") || "bash",
page: window.location.pathname,
});
}
});
});Automated Field Performance
Astro websites emphasize pristine performance. Open Analytics complements Astro by executing in under 2ms with less than 3.2KB payload, helping you maintain perfect 100 Google PageSpeed scores.
Runtime Crash Triage
Captures runtime errors arising inside interactive client islands or global layout scripts, linking crashes to specific rendered markdown posts or dynamic routes.
Frequently Asked Questions
Add Open Analytics to your Astro app today
Zero cookies, sub-3.2 KB payload, real-time Core Web Vitals RUM, and automated crash triage.