mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-03 12:10:11 +00:00
## Summary Add GTM injection for cloud distribution builds and push SPA page view + signup events. ## Changes - **What**: Inject GTM script into head-prepend and noscript iframe into body-prepend for cloud builds - **What**: Push `page_view` to `dataLayer` on cloud route changes (page_location + page_title) - **What**: Push `sign_up` to `dataLayer` after successful account creation (email/google/github) - **Dependencies**: None ## Review Focus - Placement order for head-prepend/body-prepend and cloud-only gating - Route-change page_view payload shape - Signup event emission only for new users ## Screenshots (if applicable) <img width="1512" height="860" alt="Screenshot 2026-01-26 at 11 38 11 AM" src="https://github.com/user-attachments/assets/03fb61db-5ca4-4432-9704-bbdcc4c6c1b7" /> <img width="1512" height="862" alt="Screenshot 2026-01-26 at 11 38 26 AM" src="https://github.com/user-attachments/assets/6e46c855-a552-4e52-9800-17898a512d4d" />
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { isCloud } from '@/platform/distribution/types'
|
|
|
|
const GTM_CONTAINER_ID = 'GTM-NP9JM6K7'
|
|
|
|
let isInitialized = false
|
|
let initPromise: Promise<void> | null = null
|
|
|
|
export function initGtm(): void {
|
|
if (!isCloud || typeof window === 'undefined') return
|
|
if (typeof document === 'undefined') return
|
|
if (isInitialized) return
|
|
|
|
if (!initPromise) {
|
|
initPromise = new Promise((resolve) => {
|
|
const dataLayer = window.dataLayer ?? (window.dataLayer = [])
|
|
dataLayer.push({
|
|
'gtm.start': Date.now(),
|
|
event: 'gtm.js'
|
|
})
|
|
|
|
const script = document.createElement('script')
|
|
script.async = true
|
|
script.src = `https://www.googletagmanager.com/gtm.js?id=${GTM_CONTAINER_ID}`
|
|
|
|
const finalize = () => {
|
|
isInitialized = true
|
|
resolve()
|
|
}
|
|
|
|
script.addEventListener('load', finalize, { once: true })
|
|
script.addEventListener('error', finalize, { once: true })
|
|
document.head?.appendChild(script)
|
|
})
|
|
}
|
|
|
|
void initPromise
|
|
}
|
|
|
|
export function pushDataLayerEvent(event: Record<string, unknown>): void {
|
|
if (!isCloud || typeof window === 'undefined') return
|
|
const dataLayer = window.dataLayer ?? (window.dataLayer = [])
|
|
dataLayer.push(event)
|
|
}
|