Commit b2072824 by Jaxon

修复(埋点上报混入): 完善埋点发送错误处理并统一代码格式

为所有单行if语句补充块级大括号,统一代码书写规范
为埋点数据发送请求添加错误捕获,打印错误日志
1 parent a798793f
...@@ -59,15 +59,19 @@ export default { ...@@ -59,15 +59,19 @@ export default {
eventType, eventType,
pagePath: route.path, pagePath: route.path,
}; };
if (!prePagePath) if (!prePagePath) {
prePagePath = this.getPrePagePath(this); prePagePath = this.getPrePagePath(this);
}
item.prePagePath = prePagePath || "/index"; item.prePagePath = prePagePath || "/index";
if (batchId) if (batchId) {
item.batchId = batchId; item.batchId = batchId;
if (eventCode) }
if (eventCode) {
item.eventCode = eventCode; item.eventCode = eventCode;
if (businessParam) }
if (businessParam) {
item.businessParam = JSON.stringify(businessParam); item.businessParam = JSON.stringify(businessParam);
}
if (!recordList) { if (!recordList) {
recordList = [item]; recordList = [item];
} else { } else {
...@@ -79,8 +83,9 @@ export default { ...@@ -79,8 +83,9 @@ export default {
console.log("---------------- 重新打开定时埋点 ----------------"); console.log("---------------- 重新打开定时埋点 ----------------");
this.sendTrack(); // 开启定时埋点 this.sendTrack(); // 开启定时埋点
} }
if (recordList.length > 9) if (recordList.length > 9) {
this.sendTrackData(); this.sendTrackData();
}
}, },
getRandomString(length = 30) { getRandomString(length = 30) {
const characters const characters
...@@ -94,8 +99,9 @@ export default { ...@@ -94,8 +99,9 @@ export default {
return result; return result;
}, },
onPageShow() { onPageShow() {
if (this.track_page_view_flag) if (this.track_page_view_flag) {
return; return;
}
if (!this.track_batchId) { if (!this.track_batchId) {
this.track_batchId = `DJ_${this.getRandomString()}_${Date.now()}`; this.track_batchId = `DJ_${this.getRandomString()}_${Date.now()}`;
} }
...@@ -127,8 +133,9 @@ export default { ...@@ -127,8 +133,9 @@ export default {
}, 10e3); }, 10e3);
} }
let trackParams = {}; let trackParams = {};
if (this.track_businessParam_key) if (this.track_businessParam_key) {
trackParams = this[this.track_businessParam_key] || {}; trackParams = this[this.track_businessParam_key] || {};
}
this.setReportTrackData( this.setReportTrackData(
2, 2,
this.track_event_code, this.track_event_code,
...@@ -166,8 +173,11 @@ export default { ...@@ -166,8 +173,11 @@ export default {
reportTrack({ reportTrack({
recordList: JSON.parse(recordList), recordList: JSON.parse(recordList),
}).then((res) => { }).then((res) => {
if (res) if (res) {
localStorage.removeItem("recordList"); localStorage.removeItem("recordList");
}
}).catch((e) => {
console.log("发送出错", e);
}); });
} else { } else {
clearInterval(window.TRACK_TIMER); clearInterval(window.TRACK_TIMER);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!