From b0891e343d070b7edf5f5471786027f1cf5b8bed Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Fri, 6 Mar 2026 14:28:21 +1100 Subject: [PATCH 1/2] feat: auto-populate runtimeConfig for registry scripts to support .env overrides When a registry script is enabled (e.g., `googleAnalytics: true`), automatically populate `runtimeConfig.public.scripts.` with empty-string defaults for the script's primary config keys. This allows env vars like `NUXT_PUBLIC_SCRIPTS_GOOGLE_ANALYTICS_ID` to work without manually declaring the runtimeConfig boilerplate. Closes #239 --- src/module.ts | 57 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/module.ts b/src/module.ts index 9a7755ea..9854aa6d 100644 --- a/src/module.ts +++ b/src/module.ts @@ -159,6 +159,36 @@ function fixSelfClosingScriptComponents(nuxt: any) { } } +const REGISTRY_ENV_DEFAULTS: Record> = { + clarity: { id: '' }, + cloudflareWebAnalytics: { token: '' }, + crisp: { id: '' }, + databuddyAnalytics: { clientId: '' }, + fathomAnalytics: { site: '' }, + googleAdsense: { client: '' }, + googleAnalytics: { id: '' }, + googleMaps: { apiKey: '' }, + googleRecaptcha: { siteKey: '' }, + googleSignIn: { clientId: '' }, + googleTagManager: { id: '' }, + hotjar: { id: '' }, + intercom: { app_id: '' }, + matomoAnalytics: { matomoUrl: '' }, + metaPixel: { id: '' }, + paypal: { clientId: '' }, + plausibleAnalytics: { domain: '' }, + posthog: { apiKey: '' }, + redditPixel: { id: '' }, + rybbitAnalytics: { siteId: '' }, + segment: { writeKey: '' }, + snapchatPixel: { id: '' }, + stripe: {}, + tiktokPixel: { id: '' }, + umamiAnalytics: { websiteId: '' }, + vercelAnalytics: {}, + xPixel: { id: '' }, +} + const PARTYTOWN_FORWARDS: Record = { googleAnalytics: ['dataLayer.push', 'gtag'], plausible: ['plausible'], @@ -355,12 +385,35 @@ export default defineNuxtModule({ // Merge registry config with existing runtimeConfig.public.scripts for proper env var resolution // Both scripts.registry and runtimeConfig.public.scripts should be supported if (config.registry) { - // Ensure runtimeConfig.public exists nuxt.options.runtimeConfig.public = nuxt.options.runtimeConfig.public || {} + // Auto-populate env var defaults for enabled registry scripts so that + // NUXT_PUBLIC_SCRIPTS_