Browse Source

优化百度统计:统计信息去除数字id,方便聚合

Michael Wang 5 years ago
parent
commit
6b4a6a9f7a

+ 20 - 19
src/features/OnlineExam/Examing/FaceTracking.vue

@@ -40,16 +40,16 @@ function tensorFlowWebPackStatus() {
   return __cache4TensorFlowWebPackStatus;
 }
 
-function getCPUModel() {
-  if (typeof nodeRequire != "undefined") {
-    var os = window.nodeRequire("os");
-    const cpus = os.cpus();
-    if (cpus.length > 0) {
-      return cpus[0].model;
-    }
-  }
-  return "null";
-}
+// function getCPUModel() {
+//   if (typeof nodeRequire != "undefined") {
+//     var os = window.nodeRequire("os");
+//     const cpus = os.cpus();
+//     if (cpus.length > 0) {
+//       return cpus[0].model;
+//     }
+//   }
+//   return "null";
+// }
 
 // if (os.isWin7) alert("是win7");
 
@@ -186,15 +186,16 @@ export default {
         console.log(detectTimeArray);
         detectTimeArray.push(0, 0); // 避免再次达到push条件和上传条件
 
-        const roundAvg100 = Math.round(avg / 100) * 100;
-        const osType = os.isWin7 ? "win7" : os.isWin10 ? "win10" : "other";
-        const stats = `webgl: ${webgl_available()}; tf_backend: ${faceapi.tf.getBackend()}; os: ${osType}; cpu: ${getCPUModel()}`;
-        window._hmt.push([
-          "_trackEvent",
-          "正在考试页面",
-          "实时人脸检测统计" + roundAvg100 + "ms",
-          stats,
-        ]);
+        // FIXME: 上线初期停止统计此类信息,过于零散
+        // const roundAvg100 = Math.round(avg / 100) * 100;
+        // const osType = os.isWin7 ? "win7" : os.isWin10 ? "win10" : "other";
+        // const stats = `webgl: ${webgl_available()}; tf_backend: ${faceapi.tf.getBackend()}; os: ${osType}; cpu: ${getCPUModel()}`;
+        // window._hmt.push([
+        //   "_trackEvent",
+        //   "正在考试页面",
+        //   "实时人脸检测统计" + roundAvg100 + "ms",
+        //   stats,
+        // ]);
 
         this.multipleTimeUsage = roundAvg;
       }

+ 15 - 6
src/features/OnlineExam/OnlineExamList.vue

@@ -193,12 +193,21 @@ export default {
         idx = successRatePerMinute.length - 1;
       }
       if (Math.random() > 1 - successRatePerMinute[idx]) {
-        window._hmt.push([
-          "_trackEvent",
-          "在线考试列表页面",
-          "摇号进入考试-courseId-" + course.examId,
-          minutesAfterCourseStart / 2 + "分进入",
-        ]);
+        if (minutesAfterCourseStart < 120) {
+          window._hmt.push([
+            "_trackEvent",
+            "在线考试列表页面",
+            "摇号进入考试-courseId-" + course.examId,
+            minutesAfterCourseStart / 2 + "分进入",
+          ]);
+        } else {
+          window._hmt.push([
+            "_trackEvent",
+            "在线考试列表页面",
+            "摇号进入考试-courseId-" + course.examId,
+            "60分后进入",
+          ]);
+        }
 
         this.enterExam(course);
         // return true;

+ 5 - 5
src/utils/axios.js

@@ -74,7 +74,7 @@ qmInstance.interceptors.response.use(
 
       window._hmt.push([
         "_trackEvent",
-        location.pathname,
+        location.pathname.replace(/\d+/g, ""),
         "网络连接异常,请检查网络设置。",
       ]);
 
@@ -135,9 +135,9 @@ qmInstance.interceptors.response.use(
       }
       window._hmt.push([
         "_trackEvent",
-        location.pathname,
+        location.pathname.replace(/\d+/g, ""),
         "服务器繁忙(503)!请稍后重试。",
-        error.config.url,
+        error.config.url.replace(/\d+/g, ""),
       ]);
       Message.error({
         content: "服务器繁忙(503)!请稍后重试。",
@@ -148,9 +148,9 @@ qmInstance.interceptors.response.use(
     } else if (status != 200) {
       window._hmt.push([
         "_trackEvent",
-        location.pathname,
+        location.pathname.replace(/\d+/g, ""),
         "status: " + status,
-        error.config.url,
+        error.config.url.replace(/\d+/g, ""),
       ]);
       if (
         wk_token &&

+ 15 - 7
src/utils/monitors.js

@@ -40,7 +40,7 @@ window.addEventListener("error", function(event) {
   // );
   window._hmt.push([
     "_trackEvent",
-    "全局JS错误:" + window.location.pathname,
+    "全局JS错误:" + window.location.pathname.replace(/\d+/g, ""),
     event.message,
     event.error.stack.replace(/\n/g, "||||"),
   ]);
@@ -64,12 +64,20 @@ window.addEventListener("unhandledrejection", function(event) {
   //     }
   //   }
   // );
-  window._hmt.push([
-    "_trackEvent",
-    "全局Promise未处理错误",
-    location.href,
-    event.reason,
-  ]);
+  if (
+    event.reason &&
+    (event.reason.includes("Box.constructor") ||
+      event.reason.includes("Error: toNetInput"))
+  ) {
+    window._hmt.push(["_trackEvent", "全局Promise未处理错误", event.reason]);
+  } else {
+    window._hmt.push([
+      "_trackEvent",
+      "全局Promise未处理错误",
+      window.location.pathname.replace(/\d+/g, ""),
+      event.reason,
+    ]);
+  }
 });
 
 window.addEventListener("rejectionhandled", function(event) {