Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
init: function init(cb) {
var _this = this;
var OFFLINE_MILL = 15 * 60 * 1000; // 15分钟不操作认为不在线
var SEND_MILL = 5 * 1000; // 每5s打点一次
var lastTime = _Date$now();
window.addEventListener('click', function () {
if (_this.needRecordTimeOnPage === false) {
_this.debugLogger("config.record.time_on_page\u503C\u4E3Afalse, \u8DF3\u8FC7\u505C\u7559\u65F6\u957F\u6253\u70B9");
return;
}
var now = _Date$now();
var duration = now - lastTime;
if (duration > OFFLINE_MILL) {
lastTime = _Date$now();
} else if (duration > SEND_MILL) {
lastTime = _Date$now();
window.addEventListener('click', function () {
if (_this.needRecordTimeOnPage === false) {
_this.debugLogger("config.record.time_on_page\u503C\u4E3Afalse, \u8DF3\u8FC7\u505C\u7559\u65F6\u957F\u6253\u70B9");
return;
}
var now = _Date$now();
var duration = now - lastTime;
if (duration > OFFLINE_MILL) {
lastTime = _Date$now();
} else if (duration > SEND_MILL) {
lastTime = _Date$now();
_this.debugLogger('发送用户留存时间埋点, 埋点内容 => ', {
duration_ms: duration
}); // 用户在线时长
cb && cb.call(_this, 10001, {
duration_ms: duration
});
function checkLoadFinsh() {
var now = _Date$now();
if (now > lastDomChangeTime + 300 && delayNum === 0 && effective) {
// 没有元素在变化同时,没有操作
// 这里就是所有得渲染都完成了,要开始计算首屏元素和时间了
checkDomInfirstScreen(initDoms, reportCallback);
observer.disconnect(); // 监听销毁
} else if (effective) {
_setTimeout(checkLoadFinsh, 300);
}
} // 监听全局得click和键盘输入事件
window.addEventListener('click', function () {
if (_this.needRecordTimeOnPage === false) {
_this.debugLogger("config.record.time_on_page\u503C\u4E3Afalse, \u8DF3\u8FC7\u505C\u7559\u65F6\u957F\u6253\u70B9");
return;
}
var now = _Date$now();
var duration = now - lastTime;
if (duration > OFFLINE_MILL) {
lastTime = _Date$now();
} else if (duration > SEND_MILL) {
lastTime = _Date$now();
_this.debugLogger('发送用户留存时间埋点, 埋点内容 => ', {
duration_ms: duration
}); // 用户在线时长
cb && cb.call(_this, 10001, {
duration_ms: duration
});
}
}, false);
}
export default function initRenderingTime(reportCallback) {
var initDoms = []; // 被加载得doms
var delayNum = 0; // 等待加载得时间
var effective = true; // 操作记录是否有效
var lastDomChangeTime = _Date$now();
var mutationCallback = function mutationCallback(mutationsList) {
var now = _Date$now();
lastDomChangeTime = now;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = _getIterator(mutationsList), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var mutation = _step.value;
var addedNodes = mutation.addedNodes;
for (var i = 0; i < addedNodes.length; i++) {
var addNode = addedNodes[i];
var mutationCallback = function mutationCallback(mutationsList) {
var now = _Date$now();
lastDomChangeTime = now;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = _getIterator(mutationsList), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var mutation = _step.value;
var addedNodes = mutation.addedNodes;
for (var i = 0; i < addedNodes.length; i++) {
var addNode = addedNodes[i];
var domName = getClassName(addNode);
if (/^HTML/.test(domName)) {
addNode.addEventListener('load', function () {
delayNum--;
item.time = _Date$now();
}, false);
}