项目埋点(vue)

2019-08-16  本文已影响0人  jane819
 <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
上一篇 下一篇

猜你喜欢

热点阅读