浏览代码

feat: 页面切换时支持延时上报

zhangyuhan 2 年之前
父节点
当前提交
a7277842ad
共有 1 个文件被更改,包括 9 次插入3 次删除
  1. 9 3
      src/easy-use-track.js

+ 9 - 3
src/easy-use-track.js

@@ -20,7 +20,8 @@ class EasyUse {
 
     this.config = Object.assign({
       dataSource,
-      version
+      version,
+      upWaitStep: 200
     }, options)
     this.json = []
     this.params = {}
@@ -102,7 +103,9 @@ class EasyUse {
    */
   addPageChangeListener() {
     window.addEventListener("popstate",  (e) => {
-      this.upPageInfo()
+      setTimeout(() => {
+        this.upPageInfo()
+      }, this.config.upWaitStep)
     }, false)
   }
 
@@ -123,6 +126,7 @@ class EasyUse {
     try {
       clab_tracker.ready(function () {
         this.push({"pageType":"web"});
+        params.url = params.c_url
         this.track("open_page", params);
         clab_tracker.setEnableAutoTrackExitPage(false)
       })
@@ -201,7 +205,9 @@ class EasyUse {
     this.getJSON(`${this.config.dataSource}${this.config.version ? ('?v=' + this.config.version) : ''}`, (data) => {
       if (Array.isArray(data)) {
         this.json = [].concat(data)
-        this.upPageInfo()
+        setTimeout(() => {
+          this.upPageInfo()
+        }, this.config.upWaitStep)
       }
     })
   }