mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +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
|
||||
}
|
||||
}
|
||||
dataLayer?: Array<Record<string, unknown>>
|
||||
}
|
||||
|
||||
interface Navigator {
|
||||
|
||||
@@ -36,6 +36,18 @@ function getBasePath(): string {
|
||||
|
||||
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({
|
||||
history: isFileProtocol
|
||||
? createWebHashHistory()
|
||||
@@ -93,6 +105,10 @@ installPreservedQueryTracker(router, [
|
||||
}
|
||||
])
|
||||
|
||||
router.afterEach((to) => {
|
||||
pushPageView(to)
|
||||
})
|
||||
|
||||
if (isCloud) {
|
||||
const { flags } = useFeatureFlags()
|
||||
const PUBLIC_ROUTE_NAMES = new Set([
|
||||
|
||||
Reference in New Issue
Block a user