-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Allen Zhang (张涛)
committed
Oct 31, 2024
1 parent
68ee5f3
commit 07e5793
Showing
3 changed files
with
42 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
// 要收集的数据 | ||
// const dataToSend = JSON.stringify(); | ||
// window.__canyon__ = {} | ||
// window.__coverage__ = {} | ||
// 数据收集函数 | ||
// @ts-ignore | ||
if (window.__canyon__ && window.__coverage__) { | ||
function collectData(t) { | ||
navigator.sendBeacon( | ||
"/api/coverage/collect", | ||
JSON.stringify({ | ||
// @ts-ignore | ||
...window.__canyon__, | ||
// @ts-ignore | ||
coverage: window.__coverage__, | ||
reportID: t, | ||
}), | ||
); | ||
} | ||
|
||
// beforeunload 事件:当用户即将离开页面时触发 | ||
window.addEventListener("beforeunload", () => { | ||
collectData("beforeunload"); | ||
}); | ||
|
||
// unload 事件:在页面完全卸载前触发 | ||
window.addEventListener("unload", () => { | ||
collectData("unload"); | ||
}); | ||
|
||
// visibilitychange 事件:当页面变为不可见(如切换到其他标签页)时触发 | ||
document.addEventListener("visibilitychange", () => { | ||
if (document.visibilityState === "hidden") { | ||
collectData("visibilitychange"); | ||
} | ||
}); | ||
} else { | ||
console.log("no canyon no coverage"); | ||
} | ||
// // 要收集的数据 | ||
// // const dataToSend = JSON.stringify(); | ||
// // window.__canyon__ = {} | ||
// // window.__coverage__ = {} | ||
// // 数据收集函数 | ||
// // @ts-ignore | ||
// if (window.__canyon__ && window.__coverage__) { | ||
// function collectData(t) { | ||
// navigator.sendBeacon( | ||
// "/api/coverage/collect", | ||
// JSON.stringify({ | ||
// // @ts-ignore | ||
// ...window.__canyon__, | ||
// // @ts-ignore | ||
// coverage: window.__coverage__, | ||
// reportID: t, | ||
// }), | ||
// ); | ||
// } | ||
// | ||
// // beforeunload 事件:当用户即将离开页面时触发 | ||
// window.addEventListener("beforeunload", () => { | ||
// collectData("beforeunload"); | ||
// }); | ||
// | ||
// // unload 事件:在页面完全卸载前触发 | ||
// window.addEventListener("unload", () => { | ||
// collectData("unload"); | ||
// }); | ||
// | ||
// // visibilitychange 事件:当页面变为不可见(如切换到其他标签页)时触发 | ||
// document.addEventListener("visibilitychange", () => { | ||
// if (document.visibilityState === "hidden") { | ||
// collectData("visibilitychange"); | ||
// } | ||
// }); | ||
// } else { | ||
// console.log("no canyon no coverage"); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters