hina-cloud-js-sdk 3.1.7 → 3.1.8
Sign up to get free protection for your applications and to get access to all the features.
- package/.gitlab-ci.yml +2 -6
- package/build/hina.cjs.min.js +1 -0
- package/build/hina.esm.min.js +1 -1
- package/build/hina.min.js +1 -4
- package/build/hotAnalyse.min.js +1 -1
- package/package.json +2 -7
- package/packages/core/dist/index.cjs.js +64 -0
- package/packages/core/dist/index.cjs.js.map +1 -0
- package/packages/core/dist/index.d.ts +45 -0
- package/packages/core/dist/index.esm.js +62 -0
- package/packages/core/dist/index.esm.js.map +1 -0
- package/packages/core/dist/index.global.js +1199 -0
- package/packages/core/dist/index.global.js.map +1 -0
- package/packages/core/dist/index.js +1200 -0
- package/packages/core/dist/index.js.map +1 -0
- package/packages/monitor/dist/index.cjs.js +150 -0
- package/packages/monitor/dist/index.cjs.js.map +1 -0
- package/packages/monitor/dist/index.d.ts +35 -0
- package/packages/monitor/dist/index.esm.js +145 -0
- package/packages/monitor/dist/index.esm.js.map +1 -0
- package/packages/monitor/dist/index.global.js +1343 -0
- package/packages/monitor/dist/index.global.js.map +1 -0
- package/packages/monitor/dist/index.js +1344 -0
- package/packages/monitor/dist/index.js.map +1 -0
- package/packages/track/dist/index.cjs.js +1930 -0
- package/packages/track/dist/index.cjs.js.map +1 -0
- package/packages/track/dist/index.d.ts +212 -0
- package/packages/track/dist/index.esm.js +1925 -0
- package/packages/track/dist/index.esm.js.map +1 -0
- package/packages/track/dist/index.global.js +4259 -0
- package/packages/track/dist/index.global.js.map +1 -0
- package/packages/track/dist/index.js +4260 -0
- package/packages/track/dist/index.js.map +1 -0
- package/packages/types/dist/index.d.ts +603 -0
- package/packages/types/dist/index.esm.js +25 -0
- package/packages/types/dist/index.esm.js.map +1 -0
- package/packages/utils/dist/index.cjs.js +1535 -0
- package/packages/utils/dist/index.cjs.js.map +1 -0
- package/packages/utils/dist/index.d.ts +394 -0
- package/packages/utils/dist/index.esm.js +1465 -0
- package/packages/utils/dist/index.esm.js.map +1 -0
- package/packages/utils/dist/index.global.js +2507 -0
- package/packages/utils/dist/index.global.js.map +1 -0
- package/packages/utils/dist/index.js +2508 -0
- package/packages/utils/dist/index.js.map +1 -0
@@ -0,0 +1,1535 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var UAParser = require('ua-parser-js');
|
4
|
+
var hinaCloudTypes = require('hina-cloud-types');
|
5
|
+
|
6
|
+
var MAX_REFERRER_STRING_LENGTH = 2000;
|
7
|
+
var MAX_STRING_LENGTH = 1024 * 4;
|
8
|
+
var PV_LIB_VERSION = '4.0.0';
|
9
|
+
var EPM_LIB_VERSION = '1.0.0';
|
10
|
+
var COOKIE_TEST_NAME = 'hinasdk_domain_test';
|
11
|
+
var utmTypes = [
|
12
|
+
'utm_source',
|
13
|
+
'utm_medium',
|
14
|
+
'utm_campaign',
|
15
|
+
'utm_content',
|
16
|
+
'utm_term'
|
17
|
+
];
|
18
|
+
var searchTypes = [
|
19
|
+
'www.baidu.',
|
20
|
+
'm.baidu.',
|
21
|
+
'm.sm.cn',
|
22
|
+
'so.com',
|
23
|
+
'sogou.com',
|
24
|
+
'youdao.com',
|
25
|
+
'google.',
|
26
|
+
'yahoo.com/',
|
27
|
+
'bing.com/',
|
28
|
+
'ask.com/'
|
29
|
+
];
|
30
|
+
var socialTypes = [
|
31
|
+
'weibo.com',
|
32
|
+
'renren.com',
|
33
|
+
'kaixin001.com',
|
34
|
+
'douban.com',
|
35
|
+
'qzone.qq.com',
|
36
|
+
'zhihu.com',
|
37
|
+
'tieba.baidu.com',
|
38
|
+
'weixin.qq.com'
|
39
|
+
];
|
40
|
+
var searchKeywords = {
|
41
|
+
baidu: ['wd', 'word', 'kw', 'keyword'],
|
42
|
+
google: 'q',
|
43
|
+
bing: 'q',
|
44
|
+
yahoo: 'p',
|
45
|
+
sogou: ['query', 'keyword'],
|
46
|
+
so: 'q',
|
47
|
+
sm: 'q'
|
48
|
+
};
|
49
|
+
|
50
|
+
var toString = Object.prototype.toString;
|
51
|
+
function isObject(val) {
|
52
|
+
return Object.prototype.toString.call(val) === '[object Object]';
|
53
|
+
}
|
54
|
+
function isUndefined(val) {
|
55
|
+
return val === void 0;
|
56
|
+
}
|
57
|
+
function isValid(val) {
|
58
|
+
return val !== null && val !== undefined;
|
59
|
+
}
|
60
|
+
function isArray(val) {
|
61
|
+
return Array.isArray(val);
|
62
|
+
}
|
63
|
+
function isDate(val) {
|
64
|
+
return toString.call(val) === '[object Date]';
|
65
|
+
}
|
66
|
+
function isFunction(val) {
|
67
|
+
return typeof val === 'function';
|
68
|
+
}
|
69
|
+
function isString(val) {
|
70
|
+
return typeof val === 'string';
|
71
|
+
}
|
72
|
+
function isNumber(val) {
|
73
|
+
return typeof val === 'number';
|
74
|
+
}
|
75
|
+
function isBoolean(val) {
|
76
|
+
return typeof val === 'boolean';
|
77
|
+
}
|
78
|
+
function noop() { }
|
79
|
+
function isJSONString(val) {
|
80
|
+
try {
|
81
|
+
JSON.parse(val);
|
82
|
+
}
|
83
|
+
catch (e) {
|
84
|
+
return false;
|
85
|
+
}
|
86
|
+
return true;
|
87
|
+
}
|
88
|
+
function safeJSONParse(val) {
|
89
|
+
try {
|
90
|
+
return JSON.parse(val);
|
91
|
+
}
|
92
|
+
catch (e) { }
|
93
|
+
return val;
|
94
|
+
}
|
95
|
+
function isEmptyObject(obj) {
|
96
|
+
return Object.keys(obj).length === 0;
|
97
|
+
}
|
98
|
+
function nowStamp() {
|
99
|
+
if (Date.now && isFunction(Date.now)) {
|
100
|
+
return Date.now();
|
101
|
+
}
|
102
|
+
return new Date().getTime();
|
103
|
+
}
|
104
|
+
function merge() {
|
105
|
+
var args = [];
|
106
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
107
|
+
args[_i] = arguments[_i];
|
108
|
+
}
|
109
|
+
var result = Object.create(null);
|
110
|
+
args.forEach(function (obj) {
|
111
|
+
if (obj) {
|
112
|
+
Object.keys(obj).forEach(function (key) {
|
113
|
+
var val = obj[key];
|
114
|
+
if (isObject(val)) {
|
115
|
+
if (isObject(result[key])) {
|
116
|
+
result[key] = merge(result[key], val);
|
117
|
+
}
|
118
|
+
else {
|
119
|
+
result[key] = merge(val);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
else {
|
123
|
+
result[key] = val;
|
124
|
+
}
|
125
|
+
});
|
126
|
+
}
|
127
|
+
});
|
128
|
+
return result;
|
129
|
+
}
|
130
|
+
function stripEmptyProperties(obj) {
|
131
|
+
return Object.keys(obj).reduce(function (acc, key) {
|
132
|
+
if (isValid(obj[key]) && obj[key] !== '') {
|
133
|
+
acc[key] = obj[key];
|
134
|
+
}
|
135
|
+
return acc;
|
136
|
+
}, {});
|
137
|
+
}
|
138
|
+
/**
|
139
|
+
* 返回URL对象
|
140
|
+
* @param url
|
141
|
+
*/
|
142
|
+
function getURL(url) {
|
143
|
+
var urlObj = {};
|
144
|
+
try {
|
145
|
+
urlObj = new URL(url);
|
146
|
+
}
|
147
|
+
catch (e) { }
|
148
|
+
return urlObj;
|
149
|
+
}
|
150
|
+
/**
|
151
|
+
* 获取URL上的search参数
|
152
|
+
* @param queryString
|
153
|
+
*/
|
154
|
+
function getURLSearchParams(queryString) {
|
155
|
+
queryString = queryString || '';
|
156
|
+
var args = {};
|
157
|
+
var searchParams = new URLSearchParams(queryString);
|
158
|
+
searchParams.forEach(function (value, key) {
|
159
|
+
args[key] = value;
|
160
|
+
});
|
161
|
+
return args;
|
162
|
+
}
|
163
|
+
function formatDecimal(num, decimal) {
|
164
|
+
if (decimal === void 0) { decimal = 3; }
|
165
|
+
if (!num) {
|
166
|
+
return num;
|
167
|
+
}
|
168
|
+
var str = num.toString();
|
169
|
+
var index = str.indexOf('.');
|
170
|
+
if (index !== -1) {
|
171
|
+
str = str.substring(0, index + decimal + 1);
|
172
|
+
}
|
173
|
+
else {
|
174
|
+
str = str.substring(0);
|
175
|
+
}
|
176
|
+
return parseFloat(str);
|
177
|
+
}
|
178
|
+
/**
|
179
|
+
* 获取cookie顶级域名
|
180
|
+
* @param hostname
|
181
|
+
*/
|
182
|
+
function getCookieTopLevelDomain(hostname) {
|
183
|
+
hostname = hostname || window.location.hostname;
|
184
|
+
if (!/^[a-zA-Z0-9\u4e00-\u9fa5\-\\.]+$/.exec(hostname)) {
|
185
|
+
hostname = '';
|
186
|
+
}
|
187
|
+
var splitResult = hostname.split('.');
|
188
|
+
if (splitResult.length >= 2 && !/^(\d+\.)+\d+$/.test(hostname)) {
|
189
|
+
var domainStr = ".".concat(splitResult.splice(splitResult.length - 1, 1));
|
190
|
+
while (splitResult.length > 0) {
|
191
|
+
domainStr = ".".concat(splitResult.splice(splitResult.length - 1, 1)).concat(domainStr);
|
192
|
+
document.cookie = "".concat(COOKIE_TEST_NAME, "=true; path=/; domain=").concat(domainStr);
|
193
|
+
if (document.cookie.indexOf("".concat(COOKIE_TEST_NAME, "=true")) !== -1) {
|
194
|
+
document.cookie = "".concat(COOKIE_TEST_NAME, "=true; path=/; domain=").concat(domainStr, "; max-age=0");
|
195
|
+
return domainStr;
|
196
|
+
}
|
197
|
+
}
|
198
|
+
}
|
199
|
+
return '';
|
200
|
+
}
|
201
|
+
/**
|
202
|
+
* 获取当前页面的domain
|
203
|
+
* 注意这里的domain,并不是普通的window.location.hostname值,而是拥有相同子域名的域名,因为浏览器的cookie是二级域名共享的
|
204
|
+
*/
|
205
|
+
function getCurrentDomain() {
|
206
|
+
var cookieDomain = getCookieTopLevelDomain();
|
207
|
+
if (cookieDomain === '') {
|
208
|
+
return 'url解析失败';
|
209
|
+
}
|
210
|
+
return cookieDomain;
|
211
|
+
}
|
212
|
+
/**
|
213
|
+
* 获取当前页面的referrer
|
214
|
+
*/
|
215
|
+
function getReferrer(value) {
|
216
|
+
var referrer = value || document.referrer;
|
217
|
+
if (typeof referrer !== 'string') {
|
218
|
+
return "referrer exception".concat(String(referrer));
|
219
|
+
}
|
220
|
+
if (referrer.startsWith('https://www.baidu.com/')) {
|
221
|
+
referrer = referrer.split('?')[0];
|
222
|
+
}
|
223
|
+
referrer = referrer.slice(0, MAX_REFERRER_STRING_LENGTH);
|
224
|
+
return typeof referrer === 'string' ? referrer : '';
|
225
|
+
}
|
226
|
+
/**
|
227
|
+
* 获取hostname
|
228
|
+
* @param url
|
229
|
+
* @param defaultValue
|
230
|
+
*/
|
231
|
+
function getHostname(url, defaultValue) {
|
232
|
+
if (!defaultValue || typeof defaultValue !== 'string') {
|
233
|
+
defaultValue = 'hostname解析异常';
|
234
|
+
}
|
235
|
+
if (!url) {
|
236
|
+
return defaultValue;
|
237
|
+
}
|
238
|
+
var hostname = getURL(url).hostname || '';
|
239
|
+
return hostname || defaultValue;
|
240
|
+
}
|
241
|
+
/**
|
242
|
+
* 此函数有两个作用
|
243
|
+
* 1:referrer为空时,直接返回true
|
244
|
+
* 2:referrer不为空时,判断是否是外链流量 document.referrer对应的hostname是否和当前URL的hostname是否相同
|
245
|
+
* @param referrer
|
246
|
+
*/
|
247
|
+
function isReferralTraffic(referrer) {
|
248
|
+
referrer = referrer || document.referrer;
|
249
|
+
if (referrer === '') {
|
250
|
+
return true;
|
251
|
+
}
|
252
|
+
return (getCookieTopLevelDomain(getHostname(referrer)) !== getCookieTopLevelDomain());
|
253
|
+
}
|
254
|
+
/**
|
255
|
+
* 获取浏览器scrollTop
|
256
|
+
*/
|
257
|
+
function getScrollTop() {
|
258
|
+
return document.documentElement.scrollTop || document.body.scrollTop || 0;
|
259
|
+
}
|
260
|
+
/**
|
261
|
+
* 获取浏览器scrollLeft
|
262
|
+
*/
|
263
|
+
function getScrollLeft() {
|
264
|
+
return document.documentElement.scrollLeft || document.body.scrollLeft || 0;
|
265
|
+
}
|
266
|
+
/**
|
267
|
+
* 获取浏览器可视高度
|
268
|
+
*/
|
269
|
+
function getScreenHeight() {
|
270
|
+
return (window.innerHeight ||
|
271
|
+
document.documentElement.clientHeight ||
|
272
|
+
document.body.clientHeight ||
|
273
|
+
0);
|
274
|
+
}
|
275
|
+
/**
|
276
|
+
* 获取浏览器可视宽度
|
277
|
+
*/
|
278
|
+
function getScreenWidth() {
|
279
|
+
return (window.innerWidth ||
|
280
|
+
document.documentElement.clientWidth ||
|
281
|
+
document.body.clientWidth ||
|
282
|
+
0);
|
283
|
+
}
|
284
|
+
/**
|
285
|
+
* 获取浏览器网络类型
|
286
|
+
*/
|
287
|
+
function networkType() {
|
288
|
+
if (navigator.connection === undefined)
|
289
|
+
return 'unknown';
|
290
|
+
var connection = navigator.connection;
|
291
|
+
if (connection.effectiveType) {
|
292
|
+
return connection.effectiveType;
|
293
|
+
}
|
294
|
+
if (connection.type) {
|
295
|
+
return connection.type;
|
296
|
+
}
|
297
|
+
return '取值异常';
|
298
|
+
}
|
299
|
+
/**
|
300
|
+
* 生成随机数
|
301
|
+
*/
|
302
|
+
function getRandom() {
|
303
|
+
var date = new Date();
|
304
|
+
var seed = date.getTime();
|
305
|
+
var num = Math.floor(Math.random() * 1000000);
|
306
|
+
return "".concat(seed, "_").concat(num);
|
307
|
+
}
|
308
|
+
var ListenPageState = /** @class */ (function () {
|
309
|
+
function ListenPageState(payload) {
|
310
|
+
this.visibleHandler = function () { };
|
311
|
+
this.hiddenHandler = function () { };
|
312
|
+
var visible = payload.visible, hidden = payload.hidden;
|
313
|
+
if (isFunction(visible)) {
|
314
|
+
this.visibleHandler = visible;
|
315
|
+
}
|
316
|
+
if (isFunction(hidden)) {
|
317
|
+
this.hiddenHandler = hidden;
|
318
|
+
}
|
319
|
+
this.init();
|
320
|
+
}
|
321
|
+
ListenPageState.prototype.isSupport = function () {
|
322
|
+
return typeof document.hidden !== 'undefined';
|
323
|
+
};
|
324
|
+
ListenPageState.prototype.init = function () {
|
325
|
+
var _this = this;
|
326
|
+
if (this.isSupport()) {
|
327
|
+
document.addEventListener('visibilitychange', function () {
|
328
|
+
if (document.hidden) {
|
329
|
+
_this.hiddenHandler();
|
330
|
+
}
|
331
|
+
else {
|
332
|
+
_this.visibleHandler();
|
333
|
+
}
|
334
|
+
});
|
335
|
+
}
|
336
|
+
else {
|
337
|
+
window.addEventListener('focus', this.visibleHandler);
|
338
|
+
window.addEventListener('blur', this.hiddenHandler);
|
339
|
+
}
|
340
|
+
};
|
341
|
+
return ListenPageState;
|
342
|
+
}());
|
343
|
+
function generatorUUID() {
|
344
|
+
var T = function () {
|
345
|
+
var d = nowStamp();
|
346
|
+
var i = 0;
|
347
|
+
while (d === nowStamp()) {
|
348
|
+
i++;
|
349
|
+
}
|
350
|
+
return d.toString(16) + i.toString(16);
|
351
|
+
};
|
352
|
+
var R = function () {
|
353
|
+
return Math.random().toString(16).replace('.', '');
|
354
|
+
};
|
355
|
+
var UA = function () {
|
356
|
+
var ua = navigator.userAgent;
|
357
|
+
var i;
|
358
|
+
var ch;
|
359
|
+
var buffer = [];
|
360
|
+
var ret = 0;
|
361
|
+
function xor(result, byteArray) {
|
362
|
+
var j;
|
363
|
+
var tmp = 0;
|
364
|
+
for (j = 0; j < byteArray.length; j++) {
|
365
|
+
tmp |= buffer[j] << (j * 8);
|
366
|
+
}
|
367
|
+
return result ^ tmp;
|
368
|
+
}
|
369
|
+
for (i = 0; i < ua.length; i++) {
|
370
|
+
ch = ua.charCodeAt(i);
|
371
|
+
buffer.unshift(ch & 0xff);
|
372
|
+
if (buffer.length >= 4) {
|
373
|
+
ret = xor(ret, buffer);
|
374
|
+
buffer = [];
|
375
|
+
}
|
376
|
+
}
|
377
|
+
if (buffer.length > 0) {
|
378
|
+
ret = xor(ret, buffer);
|
379
|
+
}
|
380
|
+
return ret.toString(16);
|
381
|
+
};
|
382
|
+
var se = String(window.screen.height * window.screen.width);
|
383
|
+
if (se && /\d{5,}/.test(se)) {
|
384
|
+
// @ts-ignore
|
385
|
+
se = se.toString(16);
|
386
|
+
}
|
387
|
+
else {
|
388
|
+
se = String(Math.random() * 31242)
|
389
|
+
.replace('.', '')
|
390
|
+
.slice(0, 8);
|
391
|
+
}
|
392
|
+
var val = "".concat(T(), "-").concat(R(), "-").concat(UA(), "-").concat(se, "-").concat(T());
|
393
|
+
if (val) {
|
394
|
+
return val;
|
395
|
+
}
|
396
|
+
return (String(Math.random()) +
|
397
|
+
String(Math.random()) +
|
398
|
+
String(Math.random())).slice(2, 15);
|
399
|
+
}
|
400
|
+
/**
|
401
|
+
* 查找指定url中的参数
|
402
|
+
* replace(/[\[]/, "\\[") 将 [ 替换为 \[。
|
403
|
+
* replace(/[\]]/, "\\]") 将 ] 替换为 \]。
|
404
|
+
* example[123]=>example\[123\]
|
405
|
+
* @param url
|
406
|
+
* @param key
|
407
|
+
*/
|
408
|
+
function getQueryParam(url, key) {
|
409
|
+
key = key.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
410
|
+
url = decodeURIComponent(url);
|
411
|
+
var regex = new RegExp("[\\?&]".concat(key, "=([^&#]*)"));
|
412
|
+
var results = regex.exec(url);
|
413
|
+
if (results === null ||
|
414
|
+
(results && typeof results[1] !== 'string' && results[1].length)) {
|
415
|
+
return '';
|
416
|
+
}
|
417
|
+
return decodeURIComponent(results[1]);
|
418
|
+
}
|
419
|
+
function base64Encode(str) {
|
420
|
+
try {
|
421
|
+
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (e, t) {
|
422
|
+
return String.fromCharCode(Number("0x".concat(t)));
|
423
|
+
}));
|
424
|
+
}
|
425
|
+
catch (e) {
|
426
|
+
return str;
|
427
|
+
}
|
428
|
+
}
|
429
|
+
function base64Decode(str) {
|
430
|
+
var result = [];
|
431
|
+
try {
|
432
|
+
result = atob(str)
|
433
|
+
.split('')
|
434
|
+
.map(function (v) {
|
435
|
+
return "%".concat("00".concat(v.charCodeAt(0).toString(16)).slice(-2));
|
436
|
+
});
|
437
|
+
}
|
438
|
+
catch (e) {
|
439
|
+
result = [];
|
440
|
+
}
|
441
|
+
try {
|
442
|
+
return decodeURIComponent(result.join(''));
|
443
|
+
}
|
444
|
+
catch (e) {
|
445
|
+
return result.join('');
|
446
|
+
}
|
447
|
+
}
|
448
|
+
function handleDecodeURLComponent(val) {
|
449
|
+
var result = val;
|
450
|
+
try {
|
451
|
+
result = decodeURIComponent(val);
|
452
|
+
}
|
453
|
+
catch (e) { }
|
454
|
+
return result;
|
455
|
+
}
|
456
|
+
function handleEncodeURLComponent(val) {
|
457
|
+
var result = val;
|
458
|
+
try {
|
459
|
+
result = encodeURIComponent(val);
|
460
|
+
}
|
461
|
+
catch (e) { }
|
462
|
+
return result;
|
463
|
+
}
|
464
|
+
/**
|
465
|
+
* 对原生方法进行重写
|
466
|
+
* @param source 需要被重写的对象
|
467
|
+
* @param name 重写方法名
|
468
|
+
* @param replacement 重写方法
|
469
|
+
* @param isForced 是否强制重写(可能原先没有该属性)
|
470
|
+
*/
|
471
|
+
function replaceOld(source, name, replacement, isForced) {
|
472
|
+
if (source === undefined)
|
473
|
+
return;
|
474
|
+
if (name in source || isForced) {
|
475
|
+
var original = source[name];
|
476
|
+
var wrapped = replacement(original);
|
477
|
+
if (isFunction(wrapped)) {
|
478
|
+
source[name] = wrapped;
|
479
|
+
}
|
480
|
+
}
|
481
|
+
}
|
482
|
+
function supportHistory() {
|
483
|
+
return window && !!window.history.pushState && !!window.history.replaceState;
|
484
|
+
}
|
485
|
+
|
486
|
+
/******************************************************************************
|
487
|
+
Copyright (c) Microsoft Corporation.
|
488
|
+
|
489
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
490
|
+
purpose with or without fee is hereby granted.
|
491
|
+
|
492
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
493
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
494
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
495
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
496
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
497
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
498
|
+
PERFORMANCE OF THIS SOFTWARE.
|
499
|
+
***************************************************************************** */
|
500
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
501
|
+
|
502
|
+
var extendStatics = function(d, b) {
|
503
|
+
extendStatics = Object.setPrototypeOf ||
|
504
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
505
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
506
|
+
return extendStatics(d, b);
|
507
|
+
};
|
508
|
+
|
509
|
+
function __extends(d, b) {
|
510
|
+
if (typeof b !== "function" && b !== null)
|
511
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
512
|
+
extendStatics(d, b);
|
513
|
+
function __() { this.constructor = d; }
|
514
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
515
|
+
}
|
516
|
+
|
517
|
+
function __values(o) {
|
518
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
519
|
+
if (m) return m.call(o);
|
520
|
+
if (o && typeof o.length === "number") return {
|
521
|
+
next: function () {
|
522
|
+
if (o && i >= o.length) o = void 0;
|
523
|
+
return { value: o && o[i++], done: !o };
|
524
|
+
}
|
525
|
+
};
|
526
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
527
|
+
}
|
528
|
+
|
529
|
+
function __read(o, n) {
|
530
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
531
|
+
if (!m) return o;
|
532
|
+
var i = m.call(o), r, ar = [], e;
|
533
|
+
try {
|
534
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
535
|
+
}
|
536
|
+
catch (error) { e = { error: error }; }
|
537
|
+
finally {
|
538
|
+
try {
|
539
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
540
|
+
}
|
541
|
+
finally { if (e) throw e.error; }
|
542
|
+
}
|
543
|
+
return ar;
|
544
|
+
}
|
545
|
+
|
546
|
+
function __spreadArray(to, from, pack) {
|
547
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
548
|
+
if (ar || !(i in from)) {
|
549
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
550
|
+
ar[i] = from[i];
|
551
|
+
}
|
552
|
+
}
|
553
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
554
|
+
}
|
555
|
+
|
556
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
557
|
+
var e = new Error(message);
|
558
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
559
|
+
};
|
560
|
+
|
561
|
+
/**
|
562
|
+
* cookie 操作
|
563
|
+
*/
|
564
|
+
var CookieStorage = /** @class */ (function () {
|
565
|
+
function CookieStorage() {
|
566
|
+
this.name = 'CookieStorage';
|
567
|
+
}
|
568
|
+
/**
|
569
|
+
* 用于判断是否支持cookie
|
570
|
+
* @param testKey
|
571
|
+
* @param testValue
|
572
|
+
*/
|
573
|
+
CookieStorage.prototype.isSupport = function (testKey, testValue) {
|
574
|
+
var _this = this;
|
575
|
+
if (testKey === void 0) { testKey = 'cookie_support_test'; }
|
576
|
+
if (testValue === void 0) { testValue = '1'; }
|
577
|
+
var test = function () {
|
578
|
+
_this.set(testKey, testValue);
|
579
|
+
var value = _this.get(testKey);
|
580
|
+
if (value !== testValue)
|
581
|
+
return false;
|
582
|
+
_this.remove(testKey);
|
583
|
+
return true;
|
584
|
+
};
|
585
|
+
return navigator.cookieEnabled && test();
|
586
|
+
};
|
587
|
+
/**
|
588
|
+
* 获取指定的cookie值
|
589
|
+
* @param name
|
590
|
+
*/
|
591
|
+
CookieStorage.prototype.get = function (name) {
|
592
|
+
var e_1, _a;
|
593
|
+
var cookieList = document.cookie.split(';');
|
594
|
+
try {
|
595
|
+
for (var cookieList_1 = __values(cookieList), cookieList_1_1 = cookieList_1.next(); !cookieList_1_1.done; cookieList_1_1 = cookieList_1.next()) {
|
596
|
+
var cookie = cookieList_1_1.value;
|
597
|
+
var cookiePair = cookie.split('=');
|
598
|
+
if (cookiePair[0].trim() === name) {
|
599
|
+
return decodeURIComponent(cookiePair[1]);
|
600
|
+
}
|
601
|
+
}
|
602
|
+
}
|
603
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
604
|
+
finally {
|
605
|
+
try {
|
606
|
+
if (cookieList_1_1 && !cookieList_1_1.done && (_a = cookieList_1.return)) _a.call(cookieList_1);
|
607
|
+
}
|
608
|
+
finally { if (e_1) throw e_1.error; }
|
609
|
+
}
|
610
|
+
// 如果没有找到对应的cookie,则返回null
|
611
|
+
return null;
|
612
|
+
};
|
613
|
+
/**
|
614
|
+
* 设置cookie
|
615
|
+
* @param name cookie名称
|
616
|
+
* @param value cookie值
|
617
|
+
* @param timeStamp 过期时间戳 单位s
|
618
|
+
* @param path 路径
|
619
|
+
* @param domain cookie域名
|
620
|
+
* @param sameSite 跨域设置
|
621
|
+
* @param secure 是否仅通过 HTTPS 协议传输
|
622
|
+
*/
|
623
|
+
CookieStorage.prototype.set = function (name, value, timeStamp, path, domain, sameSite, secure) {
|
624
|
+
path = path || '/';
|
625
|
+
name = name.trim();
|
626
|
+
value = value.trim();
|
627
|
+
var cookieStr = "".concat(name, "=").concat(encodeURIComponent(value), "; path=").concat(path, ";");
|
628
|
+
timeStamp = isValid(timeStamp) ? timeStamp : 73000;
|
629
|
+
// 设置过期时间
|
630
|
+
cookieStr += " max-age=".concat(timeStamp, ";");
|
631
|
+
// 是否仅通过 HTTPS 协议传输
|
632
|
+
if (secure) {
|
633
|
+
cookieStr += ' secure;';
|
634
|
+
}
|
635
|
+
// 设置域名
|
636
|
+
if (domain) {
|
637
|
+
cookieStr += " domain=".concat(domain, ";");
|
638
|
+
}
|
639
|
+
// 设置跨域
|
640
|
+
if (['Strict', 'Lax', 'None'].includes(sameSite)) {
|
641
|
+
cookieStr += " SameSite=".concat(sameSite, ";");
|
642
|
+
}
|
643
|
+
document.cookie = cookieStr;
|
644
|
+
};
|
645
|
+
/**
|
646
|
+
* 删除指定cookie
|
647
|
+
* @param name
|
648
|
+
* @param path
|
649
|
+
*/
|
650
|
+
CookieStorage.prototype.remove = function (name, path) {
|
651
|
+
if (path === void 0) { path = '/'; }
|
652
|
+
this.set(name, '1', 0, path);
|
653
|
+
};
|
654
|
+
/**
|
655
|
+
* 将cookie设置到当前子域名下,用于跨站共享
|
656
|
+
* @param name
|
657
|
+
* @param value
|
658
|
+
* @param timeStamp
|
659
|
+
*/
|
660
|
+
CookieStorage.prototype.setDomain = function (name, value, timeStamp) {
|
661
|
+
var domain = getCurrentDomain();
|
662
|
+
if (domain === 'url解析失败') {
|
663
|
+
domain = '';
|
664
|
+
}
|
665
|
+
this.set(name, value, timeStamp, '/', domain);
|
666
|
+
};
|
667
|
+
return CookieStorage;
|
668
|
+
}());
|
669
|
+
/**
|
670
|
+
* localStorage 操作
|
671
|
+
*/
|
672
|
+
var LocalStorage = /** @class */ (function () {
|
673
|
+
function LocalStorage() {
|
674
|
+
this.name = 'LocalStorage';
|
675
|
+
}
|
676
|
+
/**
|
677
|
+
* 判断是否支持localStorage
|
678
|
+
*/
|
679
|
+
LocalStorage.prototype.isSupport = function () {
|
680
|
+
var supported = true;
|
681
|
+
try {
|
682
|
+
var supportName = '__localStorageSupport__';
|
683
|
+
var val = 'testIsSupportStorage';
|
684
|
+
this.set(supportName, val);
|
685
|
+
if (this.get(supportName) !== val) {
|
686
|
+
supported = false;
|
687
|
+
}
|
688
|
+
this.remove(supportName);
|
689
|
+
}
|
690
|
+
catch (e) {
|
691
|
+
supported = false;
|
692
|
+
}
|
693
|
+
return supported;
|
694
|
+
};
|
695
|
+
LocalStorage.prototype.key = function (index) {
|
696
|
+
return window.localStorage.key(index);
|
697
|
+
};
|
698
|
+
LocalStorage.prototype.get = function (key) {
|
699
|
+
return window.localStorage.getItem(key);
|
700
|
+
};
|
701
|
+
LocalStorage.prototype.length = function () {
|
702
|
+
return window.localStorage.length;
|
703
|
+
};
|
704
|
+
LocalStorage.prototype.set = function (key, value) {
|
705
|
+
try {
|
706
|
+
window.localStorage.setItem(key, value);
|
707
|
+
}
|
708
|
+
catch (e) { }
|
709
|
+
};
|
710
|
+
LocalStorage.prototype.remove = function (key) {
|
711
|
+
window.localStorage.removeItem(key);
|
712
|
+
};
|
713
|
+
LocalStorage.prototype.parse = function (key) {
|
714
|
+
var result = this.get(key);
|
715
|
+
try {
|
716
|
+
result = JSON.parse(result);
|
717
|
+
}
|
718
|
+
catch (e) {
|
719
|
+
result = '';
|
720
|
+
}
|
721
|
+
return result;
|
722
|
+
};
|
723
|
+
return LocalStorage;
|
724
|
+
}());
|
725
|
+
/**
|
726
|
+
* memoryStorage 操作
|
727
|
+
*/
|
728
|
+
var MemoryStorage = /** @class */ (function () {
|
729
|
+
function MemoryStorage() {
|
730
|
+
this.name = 'MemoryStorage';
|
731
|
+
this.data = {};
|
732
|
+
}
|
733
|
+
MemoryStorage.prototype.get = function (key) {
|
734
|
+
var result = this.data[key];
|
735
|
+
if (isValid(result === null || result === void 0 ? void 0 : result.expireTime)) {
|
736
|
+
if (result.expireTime < nowStamp()) {
|
737
|
+
return null;
|
738
|
+
}
|
739
|
+
return result.value;
|
740
|
+
}
|
741
|
+
return result === null || result === void 0 ? void 0 : result.value;
|
742
|
+
};
|
743
|
+
/**
|
744
|
+
* 存储数据
|
745
|
+
* @param key
|
746
|
+
* @param value
|
747
|
+
* @param expires 单位 s
|
748
|
+
*/
|
749
|
+
MemoryStorage.prototype.set = function (key, value, expires) {
|
750
|
+
if (isValid(expires)) {
|
751
|
+
var expireTime = nowStamp() + expires * 1000;
|
752
|
+
this.data[key] = {
|
753
|
+
value: value,
|
754
|
+
expireTime: expireTime
|
755
|
+
};
|
756
|
+
}
|
757
|
+
this.data[key] = { value: value };
|
758
|
+
};
|
759
|
+
MemoryStorage.prototype.setDomain = function (name, value, timeStamp) {
|
760
|
+
this.set(name, value, timeStamp);
|
761
|
+
};
|
762
|
+
return MemoryStorage;
|
763
|
+
}());
|
764
|
+
|
765
|
+
function isElement(val) {
|
766
|
+
return (val === null || val === void 0 ? void 0 : val.nodeType) === 1;
|
767
|
+
}
|
768
|
+
/**
|
769
|
+
* 获取指定元素以及其父元素组成的路径
|
770
|
+
* @param element
|
771
|
+
*/
|
772
|
+
function getElementParents(element) {
|
773
|
+
var pathArr = [element];
|
774
|
+
try {
|
775
|
+
if (!isElement(element)) {
|
776
|
+
return pathArr;
|
777
|
+
}
|
778
|
+
if (element === null || element.parentElement === null) {
|
779
|
+
return pathArr;
|
780
|
+
}
|
781
|
+
while (element.parentElement !== null) {
|
782
|
+
element = element.parentElement;
|
783
|
+
pathArr.push(element);
|
784
|
+
}
|
785
|
+
return pathArr;
|
786
|
+
}
|
787
|
+
catch (error) { }
|
788
|
+
return pathArr;
|
789
|
+
}
|
790
|
+
/**
|
791
|
+
* 获取input元素的内容
|
792
|
+
* @param element
|
793
|
+
* @param isCollectInput 是否采集input
|
794
|
+
*/
|
795
|
+
function getInputElementContent(element, isCollectInput) {
|
796
|
+
var _a;
|
797
|
+
var tagName = (_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
798
|
+
if (tagName === 'input') {
|
799
|
+
if (['button', 'submit'].includes(element.type) || isCollectInput) {
|
800
|
+
return element.value || '';
|
801
|
+
}
|
802
|
+
return '';
|
803
|
+
}
|
804
|
+
var textContent = '';
|
805
|
+
if (element.textContent) {
|
806
|
+
textContent = element.textContent.trim();
|
807
|
+
}
|
808
|
+
else if (element.innerText) {
|
809
|
+
textContent = element.innerText.trim();
|
810
|
+
}
|
811
|
+
if (textContent) {
|
812
|
+
textContent = textContent
|
813
|
+
.replace(/[\r\n]/g, ' ')
|
814
|
+
.replace(/[ ]+/g, ' ')
|
815
|
+
.substring(0, 255);
|
816
|
+
}
|
817
|
+
return textContent || '';
|
818
|
+
}
|
819
|
+
/**
|
820
|
+
* 获取元素信息
|
821
|
+
* @param element 元素
|
822
|
+
* @param isCollectInput 是否采集input
|
823
|
+
*/
|
824
|
+
function getElementProperties(element, isCollectInput) {
|
825
|
+
var _a;
|
826
|
+
if (!isElement(element))
|
827
|
+
return {};
|
828
|
+
var tagName = (_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
829
|
+
var props = {
|
830
|
+
H_element_type: tagName,
|
831
|
+
H_element_name: element.getAttribute('name'),
|
832
|
+
H_element_id: element.getAttribute('id'),
|
833
|
+
H_element_target_url: element.getAttribute('href'),
|
834
|
+
H_element_class_name: element.getAttribute('className'),
|
835
|
+
H_element_content: getInputElementContent(element, isCollectInput)
|
836
|
+
};
|
837
|
+
return stripEmptyProperties(props);
|
838
|
+
}
|
839
|
+
/**
|
840
|
+
* 获取页面信息
|
841
|
+
*/
|
842
|
+
function getPageProperties() {
|
843
|
+
var referrer = getReferrer();
|
844
|
+
var url_domain = getCurrentDomain();
|
845
|
+
var viewportPosition = Math.round(getScrollTop());
|
846
|
+
var props = {
|
847
|
+
H_referrer: referrer,
|
848
|
+
H_referrer_host: referrer ? getHostname(referrer) : '',
|
849
|
+
H_url: window.location.href,
|
850
|
+
H_url_host: getHostname(window.location.href, 'url_host取值异常'),
|
851
|
+
H_url_domain: url_domain,
|
852
|
+
H_url_path: window.location.pathname,
|
853
|
+
H_url_hash: window.location.hash,
|
854
|
+
H_title: document.title,
|
855
|
+
H_viewport_position: viewportPosition
|
856
|
+
};
|
857
|
+
return stripEmptyProperties(props);
|
858
|
+
}
|
859
|
+
|
860
|
+
var SearchKeyword = /** @class */ (function () {
|
861
|
+
function SearchKeyword() {
|
862
|
+
}
|
863
|
+
SearchKeyword.getSourceFromReferrer = function () {
|
864
|
+
var getMatchStrFromArr = function (arr, str) {
|
865
|
+
for (var i = 0; i < arr.length; i++) {
|
866
|
+
if (str.split('?')[0].indexOf(arr[i]) !== -1) {
|
867
|
+
return true;
|
868
|
+
}
|
869
|
+
}
|
870
|
+
};
|
871
|
+
var utm_reg = "(".concat(utmTypes.join('|'), ")\\=[^&]+");
|
872
|
+
var referrer = document.referrer || '';
|
873
|
+
var url = window.location.href;
|
874
|
+
if (url) {
|
875
|
+
var utm_match = url.match(new RegExp(utm_reg));
|
876
|
+
if (utm_match && utm_match[0]) {
|
877
|
+
return '付费广告流量';
|
878
|
+
}
|
879
|
+
if (getMatchStrFromArr(searchTypes, referrer)) {
|
880
|
+
return '自然搜索流量';
|
881
|
+
}
|
882
|
+
if (getMatchStrFromArr(socialTypes, referrer)) {
|
883
|
+
return '社交网站流量';
|
884
|
+
}
|
885
|
+
if (referrer === '') {
|
886
|
+
return '直接流量';
|
887
|
+
}
|
888
|
+
return '引荐流量';
|
889
|
+
}
|
890
|
+
return '获取url异常';
|
891
|
+
};
|
892
|
+
SearchKeyword.getReferSearchEngine = function (referrerUrl) {
|
893
|
+
var e_1, _a;
|
894
|
+
var hostname = getHostname(referrerUrl);
|
895
|
+
if (!hostname || hostname === 'hostname解析异常') {
|
896
|
+
return '';
|
897
|
+
}
|
898
|
+
var regexps = {
|
899
|
+
baidu: [/^.*\.baidu\.com$/],
|
900
|
+
bing: [/^.*\.bing\.com$/],
|
901
|
+
google: [
|
902
|
+
/^www\.google\.com$/,
|
903
|
+
/^www\.google\.com\.[a-z]{2}$/,
|
904
|
+
/^www\.google\.[a-z]{2}$/
|
905
|
+
],
|
906
|
+
sm: [/^m\.sm\.cn$/],
|
907
|
+
so: [/^.+\.so\.com$/],
|
908
|
+
sogou: [/^.*\.sogou\.com$/],
|
909
|
+
yahoo: [/^.*\.yahoo\.com$/]
|
910
|
+
};
|
911
|
+
for (var regexp in regexps) {
|
912
|
+
var regexList = regexps[regexp];
|
913
|
+
try {
|
914
|
+
for (var regexList_1 = (e_1 = void 0, __values(regexList)), regexList_1_1 = regexList_1.next(); !regexList_1_1.done; regexList_1_1 = regexList_1.next()) {
|
915
|
+
var regex = regexList_1_1.value;
|
916
|
+
if (regex.test(hostname)) {
|
917
|
+
return regexp;
|
918
|
+
}
|
919
|
+
}
|
920
|
+
}
|
921
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
922
|
+
finally {
|
923
|
+
try {
|
924
|
+
if (regexList_1_1 && !regexList_1_1.done && (_a = regexList_1.return)) _a.call(regexList_1);
|
925
|
+
}
|
926
|
+
finally { if (e_1) throw e_1.error; }
|
927
|
+
}
|
928
|
+
}
|
929
|
+
return '未知搜索引擎';
|
930
|
+
};
|
931
|
+
SearchKeyword.getKeywordFromReferrer = function () {
|
932
|
+
var referrerUrl = document.referrer || '';
|
933
|
+
if (referrerUrl.indexOf('http') === 0) {
|
934
|
+
var searchEngine = this.getReferSearchEngine(referrerUrl);
|
935
|
+
var query = getURLSearchParams(getURL(referrerUrl).search);
|
936
|
+
if (isEmptyObject(query)) {
|
937
|
+
return '未取到值';
|
938
|
+
}
|
939
|
+
for (var key in searchKeywords) {
|
940
|
+
var value = searchKeywords[key];
|
941
|
+
if (key === searchEngine) {
|
942
|
+
if (isArray(value)) {
|
943
|
+
for (var i = 0; i < value.length; i++) {
|
944
|
+
var val = query[value[i]];
|
945
|
+
if (val) {
|
946
|
+
return val;
|
947
|
+
}
|
948
|
+
}
|
949
|
+
}
|
950
|
+
else if (query[value]) {
|
951
|
+
return query[value];
|
952
|
+
}
|
953
|
+
}
|
954
|
+
}
|
955
|
+
return '未取到值';
|
956
|
+
}
|
957
|
+
if (referrerUrl === '') {
|
958
|
+
return '未取到值_直接打开';
|
959
|
+
}
|
960
|
+
return '未取到值_非http的url';
|
961
|
+
};
|
962
|
+
return SearchKeyword;
|
963
|
+
}());
|
964
|
+
/**
|
965
|
+
* 广告参数
|
966
|
+
* @param prefix
|
967
|
+
*/
|
968
|
+
function getUmtsParams(prefix) {
|
969
|
+
if (prefix === void 0) { prefix = ''; }
|
970
|
+
var utms = getUtm();
|
971
|
+
var allUtms = {};
|
972
|
+
Object.keys(utms).forEach(function (key) {
|
973
|
+
allUtms[prefix + key] = utms[key];
|
974
|
+
});
|
975
|
+
return allUtms;
|
976
|
+
}
|
977
|
+
function getUtm() {
|
978
|
+
var params = {};
|
979
|
+
utmTypes.forEach(function (key) {
|
980
|
+
var result = getQueryParam(window.location.href, key);
|
981
|
+
if (result.length) {
|
982
|
+
params[key] = result;
|
983
|
+
}
|
984
|
+
});
|
985
|
+
return params;
|
986
|
+
}
|
987
|
+
|
988
|
+
function getBrowserInfo() {
|
989
|
+
var _a = new UAParser().getResult(), browser = _a.browser, device = _a.device, os = _a.os;
|
990
|
+
var data = {
|
991
|
+
H_timezone_offset: new Date().getTimezoneOffset(),
|
992
|
+
H_viewport_width: getScreenWidth(),
|
993
|
+
H_viewport_height: getScreenHeight(),
|
994
|
+
H_screen_width: window.screen.width,
|
995
|
+
H_screen_height: window.screen.height,
|
996
|
+
H_lib_version: PV_LIB_VERSION,
|
997
|
+
H_lib: 'js',
|
998
|
+
H_lib_method: 'code',
|
999
|
+
H_browser: browser.name.toLowerCase(),
|
1000
|
+
H_browser_version: browser.version,
|
1001
|
+
H_os: os.name,
|
1002
|
+
H_os_version: os.version,
|
1003
|
+
H_language: isString(navigator.language)
|
1004
|
+
? navigator.language.toLowerCase()
|
1005
|
+
: '取值异常',
|
1006
|
+
H_network_type: networkType()
|
1007
|
+
};
|
1008
|
+
if (device.type === 'mobile') {
|
1009
|
+
data.H_model = device.vendor ? device.model : 'UnknownPhone';
|
1010
|
+
}
|
1011
|
+
else {
|
1012
|
+
data.H_model = device.model;
|
1013
|
+
}
|
1014
|
+
return data;
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
var Request = /** @class */ (function () {
|
1018
|
+
function Request(options) {
|
1019
|
+
this.options = options;
|
1020
|
+
}
|
1021
|
+
return Request;
|
1022
|
+
}());
|
1023
|
+
/**
|
1024
|
+
* 图片请求
|
1025
|
+
*/
|
1026
|
+
var ImageRequest = /** @class */ (function (_super) {
|
1027
|
+
__extends(ImageRequest, _super);
|
1028
|
+
function ImageRequest(options) {
|
1029
|
+
var _this = _super.call(this, options) || this;
|
1030
|
+
_this.options = options;
|
1031
|
+
return _this;
|
1032
|
+
}
|
1033
|
+
ImageRequest.prototype.run = function () {
|
1034
|
+
var _this = this;
|
1035
|
+
return new Promise(function (resolve) {
|
1036
|
+
var _a = _this.options, imgUseCrossOrigin = _a.imgUseCrossOrigin, url = _a.url, data = _a.data;
|
1037
|
+
var img = new Image();
|
1038
|
+
if (imgUseCrossOrigin) {
|
1039
|
+
img.crossOrigin = 'anonymous';
|
1040
|
+
}
|
1041
|
+
var spliceStr = url.indexOf('?') === -1 ? '?' : '&';
|
1042
|
+
img.src = "".concat(url).concat(spliceStr, "data=").concat(data);
|
1043
|
+
var callback = function (type) {
|
1044
|
+
img.src = null;
|
1045
|
+
img = null;
|
1046
|
+
resolve({ type: type });
|
1047
|
+
};
|
1048
|
+
img.onload = function () {
|
1049
|
+
callback('success');
|
1050
|
+
};
|
1051
|
+
img.onerror = function () {
|
1052
|
+
callback('error');
|
1053
|
+
};
|
1054
|
+
img.onabort = function () {
|
1055
|
+
callback('abort');
|
1056
|
+
};
|
1057
|
+
});
|
1058
|
+
};
|
1059
|
+
return ImageRequest;
|
1060
|
+
}(Request));
|
1061
|
+
/**
|
1062
|
+
* ajax请求
|
1063
|
+
*/
|
1064
|
+
var AjaxRequest = /** @class */ (function (_super) {
|
1065
|
+
__extends(AjaxRequest, _super);
|
1066
|
+
function AjaxRequest(options) {
|
1067
|
+
var _this = _super.call(this, options) || this;
|
1068
|
+
_this.options = options;
|
1069
|
+
return _this;
|
1070
|
+
}
|
1071
|
+
AjaxRequest.prototype.run = function () {
|
1072
|
+
var _this = this;
|
1073
|
+
return new Promise(function (resolve) {
|
1074
|
+
var _a = _this.options, url = _a.url, data = _a.data, timeout = _a.timeout;
|
1075
|
+
var xhr = new XMLHttpRequest();
|
1076
|
+
xhr.open('POST', url, true);
|
1077
|
+
xhr.timeout = timeout || 20000;
|
1078
|
+
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
1079
|
+
xhr.send(data || null);
|
1080
|
+
xhr.onreadystatechange = function () {
|
1081
|
+
if (xhr.readyState === 4) {
|
1082
|
+
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
|
1083
|
+
resolve({
|
1084
|
+
type: 'success'
|
1085
|
+
});
|
1086
|
+
}
|
1087
|
+
else {
|
1088
|
+
resolve({
|
1089
|
+
type: 'error',
|
1090
|
+
msg: "\u7F51\u7EDC\u5F02\u5E38, \u8BF7\u6C42\u5931\u8D25".concat(xhr.status)
|
1091
|
+
});
|
1092
|
+
}
|
1093
|
+
}
|
1094
|
+
};
|
1095
|
+
});
|
1096
|
+
};
|
1097
|
+
return AjaxRequest;
|
1098
|
+
}(Request));
|
1099
|
+
/**
|
1100
|
+
* beacon请求
|
1101
|
+
*/
|
1102
|
+
var BeaconRequest = /** @class */ (function (_super) {
|
1103
|
+
__extends(BeaconRequest, _super);
|
1104
|
+
function BeaconRequest(options) {
|
1105
|
+
var _this = _super.call(this, options) || this;
|
1106
|
+
_this.options = options;
|
1107
|
+
return _this;
|
1108
|
+
}
|
1109
|
+
BeaconRequest.prototype.run = function () {
|
1110
|
+
var _this = this;
|
1111
|
+
return new Promise(function (resolve) {
|
1112
|
+
var _a = _this.options, url = _a.url, data = _a.data;
|
1113
|
+
if (navigator.sendBeacon) {
|
1114
|
+
var isSuccess = navigator.sendBeacon(url, data);
|
1115
|
+
if (isSuccess) {
|
1116
|
+
resolve({
|
1117
|
+
type: 'success'
|
1118
|
+
});
|
1119
|
+
}
|
1120
|
+
else {
|
1121
|
+
resolve({
|
1122
|
+
type: 'error',
|
1123
|
+
msg: 'sendBeacon 请求失败'
|
1124
|
+
});
|
1125
|
+
}
|
1126
|
+
}
|
1127
|
+
});
|
1128
|
+
};
|
1129
|
+
return BeaconRequest;
|
1130
|
+
}(Request));
|
1131
|
+
|
1132
|
+
var callbacks = [];
|
1133
|
+
var pending = false;
|
1134
|
+
var timerFunc;
|
1135
|
+
function flushCallbacks() {
|
1136
|
+
var e_1, _a;
|
1137
|
+
pending = false;
|
1138
|
+
try {
|
1139
|
+
for (var callbacks_1 = __values(callbacks), callbacks_1_1 = callbacks_1.next(); !callbacks_1_1.done; callbacks_1_1 = callbacks_1.next()) {
|
1140
|
+
var func = callbacks_1_1.value;
|
1141
|
+
func();
|
1142
|
+
}
|
1143
|
+
}
|
1144
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
1145
|
+
finally {
|
1146
|
+
try {
|
1147
|
+
if (callbacks_1_1 && !callbacks_1_1.done && (_a = callbacks_1.return)) _a.call(callbacks_1);
|
1148
|
+
}
|
1149
|
+
finally { if (e_1) throw e_1.error; }
|
1150
|
+
}
|
1151
|
+
callbacks.length = 0;
|
1152
|
+
}
|
1153
|
+
if (window && window.requestIdleCallback) {
|
1154
|
+
timerFunc = function () {
|
1155
|
+
window.requestIdleCallback(flushCallbacks);
|
1156
|
+
};
|
1157
|
+
}
|
1158
|
+
else if (typeof Promise !== 'undefined') {
|
1159
|
+
timerFunc = function () {
|
1160
|
+
Promise.resolve().then(flushCallbacks);
|
1161
|
+
};
|
1162
|
+
}
|
1163
|
+
else {
|
1164
|
+
timerFunc = function () {
|
1165
|
+
setTimeout(flushCallbacks, 0);
|
1166
|
+
};
|
1167
|
+
}
|
1168
|
+
function nextTick(callback, ctx) {
|
1169
|
+
var args = [];
|
1170
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
1171
|
+
args[_i - 2] = arguments[_i];
|
1172
|
+
}
|
1173
|
+
var _resolve;
|
1174
|
+
callbacks.push(function () {
|
1175
|
+
if (callback) {
|
1176
|
+
try {
|
1177
|
+
callback.apply(ctx, args);
|
1178
|
+
}
|
1179
|
+
catch (e) { }
|
1180
|
+
}
|
1181
|
+
else {
|
1182
|
+
_resolve(args);
|
1183
|
+
}
|
1184
|
+
});
|
1185
|
+
if (!pending) {
|
1186
|
+
pending = true;
|
1187
|
+
timerFunc();
|
1188
|
+
}
|
1189
|
+
if (!callback && typeof Promise !== 'undefined') {
|
1190
|
+
return new Promise(function (resolve) {
|
1191
|
+
_resolve = resolve;
|
1192
|
+
});
|
1193
|
+
}
|
1194
|
+
}
|
1195
|
+
|
1196
|
+
var Mitt = /** @class */ (function () {
|
1197
|
+
function Mitt() {
|
1198
|
+
this.all = new Map();
|
1199
|
+
}
|
1200
|
+
Mitt.prototype.on = function (type, handler) {
|
1201
|
+
var handlers = this.all.get(type);
|
1202
|
+
if (handlers) {
|
1203
|
+
handlers.push(handler);
|
1204
|
+
}
|
1205
|
+
else {
|
1206
|
+
this.all.set(type, [handler]);
|
1207
|
+
}
|
1208
|
+
};
|
1209
|
+
Mitt.prototype.emit = function (type) {
|
1210
|
+
var args = [];
|
1211
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
1212
|
+
args[_i - 1] = arguments[_i];
|
1213
|
+
}
|
1214
|
+
var handlers = this.all.get(type);
|
1215
|
+
if (handlers) {
|
1216
|
+
handlers.forEach(function (handler) {
|
1217
|
+
handler.apply(void 0, __spreadArray([], __read(args), false));
|
1218
|
+
});
|
1219
|
+
}
|
1220
|
+
};
|
1221
|
+
Mitt.prototype.off = function (type, handler) {
|
1222
|
+
var handlers = this.all.get(type);
|
1223
|
+
if (handlers) {
|
1224
|
+
if (handler) {
|
1225
|
+
var index = handlers.indexOf(handler);
|
1226
|
+
if (index >= 0) {
|
1227
|
+
handlers.splice(index, 1);
|
1228
|
+
}
|
1229
|
+
}
|
1230
|
+
else {
|
1231
|
+
this.all.set(type, []);
|
1232
|
+
}
|
1233
|
+
}
|
1234
|
+
};
|
1235
|
+
return Mitt;
|
1236
|
+
}());
|
1237
|
+
var mitt = new Mitt();
|
1238
|
+
|
1239
|
+
/**
|
1240
|
+
* 是否支持console
|
1241
|
+
*/
|
1242
|
+
function supportConsole() {
|
1243
|
+
return typeof console !== 'undefined';
|
1244
|
+
}
|
1245
|
+
/**
|
1246
|
+
* 打印日志
|
1247
|
+
* @param message
|
1248
|
+
* @param type
|
1249
|
+
*/
|
1250
|
+
function log(message, type) {
|
1251
|
+
if (type === void 0) { type = hinaCloudTypes.ConsoleTypes.LOG; }
|
1252
|
+
var func = console[type] || console.log;
|
1253
|
+
if (typeof func === 'function') {
|
1254
|
+
func(message);
|
1255
|
+
}
|
1256
|
+
}
|
1257
|
+
|
1258
|
+
var IS_NEW_USER_KEY = 'hinasdk_isNewUser';
|
1259
|
+
var State = /** @class */ (function () {
|
1260
|
+
function State(options) {
|
1261
|
+
this.options = options;
|
1262
|
+
this.storeName = 'hinasdk_crossdata';
|
1263
|
+
/**
|
1264
|
+
* 存储对象
|
1265
|
+
*/
|
1266
|
+
this.state = {
|
1267
|
+
accountId: null,
|
1268
|
+
deviceId: null,
|
1269
|
+
anonymousId: null,
|
1270
|
+
firstVisitTime: nowStamp(),
|
1271
|
+
props: {}
|
1272
|
+
};
|
1273
|
+
/**
|
1274
|
+
* 首次触发事件
|
1275
|
+
*/
|
1276
|
+
this.isFirstTime = false;
|
1277
|
+
/**
|
1278
|
+
* 首日触发事件
|
1279
|
+
*/
|
1280
|
+
this.isFirstDay = false;
|
1281
|
+
/**
|
1282
|
+
* 是否设置第一次访问属性
|
1283
|
+
*/
|
1284
|
+
this.isSetFirstVisit = true;
|
1285
|
+
}
|
1286
|
+
State.prototype.log = function (message, type) {
|
1287
|
+
if (type === void 0) { type = hinaCloudTypes.ConsoleTypes.LOG; }
|
1288
|
+
var showLog = this.options.showLog;
|
1289
|
+
if (!supportConsole() || !showLog)
|
1290
|
+
return;
|
1291
|
+
log(message, type);
|
1292
|
+
};
|
1293
|
+
/**
|
1294
|
+
* 初始化存储
|
1295
|
+
*/
|
1296
|
+
State.prototype.init = function () {
|
1297
|
+
var cookieStorage = new CookieStorage();
|
1298
|
+
var memoryStorage = new MemoryStorage();
|
1299
|
+
var localStorage = new LocalStorage();
|
1300
|
+
if (cookieStorage.isSupport()) {
|
1301
|
+
this.storage = cookieStorage;
|
1302
|
+
}
|
1303
|
+
else {
|
1304
|
+
this.log('Cookie storage is not supported, SDK internal cache has been enabled', hinaCloudTypes.ConsoleTypes.WARN);
|
1305
|
+
this.storage = memoryStorage;
|
1306
|
+
}
|
1307
|
+
if (localStorage.isSupport()) {
|
1308
|
+
this.localStorage = localStorage;
|
1309
|
+
}
|
1310
|
+
else {
|
1311
|
+
this.log('localStorage is not supported, SDK internal cache has been enabled', hinaCloudTypes.ConsoleTypes.WARN);
|
1312
|
+
}
|
1313
|
+
var oldState;
|
1314
|
+
oldState = this.storage.get(this.storeName);
|
1315
|
+
if (!oldState && this.localStorage) {
|
1316
|
+
oldState = this.localStorage.get(this.storeName);
|
1317
|
+
}
|
1318
|
+
if (oldState && isJSONString(oldState)) {
|
1319
|
+
try {
|
1320
|
+
oldState = JSON.parse(oldState);
|
1321
|
+
this.state = merge(this.state, oldState);
|
1322
|
+
}
|
1323
|
+
catch (e) {
|
1324
|
+
this.log(e, hinaCloudTypes.ConsoleTypes.ERROR);
|
1325
|
+
}
|
1326
|
+
}
|
1327
|
+
// 如果不存在hinasdk_crossdata的存储数据,则说明是第一次访问sdk
|
1328
|
+
if (oldState) {
|
1329
|
+
this.isSetFirstVisit = false;
|
1330
|
+
this.save();
|
1331
|
+
}
|
1332
|
+
else {
|
1333
|
+
this.isFirstDay = true;
|
1334
|
+
this.isFirstTime = true;
|
1335
|
+
var date = new Date();
|
1336
|
+
var dateObj = {
|
1337
|
+
h: 23 - date.getHours(),
|
1338
|
+
m: 59 - date.getMinutes(),
|
1339
|
+
s: 59 - date.getSeconds()
|
1340
|
+
};
|
1341
|
+
var second = dateObj.h * 3600 + dateObj.m * 60 + dateObj.s;
|
1342
|
+
// todo 设置这个值似乎没有什么用
|
1343
|
+
this.storage.set(IS_NEW_USER_KEY, 'true', second);
|
1344
|
+
}
|
1345
|
+
// 第一次需要生成匿名ID和设备ID,此时这两个ID是一致的,其中设备ID可以修改,但是匿名ID设置了之后 就不能再改变了
|
1346
|
+
var uuid = generatorUUID();
|
1347
|
+
if (!this.getAnonymousId()) {
|
1348
|
+
this.setAnonymousId(uuid);
|
1349
|
+
}
|
1350
|
+
if (!this.getDeviceId()) {
|
1351
|
+
this.setDeviceId(uuid);
|
1352
|
+
}
|
1353
|
+
};
|
1354
|
+
/**
|
1355
|
+
* 清空state数据
|
1356
|
+
*/
|
1357
|
+
State.prototype.clear = function () {
|
1358
|
+
this.state = {};
|
1359
|
+
this.save();
|
1360
|
+
};
|
1361
|
+
/**
|
1362
|
+
* 缓存state数据
|
1363
|
+
*/
|
1364
|
+
State.prototype.save = function () {
|
1365
|
+
// cookie存于子域名中,用于跨站共享
|
1366
|
+
this.storage.setDomain(this.storeName, JSON.stringify(this.state));
|
1367
|
+
if (this.localStorage) {
|
1368
|
+
this.localStorage.set(this.storeName, JSON.stringify(this.state));
|
1369
|
+
}
|
1370
|
+
};
|
1371
|
+
/**
|
1372
|
+
* 设置共享数据
|
1373
|
+
* @param name
|
1374
|
+
* @param value
|
1375
|
+
*/
|
1376
|
+
State.prototype.set = function (name, value) {
|
1377
|
+
this.state[name] = value;
|
1378
|
+
this.save();
|
1379
|
+
};
|
1380
|
+
/**
|
1381
|
+
* 检查设置值是否合法
|
1382
|
+
* @param name
|
1383
|
+
* @param value
|
1384
|
+
*/
|
1385
|
+
State.prototype.checkSetValue = function (name, value) {
|
1386
|
+
value = value !== null && value !== void 0 ? value : '';
|
1387
|
+
if (isNumber(value) || isString(value)) {
|
1388
|
+
return true;
|
1389
|
+
}
|
1390
|
+
this.log("".concat(name, ": id must be string or number"), hinaCloudTypes.ConsoleTypes.WARN);
|
1391
|
+
return false;
|
1392
|
+
};
|
1393
|
+
/**
|
1394
|
+
* 设置deviceId
|
1395
|
+
* @param id
|
1396
|
+
*/
|
1397
|
+
State.prototype.setDeviceId = function (id) {
|
1398
|
+
if (id === void 0) { id = ''; }
|
1399
|
+
if (this.checkSetValue('deviceId', id)) {
|
1400
|
+
this.set('deviceId', id);
|
1401
|
+
}
|
1402
|
+
};
|
1403
|
+
/**
|
1404
|
+
* 设置账号id
|
1405
|
+
* @param id
|
1406
|
+
*/
|
1407
|
+
State.prototype.setAccountId = function (id) {
|
1408
|
+
if (id === void 0) { id = ''; }
|
1409
|
+
if (this.checkSetValue('accountId', id)) {
|
1410
|
+
this.set('accountId', id);
|
1411
|
+
}
|
1412
|
+
};
|
1413
|
+
/**
|
1414
|
+
* 设置匿名id
|
1415
|
+
* @param id
|
1416
|
+
*/
|
1417
|
+
State.prototype.setAnonymousId = function (id) {
|
1418
|
+
if (this.state.anonymousId) {
|
1419
|
+
this.log("Current anonymousId is ".concat(this.getAnonymousId(), ", it has been set"), hinaCloudTypes.ConsoleTypes.WARN);
|
1420
|
+
return;
|
1421
|
+
}
|
1422
|
+
if (this.checkSetValue('anonymousId', id)) {
|
1423
|
+
this.set('anonymousId', id);
|
1424
|
+
}
|
1425
|
+
};
|
1426
|
+
/**
|
1427
|
+
* 设置广告参数
|
1428
|
+
* @param props
|
1429
|
+
*/
|
1430
|
+
State.prototype.setProps = function (props) {
|
1431
|
+
var newProps = merge(this.state.props || {}, props);
|
1432
|
+
for (var key in newProps) {
|
1433
|
+
if (typeof newProps[key] === 'string') {
|
1434
|
+
newProps[key] = newProps[key].slice(0, MAX_REFERRER_STRING_LENGTH);
|
1435
|
+
}
|
1436
|
+
}
|
1437
|
+
this.set('props', newProps);
|
1438
|
+
};
|
1439
|
+
/**
|
1440
|
+
* 获取匿名ID
|
1441
|
+
*/
|
1442
|
+
State.prototype.getAnonymousId = function () {
|
1443
|
+
return this.state.anonymousId;
|
1444
|
+
};
|
1445
|
+
/**
|
1446
|
+
* 获取设备ID
|
1447
|
+
*/
|
1448
|
+
State.prototype.getDeviceId = function () {
|
1449
|
+
return this.state.deviceId;
|
1450
|
+
};
|
1451
|
+
/**
|
1452
|
+
* 获取账户ID
|
1453
|
+
*/
|
1454
|
+
State.prototype.getAccountId = function () {
|
1455
|
+
return this.state.accountId;
|
1456
|
+
};
|
1457
|
+
/**
|
1458
|
+
* 获取cookie值
|
1459
|
+
*/
|
1460
|
+
State.prototype.getCookie = function () {
|
1461
|
+
return this.storage.get(this.storeName);
|
1462
|
+
};
|
1463
|
+
return State;
|
1464
|
+
}());
|
1465
|
+
|
1466
|
+
exports.AjaxRequest = AjaxRequest;
|
1467
|
+
exports.BeaconRequest = BeaconRequest;
|
1468
|
+
exports.COOKIE_TEST_NAME = COOKIE_TEST_NAME;
|
1469
|
+
exports.CookieStorage = CookieStorage;
|
1470
|
+
exports.EPM_LIB_VERSION = EPM_LIB_VERSION;
|
1471
|
+
exports.ImageRequest = ImageRequest;
|
1472
|
+
exports.ListenPageState = ListenPageState;
|
1473
|
+
exports.LocalStorage = LocalStorage;
|
1474
|
+
exports.MAX_REFERRER_STRING_LENGTH = MAX_REFERRER_STRING_LENGTH;
|
1475
|
+
exports.MAX_STRING_LENGTH = MAX_STRING_LENGTH;
|
1476
|
+
exports.MemoryStorage = MemoryStorage;
|
1477
|
+
exports.PV_LIB_VERSION = PV_LIB_VERSION;
|
1478
|
+
exports.Request = Request;
|
1479
|
+
exports.SearchKeyword = SearchKeyword;
|
1480
|
+
exports.State = State;
|
1481
|
+
exports.base64Decode = base64Decode;
|
1482
|
+
exports.base64Encode = base64Encode;
|
1483
|
+
exports.formatDecimal = formatDecimal;
|
1484
|
+
exports.generatorUUID = generatorUUID;
|
1485
|
+
exports.getBrowserInfo = getBrowserInfo;
|
1486
|
+
exports.getCookieTopLevelDomain = getCookieTopLevelDomain;
|
1487
|
+
exports.getCurrentDomain = getCurrentDomain;
|
1488
|
+
exports.getElementParents = getElementParents;
|
1489
|
+
exports.getElementProperties = getElementProperties;
|
1490
|
+
exports.getHostname = getHostname;
|
1491
|
+
exports.getInputElementContent = getInputElementContent;
|
1492
|
+
exports.getPageProperties = getPageProperties;
|
1493
|
+
exports.getQueryParam = getQueryParam;
|
1494
|
+
exports.getRandom = getRandom;
|
1495
|
+
exports.getReferrer = getReferrer;
|
1496
|
+
exports.getScreenHeight = getScreenHeight;
|
1497
|
+
exports.getScreenWidth = getScreenWidth;
|
1498
|
+
exports.getScrollLeft = getScrollLeft;
|
1499
|
+
exports.getScrollTop = getScrollTop;
|
1500
|
+
exports.getURL = getURL;
|
1501
|
+
exports.getURLSearchParams = getURLSearchParams;
|
1502
|
+
exports.getUmtsParams = getUmtsParams;
|
1503
|
+
exports.getUtm = getUtm;
|
1504
|
+
exports.handleDecodeURLComponent = handleDecodeURLComponent;
|
1505
|
+
exports.handleEncodeURLComponent = handleEncodeURLComponent;
|
1506
|
+
exports.isArray = isArray;
|
1507
|
+
exports.isBoolean = isBoolean;
|
1508
|
+
exports.isDate = isDate;
|
1509
|
+
exports.isElement = isElement;
|
1510
|
+
exports.isEmptyObject = isEmptyObject;
|
1511
|
+
exports.isFunction = isFunction;
|
1512
|
+
exports.isJSONString = isJSONString;
|
1513
|
+
exports.isNumber = isNumber;
|
1514
|
+
exports.isObject = isObject;
|
1515
|
+
exports.isReferralTraffic = isReferralTraffic;
|
1516
|
+
exports.isString = isString;
|
1517
|
+
exports.isUndefined = isUndefined;
|
1518
|
+
exports.isValid = isValid;
|
1519
|
+
exports.log = log;
|
1520
|
+
exports.merge = merge;
|
1521
|
+
exports.mitt = mitt;
|
1522
|
+
exports.networkType = networkType;
|
1523
|
+
exports.nextTick = nextTick;
|
1524
|
+
exports.noop = noop;
|
1525
|
+
exports.nowStamp = nowStamp;
|
1526
|
+
exports.replaceOld = replaceOld;
|
1527
|
+
exports.safeJSONParse = safeJSONParse;
|
1528
|
+
exports.searchKeywords = searchKeywords;
|
1529
|
+
exports.searchTypes = searchTypes;
|
1530
|
+
exports.socialTypes = socialTypes;
|
1531
|
+
exports.stripEmptyProperties = stripEmptyProperties;
|
1532
|
+
exports.supportConsole = supportConsole;
|
1533
|
+
exports.supportHistory = supportHistory;
|
1534
|
+
exports.utmTypes = utmTypes;
|
1535
|
+
//# sourceMappingURL=index.cjs.js.map
|