vue中使用友盟统计,统计到每个路由

只需在app.vue中加上此段代码

mounted(){
      const script = document.createElement('script');
      script.src = 'https://s65.cnzz.com/z_stat.php?id=1275785147&web_id=1275785147';//友盟中的代码
      script.language = 'JavaScript';
      document.body.appendChild(script);

    },
    watch: {
      '$route' () {
        if (window._czc) {
          // window._czc.push(["_setAutoPageview", false]);
          let location = window.location;//路由变化
          let contentUrl = location.hash;//自定义当前url,可带上路由以此区分每个页面
          // console.log(contentUrl);
          let refererUrl = '/';
          window._czc.push(["_setAutoPageview", false]);
          window._czc.push(["_trackPageview", contentUrl, refererUrl])

        }

      }

 

你可能感兴趣的:(原创,vue,前端)