友盟统计单页面应用vue

根据友盟官方提示在index.html的body标签末尾加入相关代码后:

 

 

后来发现,由于项目为单页面应用,在路由发生跳转时(到其他页面了),并不会重新将新页面加入统计中。需要在App.vue页面中,监听路由,当路由发生变化时,将新页面加入统计中。在App.vue中加入以下代码:

 

watch: {
    '$route' () {
      if (window._czc) {
        let location = window.location
        let contentUrl = location.pathname + location.hash
        let refererUrl = '/'
        window._czc.push(['_trackPageview', contentUrl, refererUrl])
      }
    }
  }

 

posted @ 2019-02-18 14:34  LLLLily  阅读(1111)  评论(0编辑  收藏  举报