|
@@ -7,11 +7,13 @@ class Tracker {
|
|
this.visitCookieTimeout = options.visitCookieTimeout || 1; // 默认访问次数cookie有效期1分钟
|
|
this.visitCookieTimeout = options.visitCookieTimeout || 1; // 默认访问次数cookie有效期1分钟
|
|
this.maxVisitCount = options.maxVisitCount || 5; // 默认最大访问次数5次
|
|
this.maxVisitCount = options.maxVisitCount || 5; // 默认最大访问次数5次
|
|
this.blockCookieTimeout = options.blockCookieTimeout || 180; // 默认封锁cookie有效期180分钟
|
|
this.blockCookieTimeout = options.blockCookieTimeout || 180; // 默认封锁cookie有效期180分钟
|
|
|
|
+ this.myEventSend = options.myEventSend || (() => {}); // 是否开启自定义事件上报
|
|
|
|
+ this.beforeDestroy = options.beforeDestroy || (() => {}); // 销毁前的回调函数
|
|
}
|
|
}
|
|
|
|
|
|
init() {
|
|
init() {
|
|
- const visitCookieName = 'userVisitCount372';
|
|
|
|
- const blockCookieName = 'userBlocked372';
|
|
|
|
|
|
+ const visitCookieName = 'userVisitCount';
|
|
|
|
+ const blockCookieName = 'userBlocked';
|
|
const isBlocked = getCookie(blockCookieName);
|
|
const isBlocked = getCookie(blockCookieName);
|
|
const doneFN = () => {
|
|
const doneFN = () => {
|
|
this.startTime = Date.now();
|
|
this.startTime = Date.now();
|
|
@@ -44,6 +46,7 @@ init() {
|
|
bindEvents() {
|
|
bindEvents() {
|
|
window.addEventListener('beforeunload', this.handleBeforeUnload);
|
|
window.addEventListener('beforeunload', this.handleBeforeUnload);
|
|
window.addEventListener('click', this.handleClickEvent);
|
|
window.addEventListener('click', this.handleClickEvent);
|
|
|
|
+ this.myEventSend(this.sendData.bind(this)); // 绑定自定义事件上报
|
|
}
|
|
}
|
|
|
|
|
|
startHeartbeat() {
|
|
startHeartbeat() {
|
|
@@ -90,6 +93,7 @@ init() {
|
|
destroy() {
|
|
destroy() {
|
|
window.removeEventListener('beforeunload', this.handleBeforeUnload);
|
|
window.removeEventListener('beforeunload', this.handleBeforeUnload);
|
|
window.removeEventListener('click', this.handleClickEvent);
|
|
window.removeEventListener('click', this.handleClickEvent);
|
|
|
|
+ this.beforeDestroy();
|
|
if (this.timer) {
|
|
if (this.timer) {
|
|
clearInterval(this.timer);
|
|
clearInterval(this.timer);
|
|
}
|
|
}
|