mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
feat: track page views in gtm
This commit is contained in:
1
global.d.ts
vendored
1
global.d.ts
vendored
@@ -30,6 +30,7 @@ interface Window {
|
|||||||
badge?: string
|
badge?: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dataLayer?: Array<Record<string, unknown>>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Navigator {
|
interface Navigator {
|
||||||
|
|||||||
@@ -36,6 +36,18 @@ function getBasePath(): string {
|
|||||||
|
|
||||||
const basePath = getBasePath()
|
const basePath = getBasePath()
|
||||||
|
|
||||||
|
function pushPageView(to: RouteLocationNormalized): void {
|
||||||
|
if (!isCloud) return
|
||||||
|
|
||||||
|
const dataLayer = window.dataLayer ?? (window.dataLayer = [])
|
||||||
|
dataLayer.push({
|
||||||
|
event: 'page_view',
|
||||||
|
page_location: window.location.href,
|
||||||
|
page_title: document.title,
|
||||||
|
page_path: to.fullPath
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: isFileProtocol
|
history: isFileProtocol
|
||||||
? createWebHashHistory()
|
? createWebHashHistory()
|
||||||
@@ -93,6 +105,10 @@ installPreservedQueryTracker(router, [
|
|||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
router.afterEach((to) => {
|
||||||
|
pushPageView(to)
|
||||||
|
})
|
||||||
|
|
||||||
if (isCloud) {
|
if (isCloud) {
|
||||||
const { flags } = useFeatureFlags()
|
const { flags } = useFeatureFlags()
|
||||||
const PUBLIC_ROUTE_NAMES = new Set([
|
const PUBLIC_ROUTE_NAMES = new Set([
|
||||||
|
|||||||
Reference in New Issue
Block a user