@datarangers/sdk-javascript 0.1.0 → 0.1.2

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,117 +1 @@
1
- // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
2
- var TrackDuration =
3
- /** @class */
4
- function () {
5
- function TrackDuration() {}
6
-
7
- TrackDuration.prototype.apply = function (collector, config) {
8
- var _this = this;
9
-
10
- this.collector = collector;
11
- this.config = config;
12
- var Types = collector.Types;
13
- collector.on(Types.TrackDurationStart, function (eventName) {
14
- _this.trackStart(eventName);
15
- });
16
- collector.on(Types.TrackDurationEnd, function (info) {
17
- _this.trackEnd(info);
18
- });
19
- collector.on(Types.TrackDurationPause, function (eventName) {
20
- _this.trackPause(eventName);
21
- });
22
- collector.on(Types.TrackDurationResume, function (eventName) {
23
- _this.trackResume(eventName);
24
- });
25
- this.Types = Types;
26
- this.TrackMap = new Map();
27
- this.ready(Types.TrackDuration);
28
- };
29
-
30
- TrackDuration.prototype.ready = function (name) {
31
- var _this = this;
32
-
33
- this.collector.set(name);
34
-
35
- if (this.collector.hook._hooksCache.hasOwnProperty(name)) {
36
- var emits = this.collector.hook._hooksCache[name];
37
- if (!Object.keys(emits).length) return;
38
-
39
- var _loop_1 = function _loop_1(key) {
40
- if (emits[key].length) {
41
- emits[key].forEach(function (item) {
42
- _this.collector.hook.emit(key, item);
43
- });
44
- }
45
- };
46
-
47
- for (var key in emits) {
48
- _loop_1(key);
49
- }
50
- }
51
- };
52
-
53
- TrackDuration.prototype.trackStart = function (eventName) {
54
- this.TrackMap.set(eventName, {
55
- startTime: Date.now(),
56
- isPause: false,
57
- pauseTime: 0,
58
- resumeTime: 0
59
- });
60
- };
61
-
62
- TrackDuration.prototype.trackEnd = function (info) {
63
- var eventName = info.eventName,
64
- params = info.params;
65
- if (!this.TrackMap.has(eventName)) return;
66
- var trackData = this.TrackMap.get(eventName);
67
- var event_duration = 0;
68
-
69
- if (trackData.isPause) {
70
- // 暂停后,未恢复,直接结束
71
- event_duration = trackData.pauseTime - trackData.startTime;
72
- } else {
73
- // 处于未暂停状态,可能是恢复了,可能是从未暂停过
74
- if (trackData.resumeTime) {
75
- // 暂停后,恢复了
76
- event_duration = trackData.pauseTime - trackData.startTime + (Date.now() - trackData.resumeTime);
77
- } else {
78
- // 未暂停过
79
- event_duration = Date.now() - trackData.startTime;
80
- }
81
- }
82
-
83
- var eventParmas = Object.assign(params, {
84
- event_duration: event_duration
85
- });
86
- this.collector.event(eventName, eventParmas);
87
- this.cleanTrack(eventName);
88
- }; // 事件暂停计时
89
-
90
-
91
- TrackDuration.prototype.trackPause = function (eventName) {
92
- if (!this.TrackMap.has(eventName)) return;
93
- var trackData = this.TrackMap.get(eventName);
94
- if (trackData.isPause) return;
95
- trackData.isPause = true;
96
- trackData.pauseTime = Date.now();
97
- this.TrackMap.set(eventName, trackData);
98
- }; // 事件恢复计时
99
-
100
-
101
- TrackDuration.prototype.trackResume = function (eventName) {
102
- if (!this.TrackMap.has(eventName)) return;
103
- var trackData = this.TrackMap.get(eventName);
104
- if (!trackData.isPause) return;
105
- trackData.isPause = false;
106
- trackData.resumeTime = Date.now();
107
- this.TrackMap.set(eventName, trackData);
108
- };
109
-
110
- TrackDuration.prototype.cleanTrack = function (eventName) {
111
- this.TrackMap["delete"](eventName);
112
- };
113
-
114
- return TrackDuration;
115
- }();
116
-
117
- export { TrackDuration as default };
1
+ var t=function(){function t(){}return t.prototype.apply=function(t,a){var e=this;this.collector=t,this.config=a;var r=t.Types;t.on(r.TrackDurationStart,function(t){e.trackStart(t)}),t.on(r.TrackDurationEnd,function(t){e.trackEnd(t)}),t.on(r.TrackDurationPause,function(t){e.trackPause(t)}),t.on(r.TrackDurationResume,function(t){e.trackResume(t)}),this.Types=r,this.TrackMap=new Map,this.ready(r.TrackDuration)},t.prototype.ready=function(t){var a=this;if(this.collector.set(t),this.collector.hook._hooksCache.hasOwnProperty(t)){var e=this.collector.hook._hooksCache[t];if(!Object.keys(e).length)return;var r=function(t){e[t].length&&e[t].forEach(function(e){a.collector.hook.emit(t,e)})};for(var o in e)r(o)}},t.prototype.trackStart=function(t){this.TrackMap.set(t,{startTime:Date.now(),isPause:!1,pauseTime:0,resumeTime:0})},t.prototype.trackEnd=function(t){var a=t.eventName,e=t.params;if(this.TrackMap.has(a)){var r=this.TrackMap.get(a),o=0;o=r.isPause?r.pauseTime-r.startTime:r.resumeTime?r.pauseTime-r.startTime+(Date.now()-r.resumeTime):Date.now()-r.startTime;var i=Object.assign(e,{event_duration:o});this.collector.event(a,i),this.cleanTrack(a)}},t.prototype.trackPause=function(t){if(this.TrackMap.has(t)){var a=this.TrackMap.get(t);a.isPause||(a.isPause=!0,a.pauseTime=Date.now(),this.TrackMap.set(t,a))}},t.prototype.trackResume=function(t){if(this.TrackMap.has(t)){var a=this.TrackMap.get(t);a.isPause&&(a.isPause=!1,a.resumeTime=Date.now(),this.TrackMap.set(t,a))}},t.prototype.cleanTrack=function(t){this.TrackMap.delete(t)},t}();export{t as default};
@@ -1,363 +1 @@
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
- function __read(o, n) {
17
- var m = typeof Symbol === "function" && o[Symbol.iterator];
18
- if (!m) return o;
19
- var i = m.call(o), r, ar = [], e;
20
- try {
21
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
- }
23
- catch (error) { e = { error: error }; }
24
- finally {
25
- try {
26
- if (r && !r.done && (m = i["return"])) m.call(i);
27
- }
28
- finally { if (e) throw e.error; }
29
- }
30
- return ar;
31
- }
32
-
33
- /** @deprecated */
34
- function __spread() {
35
- for (var ar = [], i = 0; i < arguments.length; i++)
36
- ar = ar.concat(__read(arguments[i]));
37
- return ar;
38
- }
39
-
40
- // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
41
- var Types;
42
-
43
- (function (Types) {
44
- Types["Init"] = "init";
45
- Types["Config"] = "config";
46
- Types["Start"] = "start";
47
- Types["Ready"] = "ready";
48
- Types["TokenComplete"] = "token-complete";
49
- Types["TokenStorage"] = "token-storage";
50
- Types["TokenFetch"] = "token-fetch";
51
- Types["TokenError"] = "token-error";
52
- Types["ConfigUuid"] = "config-uuid";
53
- Types["ConfigWebId"] = "config-webid";
54
- Types["ConfigDomain"] = "config-domain";
55
- Types["CustomWebId"] = "custom-webid";
56
- Types["AnonymousId"] = "anonymous-id";
57
- Types["TokenChange"] = "token-change";
58
- Types["TokenReset"] = "token-reset";
59
- Types["ConfigTransform"] = "config-transform";
60
- Types["EnvTransform"] = "env-transform";
61
- Types["SessionReset"] = "session-reset";
62
- Types["SessionResetTime"] = "session-reset-time";
63
- Types["Event"] = "event";
64
- Types["Events"] = "events";
65
- Types["EventNow"] = "event-now";
66
- Types["CleanEvents"] = "clean-events";
67
- Types["BeconEvent"] = "becon-event";
68
- Types["SubmitBefore"] = "submit-before";
69
- Types["SubmitScuess"] = "submit-scuess";
70
- Types["SubmitAfter"] = "submit-after";
71
- Types["SubmitError"] = "submit-error";
72
- Types["SubmitVerifyH"] = "submit-verify-h5";
73
- Types["Stay"] = "stay";
74
- Types["ResetStay"] = "reset-stay";
75
- Types["StayReady"] = "stay-ready";
76
- Types["SetStay"] = "set-stay";
77
- Types["RouteChange"] = "route-change";
78
- Types["RouteReady"] = "route-ready";
79
- Types["Ab"] = "ab";
80
- Types["AbVar"] = "ab-var";
81
- Types["AbAllVars"] = "ab-all-vars";
82
- Types["AbConfig"] = "ab-config";
83
- Types["AbExternalVersion"] = "ab-external-version";
84
- Types["AbVersionChangeOn"] = "ab-version-change-on";
85
- Types["AbVersionChangeOff"] = "ab-version-change-off";
86
- Types["AbOpenLayer"] = "ab-open-layer";
87
- Types["AbCloseLayer"] = "ab-close-layer";
88
- Types["AbReady"] = "ab-ready";
89
- Types["AbComplete"] = "ab-complete";
90
- Types["AbTimeout"] = "ab-timeout";
91
- Types["Profile"] = "profile";
92
- Types["ProfileSet"] = "profile-set";
93
- Types["ProfileSetOnce"] = "profile-set-once";
94
- Types["ProfileUnset"] = "profile-unset";
95
- Types["ProfileIncrement"] = "profile-increment";
96
- Types["ProfileAppend"] = "profile-append";
97
- Types["ProfileClear"] = "profile-clear";
98
- Types["TrackDuration"] = "track-duration";
99
- Types["TrackDurationStart"] = "track-duration-start";
100
- Types["TrackDurationEnd"] = "track-duration-end";
101
- Types["TrackDurationPause"] = "track-duration-pause";
102
- Types["TrackDurationResume"] = "tracl-duration-resume";
103
- Types["Autotrack"] = "autotrack";
104
- Types["AutotrackReady"] = "autotrack-ready";
105
- Types["CepReady"] = "cep-ready";
106
- Types["TracerReady"] = "tracer-ready";
107
- })(Types || (Types = {}));
108
-
109
- var DebuggerMesssge;
110
-
111
- (function (DebuggerMesssge) {
112
- DebuggerMesssge["DEBUGGER_MESSAGE"] = "debugger-message";
113
- DebuggerMesssge["DEBUGGER_MESSAGE_SDK"] = "debugger-message-sdk";
114
- DebuggerMesssge["DEBUGGER_MESSAGE_FETCH"] = "debugger-message-fetch";
115
- DebuggerMesssge["DEBUGGER_MESSAGE_FETCH_RESULT"] = "debugger-message-fetch-result";
116
- DebuggerMesssge["DEBUGGER_MESSAGE_EVENT"] = "debugger-message-event";
117
- DebuggerMesssge["DEVTOOL_WEB_READY"] = "devtool-web-ready";
118
- })(DebuggerMesssge || (DebuggerMesssge = {}));
119
-
120
- var RuotePage =
121
- /** @class */
122
- function () {
123
- function RuotePage() {
124
- this.autotrack = false;
125
- this.spa = false;
126
- this.cache = {};
127
- this.allowHash = false;
128
- }
129
-
130
- RuotePage.prototype.apply = function (collect, config) {
131
- if (!config.spa && !config.autotrack) return;
132
- var Types = collect.Types;
133
- this.collect = collect;
134
- this.config = config;
135
- this.appid = config.app_id;
136
- this.allowHash = config.allow_hash;
137
- this.fncArray = new Map();
138
- this.setKey();
139
- this.setLocation();
140
- this.hack();
141
- this.init();
142
- this.listener();
143
- collect.emit(Types.RouteReady);
144
- };
145
-
146
- RuotePage.prototype.setKey = function () {
147
- var storage = this.collect.adapters.storage;
148
- this.storage = new storage(false);
149
- this.cache_key = "__tea_cache_refer_" + this.appid;
150
- this.cache = {
151
- refer_key: '',
152
- refer_title: document.title || location.pathname,
153
- refer_manual_key: '',
154
- routeChange: false
155
- };
156
-
157
- if (this.config.autotrack && typeof this.config.autotrack === 'object' && this.config.autotrack.page_manual_key) {
158
- this.cache.refer_manual_key = this.config.autotrack.page_manual_key;
159
- }
160
-
161
- this.storage.setItem(this.cache_key, this.cache);
162
- };
163
-
164
- RuotePage.prototype.hack = function () {
165
- var _this = this;
166
-
167
- var oldPushState = window.history.pushState;
168
-
169
- history.pushState = function (state) {
170
- var args = [];
171
-
172
- for (var _i = 1; _i < arguments.length; _i++) {
173
- args[_i - 1] = arguments[_i];
174
- }
175
-
176
- if (typeof history['onpushstate'] === 'function') {
177
- history['onpushstate']({
178
- state: state
179
- });
180
- }
181
-
182
- var ret = oldPushState.call.apply(oldPushState, __spread([history, state], args));
183
- if (_this.lastLocation === location.href) return;
184
-
185
- var config = _this.getPopStateChangeEventData();
186
-
187
- _this.setReferCache(_this.lastLocation);
188
-
189
- _this.lastLocation = location.href;
190
-
191
- _this.sendPv(config, 'pushState');
192
-
193
- return ret;
194
- };
195
-
196
- var oldReplaceState = history.replaceState;
197
-
198
- history.replaceState = function (state) {
199
- var args = [];
200
-
201
- for (var _i = 1; _i < arguments.length; _i++) {
202
- args[_i - 1] = arguments[_i];
203
- }
204
-
205
- if (typeof history['onreplacestate'] === 'function') {
206
- history['onreplacestate']({
207
- state: state
208
- });
209
- }
210
-
211
- var ret = oldReplaceState.call.apply(oldReplaceState, __spread([history, state], args));
212
- if (_this.lastLocation === location.href) return;
213
-
214
- var config = _this.getPopStateChangeEventData();
215
-
216
- _this.setReferCache(_this.lastLocation);
217
-
218
- _this.lastLocation = location.href;
219
-
220
- _this.sendPv(config);
221
-
222
- return ret;
223
- };
224
- };
225
-
226
- RuotePage.prototype.setLocation = function () {
227
- if (typeof window !== 'undefined') {
228
- this.lastLocation = window.location.href;
229
- }
230
- };
231
-
232
- RuotePage.prototype.getLocation = function () {
233
- return this.lastLocation;
234
- };
235
-
236
- RuotePage.prototype.init = function () {
237
- var config = this.getPopStateChangeEventData();
238
- this.collect.emit('route-change', {
239
- config: config,
240
- init: true
241
- });
242
- };
243
-
244
- RuotePage.prototype.listener = function () {
245
- var _this = this;
246
-
247
- var timeoutId = null;
248
- var time = 10;
249
- window.addEventListener('hashchange', function (e) {
250
- if (_this.lastLocation === window.location.href) return;
251
- clearTimeout(timeoutId);
252
-
253
- if (_this.allowHash) {
254
- // 如果允许hashTag,就执行回调函数
255
- _this.setReferCache(_this.lastLocation);
256
-
257
- _this.lastLocation = window.location.href;
258
-
259
- var config = _this.getPopStateChangeEventData();
260
-
261
- _this.sendPv(config);
262
- }
263
- });
264
- window.addEventListener('popstate', function (e) {
265
- if (_this.lastLocation === window.location.href) {
266
- return;
267
- }
268
-
269
- timeoutId = setTimeout(function () {
270
- _this.setReferCache(_this.lastLocation);
271
-
272
- _this.lastLocation = window.location.href;
273
-
274
- var config = _this.getPopStateChangeEventData();
275
-
276
- _this.sendPv(config);
277
- }, time);
278
- });
279
- };
280
-
281
- RuotePage.prototype.getPopStateChangeEventData = function () {
282
- var config = this.pageConfig();
283
- config['is_back'] = 0;
284
- return config;
285
- };
286
-
287
- RuotePage.prototype.pageConfig = function () {
288
- try {
289
- var cache_local = this.storage.getItem(this.cache_key) || {};
290
- var is_first_time = false;
291
- var firstStatus = this.storage.getItem("__tea_cache_first_" + this.appid);
292
-
293
- if (firstStatus && firstStatus == 1) {
294
- is_first_time = false;
295
- } else {
296
- is_first_time = true;
297
- }
298
-
299
- return {
300
- is_html: 1,
301
- url: location.href,
302
- referrer: this.handleRefer(),
303
- page_key: location.href,
304
- refer_page_key: this.handleRefer(),
305
- page_title: document.title || location.pathname,
306
- page_manual_key: this.config.autotrack && this.config.autotrack.page_manual_key || '',
307
- refer_page_manual_key: cache_local && cache_local.refer_manual_key || '',
308
- refer_page_title: cache_local && cache_local.refer_title || '',
309
- page_path: location.pathname,
310
- page_host: location.host,
311
- is_first_time: "" + is_first_time
312
- };
313
- } catch (e) {
314
- this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
315
- type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
316
- info: '发生了异常',
317
- level: 'error',
318
- time: Date.now(),
319
- data: e.message
320
- });
321
- return {};
322
- }
323
- };
324
-
325
- RuotePage.prototype.sendPv = function (config, name) {
326
- this.collect.emit('route-change', {
327
- config: config,
328
- init: false
329
- });
330
- };
331
-
332
- RuotePage.prototype.handleRefer = function () {
333
- var refer = '';
334
-
335
- try {
336
- var cache_local = this.storage.getItem() || {};
337
-
338
- if (cache_local.routeChange) {
339
- // 已经发生路由变化
340
- refer = cache_local.refer_key;
341
- } else {
342
- // 首页,用浏览器的refer
343
- refer = this.collect.configManager.get('referrer');
344
- }
345
- } catch (e) {
346
- refer = document.referrer;
347
- }
348
-
349
- return refer;
350
- };
351
-
352
- RuotePage.prototype.setReferCache = function (url) {
353
- var cache_local = this.storage.getItem(this.cache_key) || {};
354
- cache_local.refer_key = url; // 不再是第一次进入页面
355
-
356
- cache_local.routeChange = true;
357
- this.storage.setItem(this.cache_key, cache_local);
358
- };
359
-
360
- return RuotePage;
361
- }();
362
-
363
- export { RuotePage as default };
1
+ function e(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var r,n,a=o.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=a.next()).done;)i.push(r.value)}catch(e){n={error:e}}finally{try{r&&!r.done&&(o=a.return)&&o.call(a)}finally{if(n)throw n.error}}return i}function t(){for(var t=[],o=0;o<arguments.length;o++)t=t.concat(e(arguments[o]));return t}var o,r;!function(e){e.Init="init",e.Config="config",e.Start="start",e.Ready="ready",e.TokenComplete="token-complete",e.TokenStorage="token-storage",e.TokenFetch="token-fetch",e.TokenError="token-error",e.ConfigUuid="config-uuid",e.ConfigWebId="config-webid",e.ConfigDomain="config-domain",e.CustomWebId="custom-webid",e.AnonymousId="anonymous-id",e.TokenChange="token-change",e.TokenReset="token-reset",e.ConfigTransform="config-transform",e.EnvTransform="env-transform",e.SessionReset="session-reset",e.SessionResetTime="session-reset-time",e.Event="event",e.Events="events",e.EventNow="event-now",e.CleanEvents="clean-events",e.BeconEvent="becon-event",e.SubmitBefore="submit-before",e.SubmitScuess="submit-scuess",e.SubmitSuccess="submit-success",e.SubmitAfter="submit-after",e.SubmitError="submit-error",e.SubmitVerifyH="submit-verify-h5",e.Stay="stay",e.ResetStay="reset-stay",e.StayReady="stay-ready",e.SetStay="set-stay",e.RouteChange="route-change",e.RouteReady="route-ready",e.Ab="ab",e.AbVar="ab-var",e.AbAllVars="ab-all-vars",e.AbConfig="ab-config",e.AbExternalVersion="ab-external-version",e.AbVersionChangeOn="ab-version-change-on",e.AbVersionChangeOff="ab-version-change-off",e.AbOpenLayer="ab-open-layer",e.AbCloseLayer="ab-close-layer",e.AbReady="ab-ready",e.AbComplete="ab-complete",e.AbTimeout="ab-timeout",e.Profile="profile",e.ProfileSet="profile-set",e.ProfileSetOnce="profile-set-once",e.ProfileUnset="profile-unset",e.ProfileIncrement="profile-increment",e.ProfileAppend="profile-append",e.ProfileClear="profile-clear",e.TrackDuration="track-duration",e.TrackDurationStart="track-duration-start",e.TrackDurationEnd="track-duration-end",e.TrackDurationPause="track-duration-pause",e.TrackDurationResume="tracl-duration-resume",e.Autotrack="autotrack",e.AutotrackReady="autotrack-ready",e.CustomHeader="custom-request-header",e.TracerReady="tracer-ready"}(o||(o={})),function(e){e.DEBUGGER_MESSAGE="debugger-message",e.DEBUGGER_MESSAGE_SDK="debugger-message-sdk",e.DEBUGGER_MESSAGE_FETCH="debugger-message-fetch",e.DEBUGGER_MESSAGE_FETCH_RESULT="debugger-message-fetch-result",e.DEBUGGER_MESSAGE_EVENT="debugger-message-event",e.DEVTOOL_WEB_READY="devtool-web-ready"}(r||(r={}));var n,a,i=(n=function(e,t){var o;o=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var o=arguments[e];for(var r in o)t[r]=o[r]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function o(r){function n(){}function a(t,o,a){if("undefined"!=typeof document){"number"==typeof(a=e({path:"/"},n.defaults,a)).expires&&(a.expires=new Date(1*new Date+864e5*a.expires)),a.expires=a.expires?a.expires.toUTCString():"";try{var i=JSON.stringify(o);/^[\{\[]/.test(i)&&(o=i)}catch(e){}o=r.write?r.write(o,t):encodeURIComponent(String(o)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var s="";for(var c in a)a[c]&&(s+="; "+c,!0!==a[c]&&(s+="="+a[c].split(";")[0]));return document.cookie=t+"="+o+s}}function i(e,o){if("undefined"!=typeof document){for(var n={},a=document.cookie?document.cookie.split("; "):[],i=0;i<a.length;i++){var s=a[i].split("="),c=s.slice(1).join("=");o||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var u=t(s[0]);if(c=(r.read||r)(c,u)||t(c),o)try{c=JSON.parse(c)}catch(e){}if(n[u]=c,e===u)break}catch(e){}}return e?n[e]:n}}return n.set=a,n.get=function(e){return i(e,!1)},n.getJSON=function(e){return i(e,!0)},n.remove=function(t,o){a(t,"",e(o,{expires:-1}))},n.defaults={},n.withConverter=o,n}(function(){})},e.exports=o()},n(a={exports:{}},a.exports),a.exports),s=function(){function e(){this.cache={}}return e.prototype.setItem=function(e,t){this.cache[e]=t},e.prototype.getItem=function(e){return this.cache[e]},e.prototype.removeItem=function(e){this.cache[e]=void 0},e}(),c=function(){function e(){this.support=this.isSupportLS()}return e.prototype.isSupportLS=function(){try{return localStorage.setItem("_applogtest-test-key","hi"),localStorage.getItem("_applogtest-test-key"),localStorage.removeItem("_applogtest-test-key"),!0}catch(e){return!1}},e.prototype.getItem=function(e){try{var t=localStorage.getItem(e),o=t;try{t&&"string"==typeof t&&(o=JSON.parse(t))}catch(e){}return o||{}}catch(e){}return{}},e.prototype.setItem=function(e,t){try{var o="string"==typeof t?t:JSON.stringify(t);localStorage.setItem(e,o)}catch(e){}},e.prototype.removeItem=function(e){try{localStorage.removeItem(e)}catch(e){}},e}(),u=function(){function e(){this.support=this.isSupportSession()}return e.prototype.isSupportSession=function(){try{return sessionStorage.setItem("_applogtest-test-key","hi"),sessionStorage.getItem("_applogtest-test-key"),sessionStorage.removeItem("_applogtest-test-key"),!0}catch(e){return!1}},e.prototype.getItem=function(e){try{var t=sessionStorage.getItem(e),o=t;try{t&&"string"==typeof t&&(o=JSON.parse(t))}catch(e){}return o||{}}catch(e){}return{}},e.prototype.setItem=function(e,t){try{var o="string"==typeof t?t:JSON.stringify(t);sessionStorage.setItem(e,o)}catch(e){}},e.prototype.removeItem=function(e){try{sessionStorage.removeItem(e)}catch(e){}},e}(),p=function(){function e(){this.defaultExpireTime=6048e5,this.local=new c,this.session=new u,this.cache=new s}return e.prototype.getLocalItem=function(e){return this.local.getItem(e)},e.prototype.setLocalItem=function(e,t){this.local.setItem(e,t)},e.prototype.removeLocalItem=function(e){this.local.removeItem(e)},e.prototype.getSessionItem=function(e){return this.session.getItem(e)},e.prototype.setSessionItem=function(e,t){this.session.setItem(e,t)},e.prototype.removeSessionItem=function(e){this.session.removeItem(e)},e.prototype.getCacheItem=function(e){return this.cache.getItem(e)},e.prototype.setCacheItem=function(e,t){this.cache.setItem(e,t)},e.prototype.removeCacheItem=function(e){this.cache.removeItem(e)},e.prototype.getCookie=function(e,t){try{return i.get(e)}catch(e){return""}},e.prototype.setCookie=function(e,t,o,r){void 0===o&&(o=this.defaultExpireTime);try{var n=r||document.domain,a=+new Date+o;i.set(e,t,{expires:new Date(a),path:"/",domain:n})}catch(e){}},e.prototype.removeCookie=function(e,t){try{i.remove(e,{path:"/",domain:t||""})}catch(e){}},e}(),f=function(){function e(){this.autotrack=!1,this.spa=!1,this.cache={},this.allowHash=!1}return e.prototype.apply=function(e,t){if(t.spa||t.autotrack){var o=e.Types;this.collect=e,this.config=t,this.appid=t.app_id,this.allowHash=t.allow_hash,this.fncArray=new Map,this.setKey(),this.setLocation(),this.hack(),this.init(),this.listener(),e.emit(o.RouteReady)}},e.prototype.setKey=function(){this.storage=new p,this.cache_key="__tea_cache_refer_"+this.appid,this.cache={refer_key:"",refer_title:document.title||location.pathname,refer_manual_key:"",routeChange:!1},this.config.autotrack&&"object"==typeof this.config.autotrack&&this.config.autotrack.page_manual_key&&(this.cache.refer_manual_key=this.config.autotrack.page_manual_key),this.storage.setLocalItem(this.cache_key,this.cache)},e.prototype.hack=function(){var e=this,o=window.history.pushState;history.pushState=function(r){for(var n=[],a=1;a<arguments.length;a++)n[a-1]=arguments[a];"function"==typeof history.onpushstate&&history.onpushstate({state:r});var i=o.call.apply(o,t([history,r],n));if(e.lastLocation!==location.href){var s=e.getPopStateChangeEventData();return e.setReferCache(e.lastLocation),e.lastLocation=location.href,e.sendPv(s,"pushState"),i}};var r=history.replaceState;history.replaceState=function(o){for(var n=[],a=1;a<arguments.length;a++)n[a-1]=arguments[a];"function"==typeof history.onreplacestate&&history.onreplacestate({state:o});var i=r.call.apply(r,t([history,o],n));if(e.lastLocation!==location.href){var s=e.getPopStateChangeEventData();return e.setReferCache(e.lastLocation),e.lastLocation=location.href,e.sendPv(s),i}}},e.prototype.setLocation=function(){"undefined"!=typeof window&&(this.lastLocation=window.location.href)},e.prototype.getLocation=function(){return this.lastLocation},e.prototype.init=function(){var e=this.getPopStateChangeEventData();this.collect.emit("route-change",{config:e,init:!0})},e.prototype.listener=function(){var e=this,t=null;window.addEventListener("hashchange",function(o){if(e.lastLocation!==window.location.href&&(clearTimeout(t),e.allowHash)){e.setReferCache(e.lastLocation),e.lastLocation=window.location.href;var r=e.getPopStateChangeEventData();e.sendPv(r)}}),window.addEventListener("popstate",function(o){e.lastLocation!==window.location.href&&(t=setTimeout(function(){e.setReferCache(e.lastLocation),e.lastLocation=window.location.href;var t=e.getPopStateChangeEventData();e.sendPv(t)},10))})},e.prototype.getPopStateChangeEventData=function(){var e=this.pageConfig();return e.is_back=0,e},e.prototype.pageConfig=function(){try{var e=this.storage.getLocalItem(this.cache_key)||{},t=!1,o=this.storage.getLocalItem("__tea_cache_first_"+this.appid);return t=!o||1!=o,{is_html:1,url:location.href,referrer:this.handleRefer(),page_key:location.href,refer_page_key:this.handleRefer(),page_title:document.title||location.pathname,page_manual_key:this.config.autotrack&&this.config.autotrack.page_manual_key||"",refer_page_manual_key:e&&e.refer_manual_key||"",refer_page_title:e&&e.refer_title||"",page_path:location.pathname,page_host:location.host,is_first_time:""+t}}catch(e){return this.collect.emit(r.DEBUGGER_MESSAGE,{type:r.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message}),{}}},e.prototype.sendPv=function(e,t){this.collect.emit("route-change",{config:e,init:!1})},e.prototype.handleRefer=function(){var e="";try{var t=this.storage.getLocalItem()||{};e=t.routeChange?t.refer_key:this.collect.configManager.get("referrer")}catch(t){e=document.referrer}return e},e.prototype.setReferCache=function(e){var t=this.storage.getLocalItem(this.cache_key)||{};t.refer_key=e,t.routeChange=!0,this.storage.setLocalItem(this.cache_key,t)},e}();export{f as default};