diff --git a/frontend/src/admin/baidu.ts b/frontend/src/admin/baidu.ts new file mode 100644 index 00000000..b097991d --- /dev/null +++ b/frontend/src/admin/baidu.ts @@ -0,0 +1,12 @@ +// baidu tongji +export const initBaiduTonji = () => { + if (localStorage.getItem('useStats') !== '0') { + window._hmt = window._hmt || []; + (function () { + const hm = document.createElement('script'); + hm.src = 'https://hm.baidu.com/hm.js?c35e3a563a06caee2524902c81975add'; + const s = document.getElementsByTagName('script')[0]; + s?.parentNode?.insertBefore(hm, s); + })(); + } +}; diff --git a/frontend/src/interfaces/global.d.ts b/frontend/src/interfaces/global.d.ts index afb4cccd..d21a5b65 100644 --- a/frontend/src/interfaces/global.d.ts +++ b/frontend/src/interfaces/global.d.ts @@ -1,4 +1,5 @@ interface Window { initCanvas?: Function; resetCanvas?: Function; + _hmt?: Array; } diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 526050a3..54c7477d 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -13,9 +13,13 @@ import 'normalize.css/normalize.css'; import 'font-awesome/css/font-awesome.min.css'; import 'element-plus/lib/theme-chalk/index.css'; import '@/styles/index.scss'; +import {initBaiduTonji} from '@/admin/baidu'; library.add(fab, far, fas); +// baidu tongji +initBaiduTonji(); + createApp(App) .use(store) .use(router) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index bdf52285..132241a7 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -10,6 +10,7 @@ import user from '@/router/user'; import tag from '@/router/tag'; import token from '@/router/token'; import {initRouterAuth} from '@/router/auth'; +import {sendPv} from '@/utils/admin'; export const routes: Array = [ ...login, @@ -48,6 +49,12 @@ const router = createRouter({ routes, }); +router.afterEach(async (to, from, next) => { + if (to.path) { + sendPv(to.path); + } +}); + initRouterAuth(router); export default router; diff --git a/frontend/src/utils/admin.ts b/frontend/src/utils/admin.ts new file mode 100644 index 00000000..41e5ea75 --- /dev/null +++ b/frontend/src/utils/admin.ts @@ -0,0 +1,11 @@ +export const sendPv = (page: any) => { + if (localStorage.getItem('useStats') !== '0') { + window._hmt?.push(['_trackPageview', page]); + } +}; + +export const sendEv = (category: string, eventName: string, optLabel: string, optValue: string) => { + if (localStorage.getItem('useStats') !== '0') { + window._hmt?.push(['_trackEvent', category, eventName, optLabel, optValue]); + } +};