Astro

Add DataSaaS analytics to your Astro website. Astro's layout system makes it easy to add tracking across all pages.

Method 1: Layout Component (Recommended)

Add the tracking script to your main layout at src/layouts/Layout.astro inside the <head> section:

---
// src/layouts/Layout.astro
interface Props {
  title: string;
}

const { title } = Astro.props;
---

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>{title}</title>

    <!-- DataSaaS Analytics -->
    <script
      defer
      data-website-id="ds_YOUR_WEBSITE_ID"
      data-domain="yourdomain.com"
      src="https://datasaas.co/js/script.min.js"
    ></script>
  </head>
  <body>
    <slot />
  </body>
</html>

Method 2: Individual Pages

If you don't use a shared layout, add the script directly in the <head> of any .astro page:

<!-- src/pages/index.astro -->
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>My Page</title>

    <!-- DataSaaS Analytics -->
    <script
      defer
      data-website-id="ds_YOUR_WEBSITE_ID"
      data-domain="yourdomain.com"
      src="https://datasaas.co/js/script.min.js"
    ></script>
  </head>
  <body>
    <h1>Hello, world!</h1>
  </body>
</html>

Verify

Visit your website, then open the DataSaaS dashboard. You should see your visit appear within a few seconds.