added baidu tongji

This commit is contained in:
marvzhang
2021-07-21 16:56:18 +08:00
parent 342f9d2e1b
commit babe6889f4
5 changed files with 35 additions and 0 deletions

View File

@@ -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);
})();
}
};

View File

@@ -1,4 +1,5 @@
interface Window {
initCanvas?: Function;
resetCanvas?: Function;
_hmt?: Array;
}

View File

@@ -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)

View File

@@ -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<RouteRecordRaw> = [
...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;

View File

@@ -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]);
}
};