npm install vue-matomo
main.js
//埋点
import VueMatomo from 'vue-matomo'
Vue.use(VueMatomo, {
host: 'xxxxxx', // 自己的matomo服务器地址,根据tracking code中填写
siteId: xxx, // siteId值,根据tracking code中填写
router: router, // 根据router自动注册
requireConsent: false, // 是否需要在发送追踪信息之前请求许可,默认false
enableLinkTracking: true,
trackInitialView: false, // 是否追踪初始页面,默认true
trackerFileName: 'matomo', // 最终的追踪js文件名,默认'matomo'
debug: false
});
App.vue
第一次进入this.$matomo为undefined,加setTimeout
watch: {
$route(to, form) {
setTimeout(() => {
if (this.first) {
this.$matomo.setRequestMethod("GET");
this.$matomo.setUserId('用户id');
this.first = false
}
this.$matomo.setCustomUrl(window.location.href);
this.$matomo.trackPageView(document.title);
}, 500);
},
},
网友评论