一,友盟
1,在App.vue的mounted中引入script标签,引入友盟统计链接:
const script = document.createElement('script');
script.src = 'https://s5.cnzz.com/z_stat.php?id=12345678&web_id=12345678';
script.language = 'JavaScript';
document.body.appendChild(script);
2,通过watch监听router变化
watch: {
'$route' () {
window.scrollTo(0,0);
if (window._czc) {
let location = window.location;
let contentUrl = location.pathname + location.hash;
let refererUrl = '/';
window._czc.push(['_trackPageview', contentUrl, refererUrl])
}
}
}
二,百度
1,在index.html中引入统计链接
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?11111111111112dsfdf";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
2,在main.js中监听路由变化
router.beforeEach((to, from, next) => {
if (to.path) {
_hmt.push(['_trackPageview', '/#' + to.fullPath]);
}
next();
});