@datarangers/sdk-javascript 0.1.2 → 0.1.4
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/es/index-base.min.js +6629 -1
- package/es/index.min.js +9570 -1
- package/es/plugin/ab.js +1114 -1
- package/es/plugin/autotrack.js +1608 -1
- package/es/plugin/duration.js +100 -1
- package/es/plugin/route.js +605 -1
- package/es/plugin/stay.js +476 -1
- package/lib/index-base.min.js +6634 -1
- package/lib/index.min.js +9575 -1
- package/lib/plugin/ab.js +1116 -1
- package/lib/plugin/autotrack.js +1610 -1
- package/lib/plugin/duration.js +102 -1
- package/lib/plugin/route.js +607 -1
- package/lib/plugin/stay.js +478 -1
- package/package.json +1 -1
- package/types/types.d.ts +2 -0
package/lib/plugin/stay.js
CHANGED
|
@@ -1 +1,478 @@
|
|
|
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
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
30
|
+
var e = new Error(message);
|
|
31
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
35
|
+
// @ts-nocheck
|
|
36
|
+
// @ts-nocheck
|
|
37
|
+
var isObject = function isObject(obj) {
|
|
38
|
+
return obj != null && Object.prototype.toString.call(obj) == '[object Object]';
|
|
39
|
+
};
|
|
40
|
+
(function () {
|
|
41
|
+
var lastEventId = +Date.now() + Number(("" + Math.random()).slice(2, 8));
|
|
42
|
+
return function () {
|
|
43
|
+
lastEventId += 1;
|
|
44
|
+
return lastEventId;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var isSupVisChange = function isSupVisChange() {
|
|
48
|
+
var flag = 0;
|
|
49
|
+
['hidden', 'msHidden', 'webkitHidden'].forEach(function (hidden) {
|
|
50
|
+
if (document[hidden] !== undefined) {
|
|
51
|
+
flag = 1;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return flag;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
58
|
+
var Alive = /** @class */function () {
|
|
59
|
+
function Alive(collect, config) {
|
|
60
|
+
this.maxDuration = 12 * 60 * 60 * 1000;
|
|
61
|
+
this.aliveDTime = 60 * 1000;
|
|
62
|
+
this.options = {
|
|
63
|
+
aliveName: 'predefine_page_alive',
|
|
64
|
+
params: {}
|
|
65
|
+
};
|
|
66
|
+
this.collect = collect;
|
|
67
|
+
this.config = config;
|
|
68
|
+
this.pageStartTime = Date.now();
|
|
69
|
+
this.sessionStartTime = this.pageStartTime;
|
|
70
|
+
this.timerHandler = null;
|
|
71
|
+
if (isObject(config.enable_stay_duration)) {
|
|
72
|
+
this.options = Object.assign(this.options, config.enable_stay_duration);
|
|
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
|
+
Alive.prototype.resetParams = function (url_path, title, url) {
|
|
81
|
+
this.url_path = url_path;
|
|
82
|
+
this.url = url;
|
|
83
|
+
this.title = title;
|
|
84
|
+
};
|
|
85
|
+
Alive.prototype.enable = function (url_path, title, url) {
|
|
86
|
+
this.url_path = url_path || this.url_path;
|
|
87
|
+
this.url = url || this.url;
|
|
88
|
+
this.title = title || this.title;
|
|
89
|
+
this.disableCallback = this.enablePageAlive();
|
|
90
|
+
if (this.options.params instanceof Function) {
|
|
91
|
+
this.customParmas = this.options.params();
|
|
92
|
+
} else {
|
|
93
|
+
this.customParmas = this.options.params;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
Alive.prototype.disable = function () {
|
|
97
|
+
this.disableCallback();
|
|
98
|
+
this.pageStartTime = Date.now();
|
|
99
|
+
};
|
|
100
|
+
Alive.prototype.sendEvent = function (leave, limited) {
|
|
101
|
+
if (limited === void 0) {
|
|
102
|
+
limited = false;
|
|
103
|
+
}
|
|
104
|
+
var duration = limited ? this.aliveDTime : Date.now() - this.sessionStartTime;
|
|
105
|
+
if (duration < 0 || duration > this.aliveDTime || Date.now() - this.pageStartTime > this.maxDuration) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
this.collect.beconEvent(this.options.aliveName, __assign({
|
|
109
|
+
url_path: this.getParams('url_path'),
|
|
110
|
+
title: this.getParams('title'),
|
|
111
|
+
url: this.getParams('url'),
|
|
112
|
+
duration: duration,
|
|
113
|
+
is_support_visibility_change: isSupVisChange(),
|
|
114
|
+
startTime: this.sessionStartTime,
|
|
115
|
+
hidden: document.visibilityState,
|
|
116
|
+
leave: leave
|
|
117
|
+
}, this.customParmas));
|
|
118
|
+
this.sessionStartTime = Date.now();
|
|
119
|
+
this.resetParams(location.pathname, document.title, location.href);
|
|
120
|
+
};
|
|
121
|
+
Alive.prototype.getParams = function (type) {
|
|
122
|
+
switch (type) {
|
|
123
|
+
case 'url_path':
|
|
124
|
+
return this.set_path || this.url_path || location.pathname;
|
|
125
|
+
case 'title':
|
|
126
|
+
return this.set_title || this.title || document.title || location.pathname;
|
|
127
|
+
case 'url':
|
|
128
|
+
return this.set_url || this.url || location.href;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
Alive.prototype.setUpTimer = function () {
|
|
132
|
+
var _this = this;
|
|
133
|
+
if (this.timerHandler) clearInterval(this.timerHandler);
|
|
134
|
+
return setInterval(function () {
|
|
135
|
+
if (Date.now() - _this.sessionStartTime > _this.aliveDTime) {
|
|
136
|
+
_this.sendEvent(false, true);
|
|
137
|
+
}
|
|
138
|
+
}, 1000);
|
|
139
|
+
};
|
|
140
|
+
Alive.prototype.visibilitychange = function () {
|
|
141
|
+
if (document.visibilityState === 'hidden') {
|
|
142
|
+
if (this.timerHandler) {
|
|
143
|
+
clearInterval(this.timerHandler);
|
|
144
|
+
this.sendEvent(false);
|
|
145
|
+
}
|
|
146
|
+
} else if (document.visibilityState === 'visible') {
|
|
147
|
+
// 重置时间
|
|
148
|
+
this.sessionStartTime = Date.now();
|
|
149
|
+
this.timerHandler = this.setUpTimer();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
Alive.prototype.beforeunload = function () {
|
|
153
|
+
if (!document.hidden) {
|
|
154
|
+
this.sendEvent(true);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
Alive.prototype.enablePageAlive = function () {
|
|
158
|
+
var _this = this;
|
|
159
|
+
this.timerHandler = this.setUpTimer();
|
|
160
|
+
var change = this.visibilitychange.bind(this);
|
|
161
|
+
var before = this.beforeunload.bind(this);
|
|
162
|
+
document.addEventListener('visibilitychange', change);
|
|
163
|
+
window.addEventListener('pagehide', before);
|
|
164
|
+
return function () {
|
|
165
|
+
_this.beforeunload();
|
|
166
|
+
document.removeEventListener('visibilitychange', change);
|
|
167
|
+
window.removeEventListener('beforeunload', before);
|
|
168
|
+
window.removeEventListener('pagehide', before);
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
return Alive;
|
|
172
|
+
}();
|
|
173
|
+
|
|
174
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
175
|
+
var Close = /** @class */function () {
|
|
176
|
+
function Close(collect, config) {
|
|
177
|
+
var _this = this;
|
|
178
|
+
this.maxDuration = 12 * 60 * 60 * 1000;
|
|
179
|
+
this.aliveDTime = 60 * 1000;
|
|
180
|
+
this.options = {
|
|
181
|
+
closeName: 'predefine_page_close',
|
|
182
|
+
params: {}
|
|
183
|
+
};
|
|
184
|
+
this.visibilitychange = function () {
|
|
185
|
+
if (document.visibilityState === 'hidden') {
|
|
186
|
+
_this.activeEndTime = Date.now();
|
|
187
|
+
} else if (document.visibilityState === 'visible') {
|
|
188
|
+
if (_this.activeEndTime) {
|
|
189
|
+
_this.totalTime += _this.activeEndTime - _this.activeStartTime;
|
|
190
|
+
_this.activeTimes += 1;
|
|
191
|
+
}
|
|
192
|
+
_this.activeEndTime = undefined;
|
|
193
|
+
_this.activeStartTime = Date.now();
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
this.beforeunload = function () {
|
|
197
|
+
_this.totalTime += (_this.activeEndTime || Date.now()) - _this.activeStartTime;
|
|
198
|
+
if (_this.config.autotrack) {
|
|
199
|
+
var durationKey = '_tea_cache_duration';
|
|
200
|
+
try {
|
|
201
|
+
var session = window.sessionStorage;
|
|
202
|
+
session.setItem(durationKey, JSON.stringify({
|
|
203
|
+
duration: _this.totalTime,
|
|
204
|
+
page_title: document.title || location.pathname
|
|
205
|
+
}));
|
|
206
|
+
} catch (e) {}
|
|
207
|
+
}
|
|
208
|
+
_this.sendEventPageClose();
|
|
209
|
+
};
|
|
210
|
+
this.collect = collect;
|
|
211
|
+
this.config = config;
|
|
212
|
+
this.maxDuration = config.maxDuration || 24 * 60 * 60 * 1000;
|
|
213
|
+
this.pageStartTime = Date.now();
|
|
214
|
+
if (isObject(config.enable_stay_duration)) {
|
|
215
|
+
this.options = Object.assign(this.options, config.enable_stay_duration);
|
|
216
|
+
}
|
|
217
|
+
this.resetData();
|
|
218
|
+
}
|
|
219
|
+
Close.prototype.setParams = function (url_path, title, url) {
|
|
220
|
+
this.set_path = url_path;
|
|
221
|
+
this.set_url = url;
|
|
222
|
+
this.set_title = title;
|
|
223
|
+
};
|
|
224
|
+
Close.prototype.resetParams = function (url_path, title, url) {
|
|
225
|
+
this.url_path = url_path;
|
|
226
|
+
this.url = url;
|
|
227
|
+
this.title = title;
|
|
228
|
+
};
|
|
229
|
+
Close.prototype.enable = function (url_path, title, url) {
|
|
230
|
+
this.url_path = url_path || this.url_path;
|
|
231
|
+
this.url = url || this.url;
|
|
232
|
+
this.title = title || this.title;
|
|
233
|
+
this.disableCallback = this.enablePageClose();
|
|
234
|
+
};
|
|
235
|
+
Close.prototype.disable = function () {
|
|
236
|
+
this.disableCallback();
|
|
237
|
+
};
|
|
238
|
+
Close.prototype.resetData = function () {
|
|
239
|
+
this.activeStartTime = this.activeStartTime === undefined ? this.pageStartTime : Date.now();
|
|
240
|
+
this.activeEndTime = undefined;
|
|
241
|
+
this.activeTimes = 1;
|
|
242
|
+
this.totalTime = 0;
|
|
243
|
+
if (this.options.params instanceof Function) {
|
|
244
|
+
this.customParmas = this.options.params();
|
|
245
|
+
} else {
|
|
246
|
+
this.customParmas = this.options.params;
|
|
247
|
+
}
|
|
248
|
+
this.resetParams(location.pathname, document.title, location.href);
|
|
249
|
+
};
|
|
250
|
+
Close.prototype.sendEventPageClose = function () {
|
|
251
|
+
var total_duration = Date.now() - this.pageStartTime;
|
|
252
|
+
if (this.totalTime < 0 || total_duration < 0) return;
|
|
253
|
+
// 超过24小时的时长没有统计意义
|
|
254
|
+
if (this.totalTime >= this.maxDuration) return;
|
|
255
|
+
this.collect.beconEvent(this.options.closeName, __assign({
|
|
256
|
+
url_path: this.getParams('url_path'),
|
|
257
|
+
title: this.getParams('title'),
|
|
258
|
+
url: this.getParams('url'),
|
|
259
|
+
active_times: this.activeTimes,
|
|
260
|
+
duration: this.totalTime,
|
|
261
|
+
total_duration: total_duration,
|
|
262
|
+
is_support_visibility_change: isSupVisChange()
|
|
263
|
+
}, this.customParmas));
|
|
264
|
+
this.pageStartTime = Date.now();
|
|
265
|
+
this.resetData();
|
|
266
|
+
};
|
|
267
|
+
Close.prototype.getParams = function (type) {
|
|
268
|
+
switch (type) {
|
|
269
|
+
case 'url_path':
|
|
270
|
+
return this.set_path || this.url_path || location.pathname;
|
|
271
|
+
case 'title':
|
|
272
|
+
return this.set_title || this.title || document.title || location.pathname;
|
|
273
|
+
case 'url':
|
|
274
|
+
return this.set_url || this.url || location.href;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
Close.prototype.enablePageClose = function () {
|
|
278
|
+
var _this = this;
|
|
279
|
+
var change = this.visibilitychange.bind(this);
|
|
280
|
+
var before = this.beforeunload.bind(this);
|
|
281
|
+
document.addEventListener('visibilitychange', change);
|
|
282
|
+
window.addEventListener('pagehide', before);
|
|
283
|
+
return function () {
|
|
284
|
+
_this.beforeunload();
|
|
285
|
+
document.removeEventListener('visibilitychange', change);
|
|
286
|
+
window.removeEventListener('beforeunload', before);
|
|
287
|
+
window.removeEventListener('pagehide', before);
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
return Close;
|
|
291
|
+
}();
|
|
292
|
+
|
|
293
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
294
|
+
var Types;
|
|
295
|
+
(function (Types) {
|
|
296
|
+
Types["Init"] = "init";
|
|
297
|
+
Types["Config"] = "config";
|
|
298
|
+
Types["Start"] = "start";
|
|
299
|
+
Types["Ready"] = "ready";
|
|
300
|
+
Types["TokenComplete"] = "token-complete";
|
|
301
|
+
Types["TokenStorage"] = "token-storage";
|
|
302
|
+
Types["TokenFetch"] = "token-fetch";
|
|
303
|
+
Types["TokenError"] = "token-error";
|
|
304
|
+
Types["ConfigUuid"] = "config-uuid";
|
|
305
|
+
Types["ConfigWebId"] = "config-webid";
|
|
306
|
+
Types["ConfigDomain"] = "config-domain";
|
|
307
|
+
Types["CustomWebId"] = "custom-webid";
|
|
308
|
+
Types["AnonymousId"] = "anonymous-id";
|
|
309
|
+
Types["TokenChange"] = "token-change";
|
|
310
|
+
Types["TokenReset"] = "token-reset";
|
|
311
|
+
Types["ConfigTransform"] = "config-transform";
|
|
312
|
+
Types["EnvTransform"] = "env-transform";
|
|
313
|
+
Types["SessionReset"] = "session-reset";
|
|
314
|
+
Types["SessionResetTime"] = "session-reset-time";
|
|
315
|
+
Types["Event"] = "event";
|
|
316
|
+
Types["Events"] = "events";
|
|
317
|
+
Types["EventNow"] = "event-now";
|
|
318
|
+
Types["CleanEvents"] = "clean-events";
|
|
319
|
+
Types["BeconEvent"] = "becon-event";
|
|
320
|
+
Types["SubmitBefore"] = "submit-before";
|
|
321
|
+
Types["SubmitScuess"] = "submit-scuess";
|
|
322
|
+
Types["SubmitSuccess"] = "submit-success";
|
|
323
|
+
Types["SubmitAfter"] = "submit-after";
|
|
324
|
+
Types["SubmitError"] = "submit-error";
|
|
325
|
+
Types["SubmitVerifyH"] = "submit-verify-h5";
|
|
326
|
+
Types["Stay"] = "stay";
|
|
327
|
+
Types["ResetStay"] = "reset-stay";
|
|
328
|
+
Types["StayReady"] = "stay-ready";
|
|
329
|
+
Types["SetStay"] = "set-stay";
|
|
330
|
+
Types["RouteChange"] = "route-change";
|
|
331
|
+
Types["RouteReady"] = "route-ready";
|
|
332
|
+
Types["Ab"] = "ab";
|
|
333
|
+
Types["AbVar"] = "ab-var";
|
|
334
|
+
Types["AbAllVars"] = "ab-all-vars";
|
|
335
|
+
Types["AbConfig"] = "ab-config";
|
|
336
|
+
Types["AbExternalVersion"] = "ab-external-version";
|
|
337
|
+
Types["AbVersionChangeOn"] = "ab-version-change-on";
|
|
338
|
+
Types["AbVersionChangeOff"] = "ab-version-change-off";
|
|
339
|
+
Types["AbOpenLayer"] = "ab-open-layer";
|
|
340
|
+
Types["AbCloseLayer"] = "ab-close-layer";
|
|
341
|
+
Types["AbReady"] = "ab-ready";
|
|
342
|
+
Types["AbComplete"] = "ab-complete";
|
|
343
|
+
Types["AbTimeout"] = "ab-timeout";
|
|
344
|
+
Types["Profile"] = "profile";
|
|
345
|
+
Types["ProfileSet"] = "profile-set";
|
|
346
|
+
Types["ProfileSetOnce"] = "profile-set-once";
|
|
347
|
+
Types["ProfileUnset"] = "profile-unset";
|
|
348
|
+
Types["ProfileIncrement"] = "profile-increment";
|
|
349
|
+
Types["ProfileAppend"] = "profile-append";
|
|
350
|
+
Types["ProfileClear"] = "profile-clear";
|
|
351
|
+
Types["TrackDuration"] = "track-duration";
|
|
352
|
+
Types["TrackDurationStart"] = "track-duration-start";
|
|
353
|
+
Types["TrackDurationEnd"] = "track-duration-end";
|
|
354
|
+
Types["TrackDurationPause"] = "track-duration-pause";
|
|
355
|
+
Types["TrackDurationResume"] = "tracl-duration-resume";
|
|
356
|
+
Types["Autotrack"] = "autotrack";
|
|
357
|
+
Types["AutotrackReady"] = "autotrack-ready";
|
|
358
|
+
Types["CustomHeader"] = "custom-request-header";
|
|
359
|
+
Types["TracerReady"] = "tracer-ready";
|
|
360
|
+
})(Types || (Types = {}));
|
|
361
|
+
var DebuggerMesssge;
|
|
362
|
+
(function (DebuggerMesssge) {
|
|
363
|
+
DebuggerMesssge["DEBUGGER_MESSAGE"] = "debugger-message";
|
|
364
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_SDK"] = "debugger-message-sdk";
|
|
365
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH"] = "debugger-message-fetch";
|
|
366
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH_RESULT"] = "debugger-message-fetch-result";
|
|
367
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_EVENT"] = "debugger-message-event";
|
|
368
|
+
DebuggerMesssge["DEVTOOL_WEB_READY"] = "devtool-web-ready";
|
|
369
|
+
})(DebuggerMesssge || (DebuggerMesssge = {}));
|
|
370
|
+
|
|
371
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
372
|
+
var Stay = /** @class */function () {
|
|
373
|
+
function Stay() {}
|
|
374
|
+
Stay.prototype.apply = function (collect, config) {
|
|
375
|
+
var _this = this;
|
|
376
|
+
this.collect = collect;
|
|
377
|
+
this.config = config;
|
|
378
|
+
if (!this.config.enable_stay_duration) return;
|
|
379
|
+
this.title = document.title || location.pathname;
|
|
380
|
+
this.url = location.href;
|
|
381
|
+
this.url_path = location.pathname;
|
|
382
|
+
this.pageAlive = new Alive(collect, config);
|
|
383
|
+
this.pageClose = new Close(collect, config);
|
|
384
|
+
var Types = this.collect.Types;
|
|
385
|
+
this.collect.on(Types.ResetStay, function (_a) {
|
|
386
|
+
var url_path = _a.url_path,
|
|
387
|
+
title = _a.title,
|
|
388
|
+
url = _a.url;
|
|
389
|
+
_this.resetStayDuration(url_path, title, url);
|
|
390
|
+
});
|
|
391
|
+
this.collect.on(Types.RouteChange, function (info) {
|
|
392
|
+
if (info.init) return;
|
|
393
|
+
if (config.disable_route_report) return;
|
|
394
|
+
_this.resetStayDuration();
|
|
395
|
+
});
|
|
396
|
+
this.collect.on(Types.SetStay, function (_a) {
|
|
397
|
+
var url_path = _a.url_path,
|
|
398
|
+
title = _a.title,
|
|
399
|
+
url = _a.url;
|
|
400
|
+
_this.setStayParmas(url_path, title, url);
|
|
401
|
+
});
|
|
402
|
+
this.enable(this.url_path, this.title, this.url);
|
|
403
|
+
this.ready(Types.Stay);
|
|
404
|
+
this.collect.emit(Types.StayReady);
|
|
405
|
+
};
|
|
406
|
+
Stay.prototype.ready = function (name) {
|
|
407
|
+
var _this = this;
|
|
408
|
+
this.collect.set(name);
|
|
409
|
+
if (this.collect.hook._hooksCache.hasOwnProperty(name)) {
|
|
410
|
+
var emits = this.collect.hook._hooksCache[name];
|
|
411
|
+
if (!Object.keys(emits).length) return;
|
|
412
|
+
var _loop_1 = function _loop_1(key) {
|
|
413
|
+
if (emits[key].length) {
|
|
414
|
+
emits[key].forEach(function (item) {
|
|
415
|
+
_this.collect.hook.emit(key, item);
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
for (var key in emits) {
|
|
420
|
+
_loop_1(key);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
Stay.prototype.enable = function (url_path, title, url) {
|
|
425
|
+
this.pageAlive.enable(url_path, title, url);
|
|
426
|
+
this.pageClose.enable(url_path, title, url);
|
|
427
|
+
};
|
|
428
|
+
Stay.prototype.disable = function () {
|
|
429
|
+
this.pageAlive.disable();
|
|
430
|
+
this.pageClose.disable();
|
|
431
|
+
};
|
|
432
|
+
Stay.prototype.setStayParmas = function (url_path, title, url) {
|
|
433
|
+
if (url_path === void 0) {
|
|
434
|
+
url_path = '';
|
|
435
|
+
}
|
|
436
|
+
if (title === void 0) {
|
|
437
|
+
title = '';
|
|
438
|
+
}
|
|
439
|
+
if (url === void 0) {
|
|
440
|
+
url = '';
|
|
441
|
+
}
|
|
442
|
+
// 专门用来设置stay的参数
|
|
443
|
+
this.pageAlive.setParams(url_path, title, url);
|
|
444
|
+
this.pageClose.setParams(url_path, title, url);
|
|
445
|
+
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
446
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
447
|
+
info: 'SDK 执行 resetStayParams',
|
|
448
|
+
level: 'info',
|
|
449
|
+
time: Date.now(),
|
|
450
|
+
data: {
|
|
451
|
+
url_path: url_path,
|
|
452
|
+
title: title,
|
|
453
|
+
url: url
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
Stay.prototype.reset = function (url_path, title, url) {
|
|
458
|
+
this.disable();
|
|
459
|
+
this.enable(url_path, title, url);
|
|
460
|
+
};
|
|
461
|
+
Stay.prototype.resetStayDuration = function (url_path, title, url) {
|
|
462
|
+
this.reset(url_path, title, url);
|
|
463
|
+
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
464
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
465
|
+
info: 'SDK 执行 resetStayDuration',
|
|
466
|
+
level: 'info',
|
|
467
|
+
time: Date.now(),
|
|
468
|
+
data: {
|
|
469
|
+
url_path: url_path,
|
|
470
|
+
title: title,
|
|
471
|
+
url: url
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
};
|
|
475
|
+
return Stay;
|
|
476
|
+
}();
|
|
477
|
+
|
|
478
|
+
module.exports = Stay;
|
package/package.json
CHANGED
package/types/types.d.ts
CHANGED
|
@@ -258,6 +258,8 @@ interface Sdk {
|
|
|
258
258
|
resetStayDuration(url_path?: string, title?: string, url?: string): void;
|
|
259
259
|
resetStayParams(url_path?: string, title?: string, url?: string): void;
|
|
260
260
|
|
|
261
|
+
destroyInstance(): void;
|
|
262
|
+
|
|
261
263
|
profileSet(profile: any): void;
|
|
262
264
|
profileSetOnce(profile: any): void;
|
|
263
265
|
profileIncrement(profile: any): void;
|