mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-07 14:09:59 +00:00
Revert/undo-788f5083-ef8657bb (#8353)
This reverts the addition of GTM for 1.38, as it was still present in the built files. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8353-Revert-undo-788f5083-ef8657bb-2f66d73d365081818d43fcaab220a4ef) by [Unito](https://www.unito.io)
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user