From 65bc3b1b48a8dc873313a7fba00d2e7d671c4eea Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sat, 24 Jan 2026 19:26:31 -0800 Subject: [PATCH] feat: add cloud gtm injection --- vite.config.mts | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/vite.config.mts b/vite.config.mts index 9769ec300..d868e894a 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -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.' const VITE_OG_IMAGE = `${VITE_OG_URL}/assets/images/og-image.png` 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 = + `' // Auto-detect cloud mode from 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: {