feat: add cloud gtm injection

This commit is contained in:
Benjamin Lu
2026-01-24 19:26:31 -08:00
parent 702c917e57
commit 65bc3b1b48

View File

@@ -37,6 +37,15 @@ const VITE_OG_DESC =
'Bring your creative ideas to life with Comfy Cloud. Build and run your workflows to generate stunning images and videos instantly using powerful GPUs — all from your browser, no installation required.' 'Bring your creative ideas to life with Comfy Cloud. Build and run your workflows to generate stunning images and videos instantly using powerful GPUs — all from your browser, no installation required.'
const VITE_OG_IMAGE = `${VITE_OG_URL}/assets/images/og-image.png` const VITE_OG_IMAGE = `${VITE_OG_URL}/assets/images/og-image.png`
const VITE_OG_KEYWORDS = 'ComfyUI, Comfy Cloud, ComfyUI online' const VITE_OG_KEYWORDS = 'ComfyUI, Comfy Cloud, ComfyUI online'
const GTM_CONTAINER_ID = 'GTM-NP9JM6K7'
const GTM_SCRIPT = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${GTM_CONTAINER_ID}');`
const GTM_NO_SCRIPT =
`<iframe src="https://www.googletagmanager.com/ns.html?id=${GTM_CONTAINER_ID}"` +
' height="0" width="0" style="display:none;visibility:hidden"></iframe>'
// Auto-detect cloud mode from DEV_SERVER_COMFYUI_URL // Auto-detect cloud mode from DEV_SERVER_COMFYUI_URL
const DEV_SERVER_COMFYUI_ENV_URL = process.env.DEV_SERVER_COMFYUI_URL const DEV_SERVER_COMFYUI_ENV_URL = process.env.DEV_SERVER_COMFYUI_URL
@@ -416,7 +425,33 @@ export default defineConfig({
} }
}) })
] ]
: []) : []),
// Google Tag Manager (cloud distribution only)
{
name: 'inject-gtm',
transformIndexHtml: {
order: 'post',
handler(html) {
if (DISTRIBUTION !== 'cloud') return html
return {
html,
tags: [
{
tag: 'script',
children: GTM_SCRIPT,
injectTo: 'head-prepend'
},
{
tag: 'noscript',
children: GTM_NO_SCRIPT,
injectTo: 'body-prepend'
}
]
}
}
}
}
], ],
build: { build: {