@datarangers/sdk-javascript 0.1.3 → 0.1.5
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/index-base.min.js +1 -6218
- package/es/index.min.js +1 -9165
- package/es/plugin/ab.js +1 -1114
- package/es/plugin/autotrack.js +1 -1608
- package/es/plugin/duration.js +1 -100
- package/es/plugin/route.js +1 -605
- package/es/plugin/stay.js +1 -476
- package/lib/index-base.min.js +1 -6223
- package/lib/index.min.js +1 -9170
- package/lib/plugin/ab.js +1 -1116
- package/lib/plugin/autotrack.js +1 -1610
- package/lib/plugin/duration.js +1 -102
- package/lib/plugin/route.js +1 -607
- package/lib/plugin/stay.js +1 -478
- package/package.json +1 -1
package/lib/plugin/route.js
CHANGED
|
@@ -1,607 +1 @@
|
|
|
1
|
-
|
|
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
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
43
|
-
var e = new Error(message);
|
|
44
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
48
|
-
var Types;
|
|
49
|
-
(function (Types) {
|
|
50
|
-
Types["Init"] = "init";
|
|
51
|
-
Types["Config"] = "config";
|
|
52
|
-
Types["Start"] = "start";
|
|
53
|
-
Types["Ready"] = "ready";
|
|
54
|
-
Types["TokenComplete"] = "token-complete";
|
|
55
|
-
Types["TokenStorage"] = "token-storage";
|
|
56
|
-
Types["TokenFetch"] = "token-fetch";
|
|
57
|
-
Types["TokenError"] = "token-error";
|
|
58
|
-
Types["ConfigUuid"] = "config-uuid";
|
|
59
|
-
Types["ConfigWebId"] = "config-webid";
|
|
60
|
-
Types["ConfigDomain"] = "config-domain";
|
|
61
|
-
Types["CustomWebId"] = "custom-webid";
|
|
62
|
-
Types["AnonymousId"] = "anonymous-id";
|
|
63
|
-
Types["TokenChange"] = "token-change";
|
|
64
|
-
Types["TokenReset"] = "token-reset";
|
|
65
|
-
Types["ConfigTransform"] = "config-transform";
|
|
66
|
-
Types["EnvTransform"] = "env-transform";
|
|
67
|
-
Types["SessionReset"] = "session-reset";
|
|
68
|
-
Types["SessionResetTime"] = "session-reset-time";
|
|
69
|
-
Types["Event"] = "event";
|
|
70
|
-
Types["Events"] = "events";
|
|
71
|
-
Types["EventNow"] = "event-now";
|
|
72
|
-
Types["CleanEvents"] = "clean-events";
|
|
73
|
-
Types["BeconEvent"] = "becon-event";
|
|
74
|
-
Types["SubmitBefore"] = "submit-before";
|
|
75
|
-
Types["SubmitScuess"] = "submit-scuess";
|
|
76
|
-
Types["SubmitSuccess"] = "submit-success";
|
|
77
|
-
Types["SubmitAfter"] = "submit-after";
|
|
78
|
-
Types["SubmitError"] = "submit-error";
|
|
79
|
-
Types["SubmitVerifyH"] = "submit-verify-h5";
|
|
80
|
-
Types["Stay"] = "stay";
|
|
81
|
-
Types["ResetStay"] = "reset-stay";
|
|
82
|
-
Types["StayReady"] = "stay-ready";
|
|
83
|
-
Types["SetStay"] = "set-stay";
|
|
84
|
-
Types["RouteChange"] = "route-change";
|
|
85
|
-
Types["RouteReady"] = "route-ready";
|
|
86
|
-
Types["Ab"] = "ab";
|
|
87
|
-
Types["AbVar"] = "ab-var";
|
|
88
|
-
Types["AbAllVars"] = "ab-all-vars";
|
|
89
|
-
Types["AbConfig"] = "ab-config";
|
|
90
|
-
Types["AbExternalVersion"] = "ab-external-version";
|
|
91
|
-
Types["AbVersionChangeOn"] = "ab-version-change-on";
|
|
92
|
-
Types["AbVersionChangeOff"] = "ab-version-change-off";
|
|
93
|
-
Types["AbOpenLayer"] = "ab-open-layer";
|
|
94
|
-
Types["AbCloseLayer"] = "ab-close-layer";
|
|
95
|
-
Types["AbReady"] = "ab-ready";
|
|
96
|
-
Types["AbComplete"] = "ab-complete";
|
|
97
|
-
Types["AbTimeout"] = "ab-timeout";
|
|
98
|
-
Types["Profile"] = "profile";
|
|
99
|
-
Types["ProfileSet"] = "profile-set";
|
|
100
|
-
Types["ProfileSetOnce"] = "profile-set-once";
|
|
101
|
-
Types["ProfileUnset"] = "profile-unset";
|
|
102
|
-
Types["ProfileIncrement"] = "profile-increment";
|
|
103
|
-
Types["ProfileAppend"] = "profile-append";
|
|
104
|
-
Types["ProfileClear"] = "profile-clear";
|
|
105
|
-
Types["TrackDuration"] = "track-duration";
|
|
106
|
-
Types["TrackDurationStart"] = "track-duration-start";
|
|
107
|
-
Types["TrackDurationEnd"] = "track-duration-end";
|
|
108
|
-
Types["TrackDurationPause"] = "track-duration-pause";
|
|
109
|
-
Types["TrackDurationResume"] = "tracl-duration-resume";
|
|
110
|
-
Types["Autotrack"] = "autotrack";
|
|
111
|
-
Types["AutotrackReady"] = "autotrack-ready";
|
|
112
|
-
Types["CustomHeader"] = "custom-request-header";
|
|
113
|
-
Types["TracerReady"] = "tracer-ready";
|
|
114
|
-
})(Types || (Types = {}));
|
|
115
|
-
var DebuggerMesssge;
|
|
116
|
-
(function (DebuggerMesssge) {
|
|
117
|
-
DebuggerMesssge["DEBUGGER_MESSAGE"] = "debugger-message";
|
|
118
|
-
DebuggerMesssge["DEBUGGER_MESSAGE_SDK"] = "debugger-message-sdk";
|
|
119
|
-
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH"] = "debugger-message-fetch";
|
|
120
|
-
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH_RESULT"] = "debugger-message-fetch-result";
|
|
121
|
-
DebuggerMesssge["DEBUGGER_MESSAGE_EVENT"] = "debugger-message-event";
|
|
122
|
-
DebuggerMesssge["DEVTOOL_WEB_READY"] = "devtool-web-ready";
|
|
123
|
-
})(DebuggerMesssge || (DebuggerMesssge = {}));
|
|
124
|
-
|
|
125
|
-
function createCommonjsModule(fn, module) {
|
|
126
|
-
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
var cookie = createCommonjsModule(function (module, exports) {
|
|
130
|
-
(function (factory) {
|
|
131
|
-
var registeredInModuleLoader;
|
|
132
|
-
{
|
|
133
|
-
module.exports = factory();
|
|
134
|
-
registeredInModuleLoader = true;
|
|
135
|
-
}
|
|
136
|
-
if (!registeredInModuleLoader) {
|
|
137
|
-
var OldCookies = window.Cookies;
|
|
138
|
-
var api = window.Cookies = factory();
|
|
139
|
-
api.noConflict = function () {
|
|
140
|
-
window.Cookies = OldCookies;
|
|
141
|
-
return api;
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
})(function () {
|
|
145
|
-
function extend() {
|
|
146
|
-
var i = 0;
|
|
147
|
-
var result = {};
|
|
148
|
-
for (; i < arguments.length; i++) {
|
|
149
|
-
var attributes = arguments[i];
|
|
150
|
-
for (var key in attributes) {
|
|
151
|
-
result[key] = attributes[key];
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return result;
|
|
155
|
-
}
|
|
156
|
-
function decode(s) {
|
|
157
|
-
return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
|
|
158
|
-
}
|
|
159
|
-
function init(converter) {
|
|
160
|
-
function api() {}
|
|
161
|
-
function set(key, value, attributes) {
|
|
162
|
-
if (typeof document === 'undefined') {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
attributes = extend({
|
|
166
|
-
path: '/'
|
|
167
|
-
}, api.defaults, attributes);
|
|
168
|
-
if (typeof attributes.expires === 'number') {
|
|
169
|
-
attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
|
|
170
|
-
}
|
|
171
|
-
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
|
|
172
|
-
try {
|
|
173
|
-
var result = JSON.stringify(value);
|
|
174
|
-
if (/^[\{\[]/.test(result)) {
|
|
175
|
-
value = result;
|
|
176
|
-
}
|
|
177
|
-
} catch (e) {}
|
|
178
|
-
value = converter.write ? converter.write(value, key) : encodeURIComponent(String(value)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
|
|
179
|
-
key = encodeURIComponent(String(key)).replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent).replace(/[\(\)]/g, escape);
|
|
180
|
-
var stringifiedAttributes = '';
|
|
181
|
-
for (var attributeName in attributes) {
|
|
182
|
-
if (!attributes[attributeName]) {
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
stringifiedAttributes += '; ' + attributeName;
|
|
186
|
-
if (attributes[attributeName] === true) {
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
|
190
|
-
}
|
|
191
|
-
return document.cookie = key + '=' + value + stringifiedAttributes;
|
|
192
|
-
}
|
|
193
|
-
function get(key, json) {
|
|
194
|
-
if (typeof document === 'undefined') {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
var jar = {};
|
|
198
|
-
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
|
199
|
-
var i = 0;
|
|
200
|
-
for (; i < cookies.length; i++) {
|
|
201
|
-
var parts = cookies[i].split('=');
|
|
202
|
-
var cookie = parts.slice(1).join('=');
|
|
203
|
-
if (!json && cookie.charAt(0) === '"') {
|
|
204
|
-
cookie = cookie.slice(1, -1);
|
|
205
|
-
}
|
|
206
|
-
try {
|
|
207
|
-
var name = decode(parts[0]);
|
|
208
|
-
cookie = (converter.read || converter)(cookie, name) || decode(cookie);
|
|
209
|
-
if (json) {
|
|
210
|
-
try {
|
|
211
|
-
cookie = JSON.parse(cookie);
|
|
212
|
-
} catch (e) {}
|
|
213
|
-
}
|
|
214
|
-
jar[name] = cookie;
|
|
215
|
-
if (key === name) {
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
} catch (e) {}
|
|
219
|
-
}
|
|
220
|
-
return key ? jar[key] : jar;
|
|
221
|
-
}
|
|
222
|
-
api.set = set;
|
|
223
|
-
api.get = function (key) {
|
|
224
|
-
return get(key, false );
|
|
225
|
-
};
|
|
226
|
-
api.getJSON = function (key) {
|
|
227
|
-
return get(key, true );
|
|
228
|
-
};
|
|
229
|
-
api.remove = function (key, attributes) {
|
|
230
|
-
set(key, '', extend(attributes, {
|
|
231
|
-
expires: -1
|
|
232
|
-
}));
|
|
233
|
-
};
|
|
234
|
-
api.defaults = {};
|
|
235
|
-
api.withConverter = init;
|
|
236
|
-
return api;
|
|
237
|
-
}
|
|
238
|
-
return init(function () {});
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
243
|
-
/**
|
|
244
|
-
* cacheStorage
|
|
245
|
-
*/
|
|
246
|
-
var Memory = /** @class */function () {
|
|
247
|
-
function Memory() {
|
|
248
|
-
this.cache = {};
|
|
249
|
-
}
|
|
250
|
-
Memory.prototype.setItem = function (cacheKey, data) {
|
|
251
|
-
this.cache[cacheKey] = data;
|
|
252
|
-
};
|
|
253
|
-
Memory.prototype.getItem = function (cacheKey) {
|
|
254
|
-
return this.cache[cacheKey];
|
|
255
|
-
};
|
|
256
|
-
Memory.prototype.removeItem = function (cacheKey) {
|
|
257
|
-
this.cache[cacheKey] = undefined;
|
|
258
|
-
};
|
|
259
|
-
return Memory;
|
|
260
|
-
}();
|
|
261
|
-
/**
|
|
262
|
-
* localStorage
|
|
263
|
-
*/
|
|
264
|
-
var Local = /** @class */function () {
|
|
265
|
-
function Local() {
|
|
266
|
-
this.support = this.isSupportLS();
|
|
267
|
-
}
|
|
268
|
-
Local.prototype.isSupportLS = function () {
|
|
269
|
-
try {
|
|
270
|
-
localStorage.setItem('_applogtest-test-key', 'hi');
|
|
271
|
-
localStorage.getItem('_applogtest-test-key');
|
|
272
|
-
localStorage.removeItem('_applogtest-test-key');
|
|
273
|
-
return true;
|
|
274
|
-
} catch (e) {
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
Local.prototype.getItem = function (key) {
|
|
279
|
-
try {
|
|
280
|
-
var value = localStorage.getItem(key);
|
|
281
|
-
var ret = value;
|
|
282
|
-
try {
|
|
283
|
-
if (value && typeof value === 'string') {
|
|
284
|
-
ret = JSON.parse(value);
|
|
285
|
-
}
|
|
286
|
-
} catch (e) {}
|
|
287
|
-
return ret || {};
|
|
288
|
-
} catch (e) {}
|
|
289
|
-
return {};
|
|
290
|
-
};
|
|
291
|
-
Local.prototype.setItem = function (key, value) {
|
|
292
|
-
try {
|
|
293
|
-
var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
294
|
-
localStorage.setItem(key, stringValue);
|
|
295
|
-
} catch (e) {}
|
|
296
|
-
};
|
|
297
|
-
Local.prototype.removeItem = function (key) {
|
|
298
|
-
try {
|
|
299
|
-
localStorage.removeItem(key);
|
|
300
|
-
} catch (e) {}
|
|
301
|
-
};
|
|
302
|
-
return Local;
|
|
303
|
-
}();
|
|
304
|
-
/**
|
|
305
|
-
* sessionStorage
|
|
306
|
-
*/
|
|
307
|
-
var Session = /** @class */function () {
|
|
308
|
-
function Session() {
|
|
309
|
-
this.support = this.isSupportSession();
|
|
310
|
-
}
|
|
311
|
-
Session.prototype.isSupportSession = function () {
|
|
312
|
-
try {
|
|
313
|
-
sessionStorage.setItem('_applogtest-test-key', 'hi');
|
|
314
|
-
sessionStorage.getItem('_applogtest-test-key');
|
|
315
|
-
sessionStorage.removeItem('_applogtest-test-key');
|
|
316
|
-
return true;
|
|
317
|
-
} catch (e) {
|
|
318
|
-
return false;
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
Session.prototype.getItem = function (key) {
|
|
322
|
-
try {
|
|
323
|
-
var value = sessionStorage.getItem(key);
|
|
324
|
-
var ret = value;
|
|
325
|
-
try {
|
|
326
|
-
if (value && typeof value === 'string') {
|
|
327
|
-
ret = JSON.parse(value);
|
|
328
|
-
}
|
|
329
|
-
} catch (e) {}
|
|
330
|
-
return ret || {};
|
|
331
|
-
} catch (e) {}
|
|
332
|
-
return {};
|
|
333
|
-
};
|
|
334
|
-
Session.prototype.setItem = function (key, value) {
|
|
335
|
-
try {
|
|
336
|
-
var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
337
|
-
sessionStorage.setItem(key, stringValue);
|
|
338
|
-
} catch (e) {}
|
|
339
|
-
};
|
|
340
|
-
Session.prototype.removeItem = function (key) {
|
|
341
|
-
try {
|
|
342
|
-
sessionStorage.removeItem(key);
|
|
343
|
-
} catch (e) {}
|
|
344
|
-
};
|
|
345
|
-
return Session;
|
|
346
|
-
}();
|
|
347
|
-
var StorageManager = /** @class */function () {
|
|
348
|
-
function StorageManager() {
|
|
349
|
-
this.defaultExpireTime = 7 * 1000 * 60 * 60 * 24;
|
|
350
|
-
this.local = new Local();
|
|
351
|
-
this.session = new Session();
|
|
352
|
-
this.cache = new Memory();
|
|
353
|
-
}
|
|
354
|
-
StorageManager.prototype.getLocalItem = function (key) {
|
|
355
|
-
return this.local.getItem(key);
|
|
356
|
-
};
|
|
357
|
-
StorageManager.prototype.setLocalItem = function (key, value) {
|
|
358
|
-
this.local.setItem(key, value);
|
|
359
|
-
};
|
|
360
|
-
StorageManager.prototype.removeLocalItem = function (key) {
|
|
361
|
-
this.local.removeItem(key);
|
|
362
|
-
};
|
|
363
|
-
StorageManager.prototype.getSessionItem = function (key) {
|
|
364
|
-
return this.session.getItem(key);
|
|
365
|
-
};
|
|
366
|
-
StorageManager.prototype.setSessionItem = function (key, value) {
|
|
367
|
-
this.session.setItem(key, value);
|
|
368
|
-
};
|
|
369
|
-
StorageManager.prototype.removeSessionItem = function (key) {
|
|
370
|
-
this.session.removeItem(key);
|
|
371
|
-
};
|
|
372
|
-
StorageManager.prototype.getCacheItem = function (key) {
|
|
373
|
-
return this.cache.getItem(key);
|
|
374
|
-
};
|
|
375
|
-
StorageManager.prototype.setCacheItem = function (key, value) {
|
|
376
|
-
this.cache.setItem(key, value);
|
|
377
|
-
};
|
|
378
|
-
StorageManager.prototype.removeCacheItem = function (key) {
|
|
379
|
-
this.cache.removeItem(key);
|
|
380
|
-
};
|
|
381
|
-
StorageManager.prototype.getCookie = function (key, domain) {
|
|
382
|
-
try {
|
|
383
|
-
// const _matches = Cookies.get(name, { domain: domain || document.domain })
|
|
384
|
-
var _matches = cookie.get(key);
|
|
385
|
-
return _matches;
|
|
386
|
-
} catch (e) {
|
|
387
|
-
return '';
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
StorageManager.prototype.setCookie = function (key, value, expiresTime, domain) {
|
|
391
|
-
if (expiresTime === void 0) {
|
|
392
|
-
expiresTime = this.defaultExpireTime;
|
|
393
|
-
}
|
|
394
|
-
try {
|
|
395
|
-
var _domain = domain || document.domain;
|
|
396
|
-
var timestamp = +new Date();
|
|
397
|
-
var furureTimestamp = timestamp + expiresTime;
|
|
398
|
-
cookie.set(key, value, {
|
|
399
|
-
expires: new Date(furureTimestamp),
|
|
400
|
-
path: '/',
|
|
401
|
-
domain: _domain
|
|
402
|
-
});
|
|
403
|
-
} catch (e) {}
|
|
404
|
-
};
|
|
405
|
-
StorageManager.prototype.removeCookie = function (key, domain) {
|
|
406
|
-
try {
|
|
407
|
-
cookie.remove(key, {
|
|
408
|
-
path: '/',
|
|
409
|
-
domain: domain || ''
|
|
410
|
-
});
|
|
411
|
-
} catch (e) {}
|
|
412
|
-
};
|
|
413
|
-
return StorageManager;
|
|
414
|
-
}();
|
|
415
|
-
|
|
416
|
-
var RuotePage = /** @class */function () {
|
|
417
|
-
function RuotePage() {
|
|
418
|
-
this.autotrack = false;
|
|
419
|
-
this.spa = false;
|
|
420
|
-
this.cache = {};
|
|
421
|
-
this.allowHash = false;
|
|
422
|
-
}
|
|
423
|
-
RuotePage.prototype.apply = function (collect, config) {
|
|
424
|
-
if (!config.spa && !config.autotrack) return;
|
|
425
|
-
var Types = collect.Types;
|
|
426
|
-
this.collect = collect;
|
|
427
|
-
this.config = config;
|
|
428
|
-
this.appid = config.app_id;
|
|
429
|
-
this.allowHash = config.allow_hash;
|
|
430
|
-
this.fncArray = new Map();
|
|
431
|
-
this.setKey();
|
|
432
|
-
this.setLocation();
|
|
433
|
-
this.hack();
|
|
434
|
-
this.init();
|
|
435
|
-
this.listener();
|
|
436
|
-
collect.emit(Types.RouteReady);
|
|
437
|
-
};
|
|
438
|
-
RuotePage.prototype.setKey = function () {
|
|
439
|
-
this.storage = new StorageManager();
|
|
440
|
-
this.cache_key = "__tea_cache_refer_" + this.appid;
|
|
441
|
-
this.cache = {
|
|
442
|
-
refer_key: '',
|
|
443
|
-
refer_title: document.title || location.pathname,
|
|
444
|
-
refer_manual_key: '',
|
|
445
|
-
routeChange: false
|
|
446
|
-
};
|
|
447
|
-
if (this.config.autotrack && typeof this.config.autotrack === 'object' && this.config.autotrack.page_manual_key) {
|
|
448
|
-
this.cache.refer_manual_key = this.config.autotrack.page_manual_key;
|
|
449
|
-
}
|
|
450
|
-
this.storage.setLocalItem(this.cache_key, this.cache);
|
|
451
|
-
};
|
|
452
|
-
RuotePage.prototype.hack = function () {
|
|
453
|
-
var _this = this;
|
|
454
|
-
var oldPushState = window.history.pushState;
|
|
455
|
-
history.pushState = function (state) {
|
|
456
|
-
var args = [];
|
|
457
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
458
|
-
args[_i - 1] = arguments[_i];
|
|
459
|
-
}
|
|
460
|
-
if (typeof history['onpushstate'] === 'function') {
|
|
461
|
-
history['onpushstate']({
|
|
462
|
-
state: state
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
var ret = oldPushState.call.apply(oldPushState, __spread([history, state], args));
|
|
466
|
-
if (_this.lastLocation === location.href) return;
|
|
467
|
-
var config = _this.getPopStateChangeEventData();
|
|
468
|
-
_this.setReferCache(_this.lastLocation);
|
|
469
|
-
_this.lastLocation = location.href;
|
|
470
|
-
_this.sendPv(config, 'pushState');
|
|
471
|
-
return ret;
|
|
472
|
-
};
|
|
473
|
-
var oldReplaceState = history.replaceState;
|
|
474
|
-
history.replaceState = function (state) {
|
|
475
|
-
var args = [];
|
|
476
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
477
|
-
args[_i - 1] = arguments[_i];
|
|
478
|
-
}
|
|
479
|
-
if (typeof history['onreplacestate'] === 'function') {
|
|
480
|
-
history['onreplacestate']({
|
|
481
|
-
state: state
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
var ret = oldReplaceState.call.apply(oldReplaceState, __spread([history, state], args));
|
|
485
|
-
if (_this.lastLocation === location.href) return;
|
|
486
|
-
var config = _this.getPopStateChangeEventData();
|
|
487
|
-
_this.setReferCache(_this.lastLocation);
|
|
488
|
-
_this.lastLocation = location.href;
|
|
489
|
-
_this.sendPv(config);
|
|
490
|
-
return ret;
|
|
491
|
-
};
|
|
492
|
-
};
|
|
493
|
-
RuotePage.prototype.setLocation = function () {
|
|
494
|
-
if (typeof window !== 'undefined') {
|
|
495
|
-
this.lastLocation = window.location.href;
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
RuotePage.prototype.getLocation = function () {
|
|
499
|
-
return this.lastLocation;
|
|
500
|
-
};
|
|
501
|
-
RuotePage.prototype.init = function () {
|
|
502
|
-
var config = this.getPopStateChangeEventData();
|
|
503
|
-
this.collect.emit('route-change', {
|
|
504
|
-
config: config,
|
|
505
|
-
init: true
|
|
506
|
-
});
|
|
507
|
-
};
|
|
508
|
-
RuotePage.prototype.listener = function () {
|
|
509
|
-
var _this = this;
|
|
510
|
-
var timeoutId = null;
|
|
511
|
-
var time = 10;
|
|
512
|
-
window.addEventListener('hashchange', function (e) {
|
|
513
|
-
if (_this.lastLocation === window.location.href) return;
|
|
514
|
-
clearTimeout(timeoutId);
|
|
515
|
-
if (_this.allowHash) {
|
|
516
|
-
// 如果允许hashTag,就执行回调函数
|
|
517
|
-
_this.setReferCache(_this.lastLocation);
|
|
518
|
-
_this.lastLocation = window.location.href;
|
|
519
|
-
var config = _this.getPopStateChangeEventData();
|
|
520
|
-
_this.sendPv(config);
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
window.addEventListener('popstate', function (e) {
|
|
524
|
-
if (_this.lastLocation === window.location.href) {
|
|
525
|
-
return;
|
|
526
|
-
}
|
|
527
|
-
timeoutId = setTimeout(function () {
|
|
528
|
-
_this.setReferCache(_this.lastLocation);
|
|
529
|
-
_this.lastLocation = window.location.href;
|
|
530
|
-
var config = _this.getPopStateChangeEventData();
|
|
531
|
-
_this.sendPv(config);
|
|
532
|
-
}, time);
|
|
533
|
-
});
|
|
534
|
-
};
|
|
535
|
-
RuotePage.prototype.getPopStateChangeEventData = function () {
|
|
536
|
-
var config = this.pageConfig();
|
|
537
|
-
config['is_back'] = 0;
|
|
538
|
-
return config;
|
|
539
|
-
};
|
|
540
|
-
RuotePage.prototype.pageConfig = function () {
|
|
541
|
-
try {
|
|
542
|
-
var cache_local = this.storage.getLocalItem(this.cache_key) || {};
|
|
543
|
-
var is_first_time = false;
|
|
544
|
-
var firstStatus = this.storage.getLocalItem("__tea_cache_first_" + this.appid);
|
|
545
|
-
if (firstStatus && firstStatus == 1) {
|
|
546
|
-
is_first_time = false;
|
|
547
|
-
} else {
|
|
548
|
-
is_first_time = true;
|
|
549
|
-
}
|
|
550
|
-
return {
|
|
551
|
-
is_html: 1,
|
|
552
|
-
url: location.href,
|
|
553
|
-
referrer: this.handleRefer(),
|
|
554
|
-
page_key: location.href,
|
|
555
|
-
refer_page_key: this.handleRefer(),
|
|
556
|
-
page_title: document.title || location.pathname,
|
|
557
|
-
page_manual_key: this.config.autotrack && this.config.autotrack.page_manual_key || '',
|
|
558
|
-
refer_page_manual_key: cache_local && cache_local.refer_manual_key || '',
|
|
559
|
-
refer_page_title: cache_local && cache_local.refer_title || '',
|
|
560
|
-
page_path: location.pathname,
|
|
561
|
-
page_host: location.host,
|
|
562
|
-
is_first_time: "" + is_first_time
|
|
563
|
-
};
|
|
564
|
-
} catch (e) {
|
|
565
|
-
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
566
|
-
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
567
|
-
info: '发生了异常',
|
|
568
|
-
level: 'error',
|
|
569
|
-
time: Date.now(),
|
|
570
|
-
data: e.message
|
|
571
|
-
});
|
|
572
|
-
return {};
|
|
573
|
-
}
|
|
574
|
-
};
|
|
575
|
-
RuotePage.prototype.sendPv = function (config, name) {
|
|
576
|
-
this.collect.emit('route-change', {
|
|
577
|
-
config: config,
|
|
578
|
-
init: false
|
|
579
|
-
});
|
|
580
|
-
};
|
|
581
|
-
RuotePage.prototype.handleRefer = function () {
|
|
582
|
-
var refer = '';
|
|
583
|
-
try {
|
|
584
|
-
var cache_local = this.storage.getLocalItem() || {};
|
|
585
|
-
if (cache_local.routeChange) {
|
|
586
|
-
// 已经发生路由变化
|
|
587
|
-
refer = cache_local.refer_key;
|
|
588
|
-
} else {
|
|
589
|
-
// 首页,用浏览器的refer
|
|
590
|
-
refer = this.collect.configManager.get('referrer');
|
|
591
|
-
}
|
|
592
|
-
} catch (e) {
|
|
593
|
-
refer = document.referrer;
|
|
594
|
-
}
|
|
595
|
-
return refer;
|
|
596
|
-
};
|
|
597
|
-
RuotePage.prototype.setReferCache = function (url) {
|
|
598
|
-
var cache_local = this.storage.getLocalItem(this.cache_key) || {};
|
|
599
|
-
cache_local.refer_key = url;
|
|
600
|
-
// 不再是第一次进入页面
|
|
601
|
-
cache_local.routeChange = true;
|
|
602
|
-
this.storage.setLocalItem(this.cache_key, cache_local);
|
|
603
|
-
};
|
|
604
|
-
return RuotePage;
|
|
605
|
-
}();
|
|
606
|
-
|
|
607
|
-
module.exports = RuotePage;
|
|
1
|
+
"use strict";function t(t,e,o){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var n=o.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}var e=function(t){return 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",t}({});var o=function(t,e){return t(e={exports:{}},e.exports),e.exports}(function(t,e){var o;o=function(){function t(){for(var t=0,e={};t<arguments.length;t++){var o=arguments[t];for(var n in o)e[n]=o[n]}return e}function e(t){return t.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function o(n){function i(){}function a(e,o,a){if("undefined"!=typeof document){"number"==typeof(a=t({path:"/"},i.defaults,a)).expires&&(a.expires=new Date(1*new Date+864e5*a.expires)),a.expires=a.expires?a.expires.toUTCString():"";try{var r=JSON.stringify(o);/^[\{\[]/.test(r)&&(o=r)}catch(t){}o=n.write?n.write(o,e):encodeURIComponent(String(o)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=encodeURIComponent(String(e)).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=e+"="+o+s}}function r(t,o){if("undefined"!=typeof document){for(var i={},a=document.cookie?document.cookie.split("; "):[],r=0;r<a.length;r++){var s=a[r].split("="),c=s.slice(1).join("=");o||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var h=e(s[0]);if(c=(n.read||n)(c,h)||e(c),o)try{c=JSON.parse(c)}catch(t){}if(i[h]=c,t===h)break}catch(t){}}return t?i[t]:i}}return i.set=a,i.get=function(t){return r(t,!1)},i.getJSON=function(t){return r(t,!0)},i.remove=function(e,o){a(e,"",t(o,{expires:-1}))},i.defaults={},i.withConverter=o,i}(function(){})},t.exports=o()}),n=function(){function e(){t(this,"cache",void 0),this.cache={}}var o=e.prototype;return o.setItem=function(t,e){this.cache[t]=e},o.getItem=function(t){return this.cache[t]},o.removeItem=function(t){this.cache[t]=void 0},e}(),i=function(){function e(){t(this,"support",void 0),this.support=this.isSupportLS()}var o=e.prototype;return o.isSupportLS=function(){try{return localStorage.setItem("_applogtest-test-key","hi"),localStorage.getItem("_applogtest-test-key"),localStorage.removeItem("_applogtest-test-key"),!0}catch(t){return!1}},o.getItem=function(t){try{var e=localStorage.getItem(t),o=e;try{e&&"string"==typeof e&&(o=JSON.parse(e))}catch(t){}return o||{}}catch(t){}return{}},o.setItem=function(t,e){try{var o="string"==typeof e?e:JSON.stringify(e);localStorage.setItem(t,o)}catch(t){}},o.removeItem=function(t){try{localStorage.removeItem(t)}catch(t){}},e}(),a=function(){function e(){t(this,"support",void 0),this.support=this.isSupportSession()}var o=e.prototype;return o.isSupportSession=function(){try{return sessionStorage.setItem("_applogtest-test-key","hi"),sessionStorage.getItem("_applogtest-test-key"),sessionStorage.removeItem("_applogtest-test-key"),!0}catch(t){return!1}},o.getItem=function(t){try{var e=sessionStorage.getItem(t),o=e;try{e&&"string"==typeof e&&(o=JSON.parse(e))}catch(t){}return o||{}}catch(t){}return{}},o.setItem=function(t,e){try{var o="string"==typeof e?e:JSON.stringify(e);sessionStorage.setItem(t,o)}catch(t){}},o.removeItem=function(t){try{sessionStorage.removeItem(t)}catch(t){}},e}(),r=function(){function e(){t(this,"local",void 0),t(this,"session",void 0),t(this,"cache",void 0),t(this,"defaultExpireTime",void 0),this.defaultExpireTime=6048e5,this.local=new i,this.session=new a,this.cache=new n}var r=e.prototype;return r.getLocalItem=function(t){return this.local.getItem(t)},r.setLocalItem=function(t,e){this.local.setItem(t,e)},r.removeLocalItem=function(t){this.local.removeItem(t)},r.getSessionItem=function(t){return this.session.getItem(t)},r.setSessionItem=function(t,e){this.session.setItem(t,e)},r.removeSessionItem=function(t){this.session.removeItem(t)},r.getCacheItem=function(t){return this.cache.getItem(t)},r.setCacheItem=function(t,e){this.cache.setItem(t,e)},r.removeCacheItem=function(t){this.cache.removeItem(t)},r.getCookie=function(t,e){try{return o.get(t)}catch(t){return""}},r.setCookie=function(t,e,n,i){void 0===n&&(n=this.defaultExpireTime);try{var a=i||document.domain,r=+new Date+n;o.set(t,e,{expires:new Date(r),path:"/",domain:a})}catch(t){}},r.removeCookie=function(t,e){try{o.remove(t,{path:"/",domain:e||""})}catch(t){}},e}(),s=function(){function o(){t(this,"storage",void 0),t(this,"lastLocation",void 0),t(this,"autotrack",!1),t(this,"spa",!1),t(this,"fncArray",void 0),t(this,"collect",void 0),t(this,"config",void 0),t(this,"cache_key",void 0),t(this,"cache",{}),t(this,"appid",void 0),t(this,"allowHash",!1)}var n=o.prototype;return n.apply=function(t,e){if(e.spa||e.autotrack){var o=t.Types;this.collect=t,this.config=e,this.appid=e.app_id,this.allowHash=e.allow_hash,this.fncArray=new Map,this.setKey(),this.setLocation(),this.hack(),this.init(),this.listener(),t.emit(o.RouteReady)}},n.setKey=function(){this.storage=new r,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)},n.hack=function(){var t=this,e=window.history.pushState;history.pushState=function(o){"function"==typeof history.onpushstate&&history.onpushstate({state:o});for(var n=arguments.length,i=new Array(n>1?n-1:0),a=1;a<n;a++)i[a-1]=arguments[a];var r=e.call.apply(e,[history,o].concat(i));if(t.lastLocation!==location.href){var s=t.getPopStateChangeEventData();return t.setReferCache(t.lastLocation),t.lastLocation=location.href,t.sendPv(s,"pushState"),r}};var o=history.replaceState;history.replaceState=function(e){"function"==typeof history.onreplacestate&&history.onreplacestate({state:e});for(var n=arguments.length,i=new Array(n>1?n-1:0),a=1;a<n;a++)i[a-1]=arguments[a];var r=o.call.apply(o,[history,e].concat(i));if(t.lastLocation!==location.href){var s=t.getPopStateChangeEventData();return t.setReferCache(t.lastLocation),t.lastLocation=location.href,t.sendPv(s),r}}},n.setLocation=function(){"undefined"!=typeof window&&(this.lastLocation=window.location.href)},n.getLocation=function(){return this.lastLocation},n.init=function(){var t=this.getPopStateChangeEventData();this.collect.emit("route-change",{config:t,init:!0})},n.listener=function(){var t=this,e=null;window.addEventListener("hashchange",function(o){if(t.lastLocation!==window.location.href&&(clearTimeout(e),t.allowHash)){t.setReferCache(t.lastLocation),t.lastLocation=window.location.href;var n=t.getPopStateChangeEventData();t.sendPv(n)}}),window.addEventListener("popstate",function(o){t.lastLocation!==window.location.href&&(e=setTimeout(function(){t.setReferCache(t.lastLocation),t.lastLocation=window.location.href;var e=t.getPopStateChangeEventData();t.sendPv(e)},10))})},n.getPopStateChangeEventData=function(){var t=this.pageConfig();return t.is_back=0,t},n.pageConfig=function(){try{var t=this.storage.getLocalItem(this.cache_key)||{},o=!1,n=this.storage.getLocalItem("__tea_cache_first_"+this.appid);return o=!n||1!=n,{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:t&&t.refer_manual_key||"",refer_page_title:t&&t.refer_title||"",page_path:location.pathname,page_host:location.host,is_first_time:""+o}}catch(t){return this.collect.emit(e.DEBUGGER_MESSAGE,{type:e.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:t.message}),{}}},n.sendPv=function(t,e){this.collect.emit("route-change",{config:t,init:!1})},n.handleRefer=function(){var t="";try{var e=this.storage.getLocalItem()||{};t=e.routeChange?e.refer_key:this.collect.configManager.get("referrer")}catch(e){t=document.referrer}return t},n.setReferCache=function(t){var e=this.storage.getLocalItem(this.cache_key)||{};e.refer_key=t,e.routeChange=!0,this.storage.setLocalItem(this.cache_key,e)},o}();module.exports=s;
|