feat: 为页面跳转与路由切换添加埋点上报

This commit is contained in:
ZiuChen 2022-08-19 19:05:07 +08:00
parent 3c6b310889
commit ef911c284e
2 changed files with 30 additions and 1 deletions

View File

@ -1,7 +1,26 @@
module.exports = {
title: 'ZiuChen',
description: 'Unlimited Progress.',
head: [['link', { rel: 'icon', href: '/logo.png' }]],
head: [
['link', { rel: 'icon', href: '/logo.png' }],
[
'script',
{},
/* js */ `
var _hmt = _hmt || [];
(function() {
var hm1 = document.createElement("script");
hm1.src = "https://hm.baidu.com/hm.js?08b4ef50a9244e83e5a1bd5822442829"; // gitee
var hm2 = document.createElement("script");
hm2.src = "https://hm.baidu.com/hm.js?50bac15a1f238d1aa61f104a5fb6f5e0"; // github
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm1, s);
s.parentNode.insertBefore(hm2, s);
})();
</script>
`
]
],
plugins: [
'@vuepress/medium-zoom',
'@vuepress/active-header-links',

View File

@ -0,0 +1,10 @@
export default ({ router }) => {
router.beforeEach((to, from, next) => {
if (typeof _hmt !== 'undefined') {
if (to.path) {
_hmt.push(['_trackPageview', to.fullPath]) // 添加埋点上报
}
}
next() // 执行路由跳转
})
}