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