@iandolan/astro-analytics
v0.1.1
Published
Tracking layer for Astro: GTM, CallRail swap, and interaction-gated loading for heavy third-party scripts.
Maintainers
Readme
@iandolan/astro-analytics
Tag and script insertion for Astro with two deliberately opposite loading strategies. Replaces the GTM / CallRail insertion plugins and the WP Rocket style script delay.
---
import Analytics from '@iandolan/astro-analytics/Analytics.astro';
import DelayedScript from '@iandolan/astro-analytics/DelayedScript.astro';
---
<Analytics gtmId="GTM-XXXXXXX" />
<DelayedScript src="https://widget.example.com/embed.js" />Analytics handles GTM, direct GA4 (defaulting to no Google Signals and no ad personalization), and CallRail number swap. It loads eagerly on purpose. Gating analytics on first interaction stops recording land-read-leave sessions, which are exactly the ones worth understanding.
DelayedScript is the opposite. Heavy third-party widgets (chat, social embeds, players) load on first interaction, with a timeout fallback so idle visitors still get them. They stop taxing Core Web Vitals for visitors who never touch them. Never use it for analytics.
Part of the Dolan SEO Suite, WordPress SEO plugin functionality rebuilt for static Astro sites. Plain ESM, no build step.
MIT © Ian Dolan
