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