美文网首页
项目埋点(vue)

项目埋点(vue)

作者: jane819 | 来源:发表于2019-08-16 11:05 被阅读0次
    • index.html
     <script>
          var _hmt = _hmt || [];
          (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?bcf4b9aa718c44d0552ca883aed26b42";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
          })();
        </script>
    * plugins文件-新建track.ts
      import _Vue from 'vue'
    
    type PluginFunction<T> = (Vue: typeof _Vue, options?: T) => void
    
    interface PluginObject<T> {
      install: PluginFunction<T>;
      [key: string]: any;
    }
    
    const VueTrack:PluginObject<any> = {
      install: () => {}
    }
    
    VueTrack.install = (Vue: typeof _Vue) => {
      function trackEvent(...arg:any) {
        const _hmt = window._hmt || []
        _hmt.push(['_trackEvent', arg]) //百度统计
    // 增加实时查看 
    // 文档地址:
    // http://doc.talkingdata.com/posts/36](http://doc.talkingdata.com/posts/36)
    // html - 》head-》引入sdk  <script src="https://jic.talkingdata.com/app/h5/v1?appid=1A39A61C5DAE4FD3BB35D55019381CCC&vn=web&vc=2"></script>
    // 设置全局变量TDAPP type->shims-tsx.d.ts
    )
        if (arg.length > 2) {
          const kv = { [arg[2]]:arg[3] }
          window.TDAPP.onEvent(arg[1], arg[2], kv)
        } else {
          window.TDAPP.onEvent(arg)
        }
      }
      Vue.prototype.$track = trackEvent
    }
    export default VueTrack
    
    • 最后项目直接使用this.$track('事件id',‘参数1’,‘参数2’,‘参数3’)

    相关文章

      网友评论

          本文标题:项目埋点(vue)

          本文链接:https://www.haomeiwen.com/subject/ynlfsctx.html