参考资料:资料
一、Vue 使用百度统计
在Vue单页面开发中接入百度统计代码时,如果直接按照官网的走会出现错误,就是_hmt找不到,这是因为在一个js文件里声明的变量在另一个js文件里是找不到的,所以需要把...使用 Google 统计
单页面应用切换时要手动发送页面统计,首先在 index.html或者 main.js 里引入谷歌统计代码:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject...s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com.../analytics.js','ga');
ga('create', 'UA-yourID', 'auto')
ga('send', 'pageview') // 是否要统计着陆页面访问,取决于你的需求...,这个不一定需要,会和`router`统计有重复
// main.js 里,如果你使用了 vue-router
router.afterEach(function (to) {
if (window.ga