npm install vue-matomo
main.js
//埋點
import VueMatomo from 'vue-matomo'
Vue.use(VueMatomo, {
host: 'xxxxxx', // 自己的matomo服務器地址,根據(jù)tracking code中填寫
siteId: xxx, // siteId值,根據(jù)tracking code中填寫
router: router, // 根據(jù)router自動注冊
requireConsent: false, // 是否需要在發(fā)送追蹤信息之前請求許可,默認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);
},
},