@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.
@@ -1 +1,549 @@
1
- "use strict";var t=function(){return t=Object.assign||function(t){for(var e,i=1,a=arguments.length;i<a;i++)for(var s in e=arguments[i])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);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,s=function(){var t=0;return["hidden","msHidden","webkitHidden"].forEach((function(e){void 0!==document[e]&&(t=1)})),t},n=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:s(),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:s()},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 n(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,s=t.url;i.resetStayDuration(e,a,s)})),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,s=t.url;i.setStayParmas(e,a,s)})),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 s in i)a(s)}},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}();module.exports=r;
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;