Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Oct 31, 2024
1 parent cff2d94 commit d773f9d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/canyon-platform/public/0.0.1/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
if (window.__coverage__ && window.__canyon__analytics__dsn__) {
function collectCoverageData(timing) {
const data = {
coverage: JSON.stringify(Object.entries(window.__coverage__).map(([path, {b,f,s}]) => ({
path,
b,
f,
s,
})).reduce((acc, {path, b, f, s}) => {
acc[path] = {b, f, s};
return acc;
})),
canyonID:'canyon-platform',
addInfo:{
// 时机
timing: timing,
}
}
navigator.sendBeacon(
window.__canyon__analytics__dsn__,
JSON.stringify(data),
);
}

// beforeunload 事件:当用户即将离开页面时触发
window.addEventListener("beforeunload", () => {
collectCoverageData("beforeunload");
});

// unload 事件:在页面完全卸载前触发
window.addEventListener("unload", () => {
collectCoverageData("unload");
});

// visibilitychange 事件:当页面变为不可见(如切换到其他标签页)时触发
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "hidden") {
collectCoverageData("visibilitychange");
}
});

}
3 changes: 3 additions & 0 deletions tools/canyon-collect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Canyon Collect

js sdk,直接script引入
Empty file added tools/canyon-collect/main.js
Empty file.

0 comments on commit d773f9d

Please sign in to comment.