feat: track page views in gtm

This commit is contained in:
Benjamin Lu
2026-01-24 19:34:54 -08:00
parent 65bc3b1b48
commit 43f6251f7a
2 changed files with 17 additions and 0 deletions

1
global.d.ts vendored
View File

@@ -30,6 +30,7 @@ interface Window {
badge?: string
}
}
dataLayer?: Array<Record<string, unknown>>
}
interface Navigator {

View File

@@ -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([