Skip to main content

Astro Integration

Add Ovyxa analytics to your Astro site. Works with static (SSG), server-rendered (SSR), and hybrid modes.

Add the Script to Your Layout

Create or edit your base layout and add the tracking script in the <head>:

---
// src/layouts/BaseLayout.astro
const { title } = Astro.props
---

<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{title}</title>
<script
defer
data-domain="yourdomain.com"
src="https://ovyxa.com/js/script.js"
></script>
</head>
<body>
<slot />
</body>
</html>

Then use the layout in your pages:

---
// src/pages/index.astro
import BaseLayout from '../layouts/BaseLayout.astro'
---

<BaseLayout title="Home">
<h1>Welcome</h1>
</BaseLayout>

Only Track in Production

Use import.meta.env.PROD to conditionally include the script:

<head>
{import.meta.env.PROD && (
<script
defer
data-domain="yourdomain.com"
src="https://ovyxa.com/js/script.js"
></script>
)}
</head>

Tracking Custom Events

Use a client-side script to send custom events:

<button id="signup-btn">Sign Up</button>

<script>
document.getElementById('signup-btn')?.addEventListener('click', () => {
window.ovyxa('event', 'Signup', { props: { source: 'landing' } })
})
</script>

Or from a React/Vue/Svelte island component:

// src/components/CTAButton.tsx (React island)
export default function CTAButton() {
const handleClick = () => {
window.ovyxa('event', 'CTAClick', { props: { variant: 'hero' } })
}

return <button onClick={handleClick}>Get Started</button>
}

Cookieless Mode

Add the data-cookieless attribute to avoid needing cookie consent:

<script
defer
data-domain="yourdomain.com"
data-cookieless
src="https://ovyxa.com/js/script.js"
></script>

Verify Installation

  1. Build and preview your site with astro build && astro preview
  2. Check the browser Network tab for the script loading
  3. Confirm data appears on your Ovyxa dashboard

Next Steps