ACTIVATE when integrating third-party scripts (Google Analytics, GTM, Facebook Pixel) in Astro via Partytown web worker. ACTIVATE for 'analytics', 'Partytown', 'GA4', 'GTM', 'tracking script', 'text/partytown'. Covers: Partytown setup, GA4/GTM/Facebook Pixel integration, forward configuration, custom events, conditional loading (prod only), cookie consent integration, debug mode. DO NOT use for: general script handling in Astro, SEO configuration.
From astronpx claudepluginhub fabiensalles/claude-marketplace --plugin astroThis skill uses the workspace's default tool permissions.
references/analytics-integration-examples.mdGuides Next.js Cache Components and Partial Prerendering (PPR) with cacheComponents enabled. Implements 'use cache', cacheLife(), cacheTag(), revalidateTag(), static/dynamic optimization, and cache debugging.
Migrates code, prompts, and API calls from Claude Sonnet 4.0/4.5 or Opus 4.1 to Opus 4.5, updating model strings on Anthropic, AWS, GCP, Azure platforms.
Configures VPN and dedicated connections like Direct Connect, ExpressRoute, Interconnect for secure on-premises to AWS, Azure, GCP, OCI hybrid networking.
Patterns for offloading third-party scripts to a web worker for better performance.
Third-party scripts (analytics, ads, chat widgets) block the main thread and slow page interactivity. Partytown runs them in a web worker, keeping the main thread free.
npx astro add partytown
// astro.config.mjs
import partytown from '@astrojs/partytown';
export default defineConfig({
integrations: [
partytown({
config: {
forward: ['dataLayer.push'],
},
}),
],
});
Scripts use type="text/partytown" and is:inline to run in the web worker. The forward array tells Partytown which functions to proxy from main thread to worker.
partytown({
config: {
forward: [
'dataLayer.push', // Google Analytics/GTM
'fbq', // Facebook Pixel
'gtag', // Google gtag
'_hsq.push', // HubSpot
],
},
}),
When integrating GA4, GTM, or Facebook Pixel, read
references/analytics-integration-examples.mdfor complete setup snippets with Partytown.
When implementing custom events, conditional loading, or cookie consent, read
references/analytics-integration-examples.mdfor React component events, production-only loading, and consent patterns.
When debugging Partytown issues (scripts not running, CORS errors), read
references/analytics-integration-examples.mdfor troubleshooting steps.
| Script Type | Forward Config | Notes |
|---|---|---|
| GA4 | dataLayer.push | Most common |
| GTM | dataLayer.push | Same as GA4 |
fbq | Single function | |
| HubSpot | _hsq.push | Array-based |
| Intercom | Intercom | Object-based |
| Custom | Add to forward | Any global function |
| Attribute | Purpose |
|---|---|
type="text/partytown" | Run in web worker |
is:inline | Don't bundle, keep inline |
define:vars={{ }} | Pass Astro vars to script |