chore: baidutongji

This commit is contained in:
xiaojunnuo
2024-10-20 03:35:08 +08:00
parent e646f01c2a
commit eb937737c2
2 changed files with 66 additions and 0 deletions
+17
View File
@@ -4,6 +4,11 @@ import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import './style.css'
import Layout from './Layout.vue'
import { registerAnalytics, siteIds, trackPageview } from './plugins/baidutongji'
import { inBrowser } from "vitepress";
export default {
extends: DefaultTheme,
Layout,
@@ -14,5 +19,17 @@ export default {
// },
enhanceApp({ app, router, siteData }) {
// ...
if (inBrowser) {
registerAnalytics(siteIds)
window.addEventListener('hashchange', () => {
const { href: url } = window.location
trackPageview(siteIds, url)
})
router.onAfterRouteChanged = (to) => {
trackPageview(siteIds, to)
}
}
}
} satisfies Theme