<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’)
 
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。