astro-ym



Lightweight, type-safe Yandex Metrika integration for Astro.
Designed for
Astro 4+ and
Astro 5+ (supports both
View Transitions and the new
Client Router). It handles SPA navigation correctly out of the box, eliminating duplicate hits and ensuring accurate tracking.
âĻ Features
- ð
Client Router Support: Automatically tracks page views on route changes (SPA navigation) using
astro:page-load.
- ðĪ
Lazy Loading: Optional lazy load of Yandex Metrika script (load on first user interaction or after timeout) for better Lighthouse scores.
- âĄ
Zero Config: Smart defaults (Clickmap, Link tracking enabled by default).
- ðĄ
TypeScript: Fully typed component and helper functions.
- ðŊ
Goals Helper: Exported
reachGoal function for easy conversion tracking.
- ðŠķ
Lightweight: Uses the modern Yandex
tag.js structure and queues calls before the script loads.
ðĶ Installation
``
bash
npm install astro-ym
`
ð Usage
Add the component to your main Layout file (e.g., src/layouts/Layout.astro
). It is recommended to place it before the closing