@datarangers/sdk-javascript 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/es/index.min.js +1 -0
- package/core/lib/index.min.js +1 -0
- package/es/index-base.min.js +6430 -1
- package/es/index.min.js +9936 -1
- package/es/plugin/ab.js +928 -1
- package/es/plugin/autotrack.js +1897 -1
- package/es/plugin/duration.js +117 -1
- package/es/plugin/route.js +363 -1
- package/es/plugin/stay.js +547 -1
- package/es/plugin/store.js +151 -1
- package/lib/index-base.min.js +6435 -1
- package/lib/index.min.js +9941 -1
- package/lib/plugin/ab.js +930 -1
- package/lib/plugin/autotrack.js +1899 -1
- package/lib/plugin/duration.js +119 -1
- package/lib/plugin/route.js +365 -1
- package/lib/plugin/stay.js +549 -1
- package/lib/plugin/store.js +153 -1
- package/package.json +2 -2
package/lib/plugin/stay.js
CHANGED
|
@@ -1 +1,549 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
|
|
18
|
+
var __assign = function() {
|
|
19
|
+
__assign = Object.assign || function __assign(t) {
|
|
20
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
+
s = arguments[i];
|
|
22
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
30
|
+
// @ts-nocheck
|
|
31
|
+
// @ts-nocheck
|
|
32
|
+
var isObject = function isObject(obj) {
|
|
33
|
+
return obj != null && Object.prototype.toString.call(obj) == '[object Object]';
|
|
34
|
+
};
|
|
35
|
+
(function () {
|
|
36
|
+
var lastEventId = +Date.now() + Number(("" + Math.random()).slice(2, 8));
|
|
37
|
+
return function () {
|
|
38
|
+
lastEventId += 1;
|
|
39
|
+
return lastEventId;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
var isSupVisChange = function isSupVisChange() {
|
|
43
|
+
var flag = 0;
|
|
44
|
+
['hidden', 'msHidden', 'webkitHidden'].forEach(function (hidden) {
|
|
45
|
+
if (document[hidden] !== undefined) {
|
|
46
|
+
flag = 1;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return flag;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
53
|
+
|
|
54
|
+
var Alive =
|
|
55
|
+
/** @class */
|
|
56
|
+
function () {
|
|
57
|
+
function Alive(collect, config) {
|
|
58
|
+
this.maxDuration = 12 * 60 * 60 * 1000;
|
|
59
|
+
this.aliveDTime = 60 * 1000;
|
|
60
|
+
this.options = {
|
|
61
|
+
aliveName: 'predefine_page_alive',
|
|
62
|
+
params: {}
|
|
63
|
+
};
|
|
64
|
+
this.collect = collect;
|
|
65
|
+
this.config = config;
|
|
66
|
+
this.pageStartTime = Date.now();
|
|
67
|
+
this.sessionStartTime = this.pageStartTime;
|
|
68
|
+
this.timerHandler = null;
|
|
69
|
+
|
|
70
|
+
if (isObject(config.enable_stay_duration)) {
|
|
71
|
+
this.options = Object.assign(this.options, config.enable_stay_duration);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
Alive.prototype.setParams = function (url_path, title, url) {
|
|
76
|
+
this.set_path = url_path;
|
|
77
|
+
this.set_url = url;
|
|
78
|
+
this.set_title = title;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
Alive.prototype.resetParams = function (url_path, title, url) {
|
|
82
|
+
this.url_path = url_path;
|
|
83
|
+
this.url = url;
|
|
84
|
+
this.title = title;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
Alive.prototype.enable = function (url_path, title, url) {
|
|
88
|
+
this.url_path = url_path || this.url_path;
|
|
89
|
+
this.url = url || this.url;
|
|
90
|
+
this.title = title || this.title;
|
|
91
|
+
this.disableCallback = this.enablePageAlive();
|
|
92
|
+
|
|
93
|
+
if (this.options.params instanceof Function) {
|
|
94
|
+
this.customParmas = this.options.params();
|
|
95
|
+
} else {
|
|
96
|
+
this.customParmas = this.options.params;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
Alive.prototype.disable = function () {
|
|
101
|
+
this.disableCallback();
|
|
102
|
+
this.pageStartTime = Date.now();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
Alive.prototype.sendEvent = function (leave, limited) {
|
|
106
|
+
if (limited === void 0) {
|
|
107
|
+
limited = false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
var duration = limited ? this.aliveDTime : Date.now() - this.sessionStartTime;
|
|
111
|
+
|
|
112
|
+
if (duration < 0 || duration > this.aliveDTime || Date.now() - this.pageStartTime > this.maxDuration) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this.collect.beconEvent(this.options.aliveName, __assign({
|
|
117
|
+
url_path: this.getParams('url_path'),
|
|
118
|
+
title: this.getParams('title'),
|
|
119
|
+
url: this.getParams('url'),
|
|
120
|
+
duration: duration,
|
|
121
|
+
is_support_visibility_change: isSupVisChange(),
|
|
122
|
+
startTime: this.sessionStartTime,
|
|
123
|
+
hidden: document.visibilityState,
|
|
124
|
+
leave: leave
|
|
125
|
+
}, this.customParmas));
|
|
126
|
+
this.sessionStartTime = Date.now();
|
|
127
|
+
this.resetParams(location.pathname, document.title, location.href);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
Alive.prototype.getParams = function (type) {
|
|
131
|
+
switch (type) {
|
|
132
|
+
case 'url_path':
|
|
133
|
+
return this.set_path || this.url_path || location.pathname;
|
|
134
|
+
|
|
135
|
+
case 'title':
|
|
136
|
+
return this.set_title || this.title || document.title || location.pathname;
|
|
137
|
+
|
|
138
|
+
case 'url':
|
|
139
|
+
return this.set_url || this.url || location.href;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
Alive.prototype.setUpTimer = function () {
|
|
144
|
+
var _this = this;
|
|
145
|
+
|
|
146
|
+
if (this.timerHandler) clearInterval(this.timerHandler);
|
|
147
|
+
return setInterval(function () {
|
|
148
|
+
if (Date.now() - _this.sessionStartTime > _this.aliveDTime) {
|
|
149
|
+
_this.sendEvent(false, true);
|
|
150
|
+
}
|
|
151
|
+
}, 1000);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
Alive.prototype.visibilitychange = function () {
|
|
155
|
+
if (document.visibilityState === 'hidden') {
|
|
156
|
+
if (this.timerHandler) {
|
|
157
|
+
clearInterval(this.timerHandler);
|
|
158
|
+
this.sendEvent(false);
|
|
159
|
+
}
|
|
160
|
+
} else if (document.visibilityState === 'visible') {
|
|
161
|
+
// 重置时间
|
|
162
|
+
this.sessionStartTime = Date.now();
|
|
163
|
+
this.timerHandler = this.setUpTimer();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
Alive.prototype.beforeunload = function () {
|
|
168
|
+
if (!document.hidden) {
|
|
169
|
+
this.sendEvent(true);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
Alive.prototype.enablePageAlive = function () {
|
|
174
|
+
var _this = this;
|
|
175
|
+
|
|
176
|
+
this.timerHandler = this.setUpTimer();
|
|
177
|
+
var change = this.visibilitychange.bind(this);
|
|
178
|
+
var before = this.beforeunload.bind(this);
|
|
179
|
+
document.addEventListener('visibilitychange', change);
|
|
180
|
+
window.addEventListener('pagehide', before);
|
|
181
|
+
return function () {
|
|
182
|
+
_this.beforeunload();
|
|
183
|
+
|
|
184
|
+
document.removeEventListener('visibilitychange', change);
|
|
185
|
+
window.removeEventListener('beforeunload', before);
|
|
186
|
+
window.removeEventListener('pagehide', before);
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
return Alive;
|
|
191
|
+
}();
|
|
192
|
+
|
|
193
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
194
|
+
|
|
195
|
+
var Close =
|
|
196
|
+
/** @class */
|
|
197
|
+
function () {
|
|
198
|
+
function Close(collect, config) {
|
|
199
|
+
var _this = this;
|
|
200
|
+
|
|
201
|
+
this.maxDuration = 12 * 60 * 60 * 1000;
|
|
202
|
+
this.aliveDTime = 60 * 1000;
|
|
203
|
+
this.options = {
|
|
204
|
+
closeName: 'predefine_page_close',
|
|
205
|
+
params: {}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
this.visibilitychange = function () {
|
|
209
|
+
if (document.visibilityState === 'hidden') {
|
|
210
|
+
_this.activeEndTime = Date.now();
|
|
211
|
+
} else if (document.visibilityState === 'visible') {
|
|
212
|
+
if (_this.activeEndTime) {
|
|
213
|
+
_this.totalTime += _this.activeEndTime - _this.activeStartTime;
|
|
214
|
+
_this.activeTimes += 1;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
_this.activeEndTime = undefined;
|
|
218
|
+
_this.activeStartTime = Date.now();
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
this.beforeunload = function () {
|
|
223
|
+
_this.totalTime += (_this.activeEndTime || Date.now()) - _this.activeStartTime;
|
|
224
|
+
|
|
225
|
+
if (_this.config.autotrack) {
|
|
226
|
+
var durationKey = '_tea_cache_duration';
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
var session = window.sessionStorage;
|
|
230
|
+
session.setItem(durationKey, JSON.stringify({
|
|
231
|
+
duration: _this.totalTime,
|
|
232
|
+
page_title: document.title || location.pathname
|
|
233
|
+
}));
|
|
234
|
+
} catch (e) {}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
_this.sendEventPageClose();
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
this.collect = collect;
|
|
241
|
+
this.config = config;
|
|
242
|
+
this.maxDuration = config.maxDuration || 24 * 60 * 60 * 1000;
|
|
243
|
+
this.pageStartTime = Date.now();
|
|
244
|
+
|
|
245
|
+
if (isObject(config.enable_stay_duration)) {
|
|
246
|
+
this.options = Object.assign(this.options, config.enable_stay_duration);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
this.resetData();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
Close.prototype.setParams = function (url_path, title, url) {
|
|
253
|
+
this.set_path = url_path;
|
|
254
|
+
this.set_url = url;
|
|
255
|
+
this.set_title = title;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
Close.prototype.resetParams = function (url_path, title, url) {
|
|
259
|
+
this.url_path = url_path;
|
|
260
|
+
this.url = url;
|
|
261
|
+
this.title = title;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
Close.prototype.enable = function (url_path, title, url) {
|
|
265
|
+
this.url_path = url_path || this.url_path;
|
|
266
|
+
this.url = url || this.url;
|
|
267
|
+
this.title = title || this.title;
|
|
268
|
+
this.disableCallback = this.enablePageClose();
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
Close.prototype.disable = function () {
|
|
272
|
+
this.disableCallback();
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
Close.prototype.resetData = function () {
|
|
276
|
+
this.activeStartTime = this.activeStartTime === undefined ? this.pageStartTime : Date.now();
|
|
277
|
+
this.activeEndTime = undefined;
|
|
278
|
+
this.activeTimes = 1;
|
|
279
|
+
this.totalTime = 0;
|
|
280
|
+
|
|
281
|
+
if (this.options.params instanceof Function) {
|
|
282
|
+
this.customParmas = this.options.params();
|
|
283
|
+
} else {
|
|
284
|
+
this.customParmas = this.options.params;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
this.resetParams(location.pathname, document.title, location.href);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
Close.prototype.sendEventPageClose = function () {
|
|
291
|
+
var total_duration = Date.now() - this.pageStartTime;
|
|
292
|
+
if (this.totalTime < 0 || total_duration < 0) return; // 超过24小时的时长没有统计意义
|
|
293
|
+
|
|
294
|
+
if (this.totalTime >= this.maxDuration) return;
|
|
295
|
+
this.collect.beconEvent(this.options.closeName, __assign({
|
|
296
|
+
url_path: this.getParams('url_path'),
|
|
297
|
+
title: this.getParams('title'),
|
|
298
|
+
url: this.getParams('url'),
|
|
299
|
+
active_times: this.activeTimes,
|
|
300
|
+
duration: this.totalTime,
|
|
301
|
+
total_duration: total_duration,
|
|
302
|
+
is_support_visibility_change: isSupVisChange()
|
|
303
|
+
}, this.customParmas));
|
|
304
|
+
this.pageStartTime = Date.now();
|
|
305
|
+
this.resetData();
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
Close.prototype.getParams = function (type) {
|
|
309
|
+
switch (type) {
|
|
310
|
+
case 'url_path':
|
|
311
|
+
return this.set_path || this.url_path || location.pathname;
|
|
312
|
+
|
|
313
|
+
case 'title':
|
|
314
|
+
return this.set_title || this.title || document.title || location.pathname;
|
|
315
|
+
|
|
316
|
+
case 'url':
|
|
317
|
+
return this.set_url || this.url || location.href;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
Close.prototype.enablePageClose = function () {
|
|
322
|
+
var _this = this;
|
|
323
|
+
|
|
324
|
+
var change = this.visibilitychange.bind(this);
|
|
325
|
+
var before = this.beforeunload.bind(this);
|
|
326
|
+
document.addEventListener('visibilitychange', change);
|
|
327
|
+
window.addEventListener('pagehide', before);
|
|
328
|
+
return function () {
|
|
329
|
+
_this.beforeunload();
|
|
330
|
+
|
|
331
|
+
document.removeEventListener('visibilitychange', change);
|
|
332
|
+
window.removeEventListener('beforeunload', before);
|
|
333
|
+
window.removeEventListener('pagehide', before);
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
return Close;
|
|
338
|
+
}();
|
|
339
|
+
|
|
340
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
341
|
+
var Types;
|
|
342
|
+
|
|
343
|
+
(function (Types) {
|
|
344
|
+
Types["Init"] = "init";
|
|
345
|
+
Types["Config"] = "config";
|
|
346
|
+
Types["Start"] = "start";
|
|
347
|
+
Types["Ready"] = "ready";
|
|
348
|
+
Types["TokenComplete"] = "token-complete";
|
|
349
|
+
Types["TokenStorage"] = "token-storage";
|
|
350
|
+
Types["TokenFetch"] = "token-fetch";
|
|
351
|
+
Types["TokenError"] = "token-error";
|
|
352
|
+
Types["ConfigUuid"] = "config-uuid";
|
|
353
|
+
Types["ConfigWebId"] = "config-webid";
|
|
354
|
+
Types["ConfigDomain"] = "config-domain";
|
|
355
|
+
Types["CustomWebId"] = "custom-webid";
|
|
356
|
+
Types["AnonymousId"] = "anonymous-id";
|
|
357
|
+
Types["TokenChange"] = "token-change";
|
|
358
|
+
Types["TokenReset"] = "token-reset";
|
|
359
|
+
Types["ConfigTransform"] = "config-transform";
|
|
360
|
+
Types["EnvTransform"] = "env-transform";
|
|
361
|
+
Types["SessionReset"] = "session-reset";
|
|
362
|
+
Types["SessionResetTime"] = "session-reset-time";
|
|
363
|
+
Types["Event"] = "event";
|
|
364
|
+
Types["Events"] = "events";
|
|
365
|
+
Types["EventNow"] = "event-now";
|
|
366
|
+
Types["CleanEvents"] = "clean-events";
|
|
367
|
+
Types["BeconEvent"] = "becon-event";
|
|
368
|
+
Types["SubmitBefore"] = "submit-before";
|
|
369
|
+
Types["SubmitScuess"] = "submit-scuess";
|
|
370
|
+
Types["SubmitAfter"] = "submit-after";
|
|
371
|
+
Types["SubmitError"] = "submit-error";
|
|
372
|
+
Types["SubmitVerifyH"] = "submit-verify-h5";
|
|
373
|
+
Types["Stay"] = "stay";
|
|
374
|
+
Types["ResetStay"] = "reset-stay";
|
|
375
|
+
Types["StayReady"] = "stay-ready";
|
|
376
|
+
Types["SetStay"] = "set-stay";
|
|
377
|
+
Types["RouteChange"] = "route-change";
|
|
378
|
+
Types["RouteReady"] = "route-ready";
|
|
379
|
+
Types["Ab"] = "ab";
|
|
380
|
+
Types["AbVar"] = "ab-var";
|
|
381
|
+
Types["AbAllVars"] = "ab-all-vars";
|
|
382
|
+
Types["AbConfig"] = "ab-config";
|
|
383
|
+
Types["AbExternalVersion"] = "ab-external-version";
|
|
384
|
+
Types["AbVersionChangeOn"] = "ab-version-change-on";
|
|
385
|
+
Types["AbVersionChangeOff"] = "ab-version-change-off";
|
|
386
|
+
Types["AbOpenLayer"] = "ab-open-layer";
|
|
387
|
+
Types["AbCloseLayer"] = "ab-close-layer";
|
|
388
|
+
Types["AbReady"] = "ab-ready";
|
|
389
|
+
Types["AbComplete"] = "ab-complete";
|
|
390
|
+
Types["AbTimeout"] = "ab-timeout";
|
|
391
|
+
Types["Profile"] = "profile";
|
|
392
|
+
Types["ProfileSet"] = "profile-set";
|
|
393
|
+
Types["ProfileSetOnce"] = "profile-set-once";
|
|
394
|
+
Types["ProfileUnset"] = "profile-unset";
|
|
395
|
+
Types["ProfileIncrement"] = "profile-increment";
|
|
396
|
+
Types["ProfileAppend"] = "profile-append";
|
|
397
|
+
Types["ProfileClear"] = "profile-clear";
|
|
398
|
+
Types["TrackDuration"] = "track-duration";
|
|
399
|
+
Types["TrackDurationStart"] = "track-duration-start";
|
|
400
|
+
Types["TrackDurationEnd"] = "track-duration-end";
|
|
401
|
+
Types["TrackDurationPause"] = "track-duration-pause";
|
|
402
|
+
Types["TrackDurationResume"] = "tracl-duration-resume";
|
|
403
|
+
Types["Autotrack"] = "autotrack";
|
|
404
|
+
Types["AutotrackReady"] = "autotrack-ready";
|
|
405
|
+
Types["CepReady"] = "cep-ready";
|
|
406
|
+
Types["TracerReady"] = "tracer-ready";
|
|
407
|
+
})(Types || (Types = {}));
|
|
408
|
+
|
|
409
|
+
var DebuggerMesssge;
|
|
410
|
+
|
|
411
|
+
(function (DebuggerMesssge) {
|
|
412
|
+
DebuggerMesssge["DEBUGGER_MESSAGE"] = "debugger-message";
|
|
413
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_SDK"] = "debugger-message-sdk";
|
|
414
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH"] = "debugger-message-fetch";
|
|
415
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH_RESULT"] = "debugger-message-fetch-result";
|
|
416
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_EVENT"] = "debugger-message-event";
|
|
417
|
+
DebuggerMesssge["DEVTOOL_WEB_READY"] = "devtool-web-ready";
|
|
418
|
+
})(DebuggerMesssge || (DebuggerMesssge = {}));
|
|
419
|
+
|
|
420
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
421
|
+
|
|
422
|
+
var Stay =
|
|
423
|
+
/** @class */
|
|
424
|
+
function () {
|
|
425
|
+
function Stay() {}
|
|
426
|
+
|
|
427
|
+
Stay.prototype.apply = function (collect, config) {
|
|
428
|
+
var _this = this;
|
|
429
|
+
|
|
430
|
+
this.collect = collect;
|
|
431
|
+
this.config = config;
|
|
432
|
+
if (!this.config.enable_stay_duration) return;
|
|
433
|
+
this.title = document.title || location.pathname;
|
|
434
|
+
this.url = location.href;
|
|
435
|
+
this.url_path = location.pathname;
|
|
436
|
+
this.pageAlive = new Alive(collect, config);
|
|
437
|
+
this.pageClose = new Close(collect, config);
|
|
438
|
+
var Types = this.collect.Types;
|
|
439
|
+
this.collect.on(Types.ResetStay, function (_a) {
|
|
440
|
+
var url_path = _a.url_path,
|
|
441
|
+
title = _a.title,
|
|
442
|
+
url = _a.url;
|
|
443
|
+
|
|
444
|
+
_this.resetStayDuration(url_path, title, url);
|
|
445
|
+
});
|
|
446
|
+
this.collect.on(Types.RouteChange, function (info) {
|
|
447
|
+
if (info.init) return;
|
|
448
|
+
if (config.disable_route_report) return;
|
|
449
|
+
|
|
450
|
+
_this.resetStayDuration();
|
|
451
|
+
});
|
|
452
|
+
this.collect.on(Types.SetStay, function (_a) {
|
|
453
|
+
var url_path = _a.url_path,
|
|
454
|
+
title = _a.title,
|
|
455
|
+
url = _a.url;
|
|
456
|
+
|
|
457
|
+
_this.setStayParmas(url_path, title, url);
|
|
458
|
+
});
|
|
459
|
+
this.enable(this.url_path, this.title, this.url);
|
|
460
|
+
this.ready(Types.Stay);
|
|
461
|
+
this.collect.emit(Types.StayReady);
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
Stay.prototype.ready = function (name) {
|
|
465
|
+
var _this = this;
|
|
466
|
+
|
|
467
|
+
this.collect.set(name);
|
|
468
|
+
|
|
469
|
+
if (this.collect.hook._hooksCache.hasOwnProperty(name)) {
|
|
470
|
+
var emits = this.collect.hook._hooksCache[name];
|
|
471
|
+
if (!Object.keys(emits).length) return;
|
|
472
|
+
|
|
473
|
+
var _loop_1 = function _loop_1(key) {
|
|
474
|
+
if (emits[key].length) {
|
|
475
|
+
emits[key].forEach(function (item) {
|
|
476
|
+
_this.collect.hook.emit(key, item);
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
for (var key in emits) {
|
|
482
|
+
_loop_1(key);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
Stay.prototype.enable = function (url_path, title, url) {
|
|
488
|
+
this.pageAlive.enable(url_path, title, url);
|
|
489
|
+
this.pageClose.enable(url_path, title, url);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
Stay.prototype.disable = function () {
|
|
493
|
+
this.pageAlive.disable();
|
|
494
|
+
this.pageClose.disable();
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
Stay.prototype.setStayParmas = function (url_path, title, url) {
|
|
498
|
+
if (url_path === void 0) {
|
|
499
|
+
url_path = '';
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (title === void 0) {
|
|
503
|
+
title = '';
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (url === void 0) {
|
|
507
|
+
url = '';
|
|
508
|
+
} // 专门用来设置stay的参数
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
this.pageAlive.setParams(url_path, title, url);
|
|
512
|
+
this.pageClose.setParams(url_path, title, url);
|
|
513
|
+
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
514
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
515
|
+
info: 'SDK 执行 resetStayParams',
|
|
516
|
+
level: 'info',
|
|
517
|
+
time: Date.now(),
|
|
518
|
+
data: {
|
|
519
|
+
url_path: url_path,
|
|
520
|
+
title: title,
|
|
521
|
+
url: url
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
Stay.prototype.reset = function (url_path, title, url) {
|
|
527
|
+
this.disable();
|
|
528
|
+
this.enable(url_path, title, url);
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
Stay.prototype.resetStayDuration = function (url_path, title, url) {
|
|
532
|
+
this.reset(url_path, title, url);
|
|
533
|
+
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
534
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
535
|
+
info: 'SDK 执行 resetStayDuration',
|
|
536
|
+
level: 'info',
|
|
537
|
+
time: Date.now(),
|
|
538
|
+
data: {
|
|
539
|
+
url_path: url_path,
|
|
540
|
+
title: title,
|
|
541
|
+
url: url
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
return Stay;
|
|
547
|
+
}();
|
|
548
|
+
|
|
549
|
+
module.exports = Stay;
|