@datarangers/sdk-javascript 0.1.1 → 0.1.3

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