hina-cloud-js-sdk 3.1.6 → 3.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. package/.gitlab-ci.yml +2 -6
  2. package/build/hina.cjs.min.js +1 -0
  3. package/build/hina.esm.min.js +1 -0
  4. package/build/hina.min.js +1 -4
  5. package/build/hotAnalyse.min.js +1 -1
  6. package/package.json +2 -7
  7. package/packages/core/dist/index.cjs.js +64 -0
  8. package/packages/core/dist/index.cjs.js.map +1 -0
  9. package/packages/core/dist/index.d.ts +45 -0
  10. package/packages/core/dist/index.esm.js +62 -0
  11. package/packages/core/dist/index.esm.js.map +1 -0
  12. package/packages/core/dist/index.global.js +1199 -0
  13. package/packages/core/dist/index.global.js.map +1 -0
  14. package/packages/core/dist/index.js +1200 -0
  15. package/packages/core/dist/index.js.map +1 -0
  16. package/packages/monitor/dist/index.cjs.js +150 -0
  17. package/packages/monitor/dist/index.cjs.js.map +1 -0
  18. package/packages/monitor/dist/index.d.ts +35 -0
  19. package/packages/monitor/dist/index.esm.js +145 -0
  20. package/packages/monitor/dist/index.esm.js.map +1 -0
  21. package/packages/monitor/dist/index.global.js +1343 -0
  22. package/packages/monitor/dist/index.global.js.map +1 -0
  23. package/packages/monitor/dist/index.js +1344 -0
  24. package/packages/monitor/dist/index.js.map +1 -0
  25. package/packages/track/dist/index.cjs.js +1930 -0
  26. package/packages/track/dist/index.cjs.js.map +1 -0
  27. package/packages/track/dist/index.d.ts +212 -0
  28. package/packages/track/dist/index.esm.js +1925 -0
  29. package/packages/track/dist/index.esm.js.map +1 -0
  30. package/packages/track/dist/index.global.js +4259 -0
  31. package/packages/track/dist/index.global.js.map +1 -0
  32. package/packages/track/dist/index.js +4260 -0
  33. package/packages/track/dist/index.js.map +1 -0
  34. package/packages/types/dist/index.d.ts +603 -0
  35. package/packages/types/dist/index.esm.js +25 -0
  36. package/packages/types/dist/index.esm.js.map +1 -0
  37. package/packages/utils/dist/index.cjs.js +1535 -0
  38. package/packages/utils/dist/index.cjs.js.map +1 -0
  39. package/packages/utils/dist/index.d.ts +394 -0
  40. package/packages/utils/dist/index.esm.js +1465 -0
  41. package/packages/utils/dist/index.esm.js.map +1 -0
  42. package/packages/utils/dist/index.global.js +2507 -0
  43. package/packages/utils/dist/index.global.js.map +1 -0
  44. package/packages/utils/dist/index.js +2508 -0
  45. package/packages/utils/dist/index.js.map +1 -0
@@ -0,0 +1,4259 @@
1
+ var hinaDataStatistic = (function (exports) {
2
+ 'use strict';
3
+
4
+ /******************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
19
+
20
+ var extendStatics = function(d, b) {
21
+ extendStatics = Object.setPrototypeOf ||
22
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
23
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
24
+ return extendStatics(d, b);
25
+ };
26
+
27
+ function __extends(d, b) {
28
+ if (typeof b !== "function" && b !== null)
29
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
30
+ extendStatics(d, b);
31
+ function __() { this.constructor = d; }
32
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
33
+ }
34
+
35
+ var __assign = function() {
36
+ __assign = Object.assign || function __assign(t) {
37
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
38
+ s = arguments[i];
39
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
40
+ }
41
+ return t;
42
+ };
43
+ return __assign.apply(this, arguments);
44
+ };
45
+
46
+ function __values(o) {
47
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
48
+ if (m) return m.call(o);
49
+ if (o && typeof o.length === "number") return {
50
+ next: function () {
51
+ if (o && i >= o.length) o = void 0;
52
+ return { value: o && o[i++], done: !o };
53
+ }
54
+ };
55
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
56
+ }
57
+
58
+ function __read(o, n) {
59
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
60
+ if (!m) return o;
61
+ var i = m.call(o), r, ar = [], e;
62
+ try {
63
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
64
+ }
65
+ catch (error) { e = { error: error }; }
66
+ finally {
67
+ try {
68
+ if (r && !r.done && (m = i["return"])) m.call(i);
69
+ }
70
+ finally { if (e) throw e.error; }
71
+ }
72
+ return ar;
73
+ }
74
+
75
+ function __spreadArray(to, from, pack) {
76
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
77
+ if (ar || !(i in from)) {
78
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
79
+ ar[i] = from[i];
80
+ }
81
+ }
82
+ return to.concat(ar || Array.prototype.slice.call(from));
83
+ }
84
+
85
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
86
+ var e = new Error(message);
87
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
88
+ };
89
+
90
+ var ConsoleTypes;
91
+ (function (ConsoleTypes) {
92
+ ConsoleTypes["LOG"] = "log";
93
+ ConsoleTypes["INFO"] = "info";
94
+ ConsoleTypes["WARN"] = "warn";
95
+ ConsoleTypes["ERROR"] = "error";
96
+ ConsoleTypes["ASSERT"] = "assert";
97
+ })(ConsoleTypes || (ConsoleTypes = {}));
98
+ var ReportType;
99
+ (function (ReportType) {
100
+ ReportType["BEACON"] = "beacon";
101
+ ReportType["IMAGE"] = "image";
102
+ ReportType["AJAX"] = "ajax";
103
+ })(ReportType || (ReportType = {}));
104
+
105
+ var PluginBase = /** @class */ (function () {
106
+ function PluginBase(options, context) {
107
+ this.options = options;
108
+ this.context = context;
109
+ }
110
+ return PluginBase;
111
+ }());
112
+
113
+ var MAX_REFERRER_STRING_LENGTH = 2000;
114
+ var MAX_STRING_LENGTH = 1024 * 4;
115
+ var PV_LIB_VERSION = '4.0.0';
116
+ var COOKIE_TEST_NAME = 'hinasdk_domain_test';
117
+ var utmTypes = [
118
+ 'utm_source',
119
+ 'utm_medium',
120
+ 'utm_campaign',
121
+ 'utm_content',
122
+ 'utm_term'
123
+ ];
124
+ var searchTypes = [
125
+ 'www.baidu.',
126
+ 'm.baidu.',
127
+ 'm.sm.cn',
128
+ 'so.com',
129
+ 'sogou.com',
130
+ 'youdao.com',
131
+ 'google.',
132
+ 'yahoo.com/',
133
+ 'bing.com/',
134
+ 'ask.com/'
135
+ ];
136
+ var socialTypes = [
137
+ 'weibo.com',
138
+ 'renren.com',
139
+ 'kaixin001.com',
140
+ 'douban.com',
141
+ 'qzone.qq.com',
142
+ 'zhihu.com',
143
+ 'tieba.baidu.com',
144
+ 'weixin.qq.com'
145
+ ];
146
+ var searchKeywords = {
147
+ baidu: ['wd', 'word', 'kw', 'keyword'],
148
+ google: 'q',
149
+ bing: 'q',
150
+ yahoo: 'p',
151
+ sogou: ['query', 'keyword'],
152
+ so: 'q',
153
+ sm: 'q'
154
+ };
155
+
156
+ function isObject(val) {
157
+ return Object.prototype.toString.call(val) === '[object Object]';
158
+ }
159
+ function isValid(val) {
160
+ return val !== null && val !== undefined;
161
+ }
162
+ function isArray(val) {
163
+ return Array.isArray(val);
164
+ }
165
+ function isFunction(val) {
166
+ return typeof val === 'function';
167
+ }
168
+ function isString(val) {
169
+ return typeof val === 'string';
170
+ }
171
+ function isNumber(val) {
172
+ return typeof val === 'number';
173
+ }
174
+ function isBoolean(val) {
175
+ return typeof val === 'boolean';
176
+ }
177
+ function noop() { }
178
+ function isJSONString(val) {
179
+ try {
180
+ JSON.parse(val);
181
+ }
182
+ catch (e) {
183
+ return false;
184
+ }
185
+ return true;
186
+ }
187
+ function safeJSONParse(val) {
188
+ try {
189
+ return JSON.parse(val);
190
+ }
191
+ catch (e) { }
192
+ return val;
193
+ }
194
+ function isEmptyObject(obj) {
195
+ return Object.keys(obj).length === 0;
196
+ }
197
+ function nowStamp() {
198
+ if (Date.now && isFunction(Date.now)) {
199
+ return Date.now();
200
+ }
201
+ return new Date().getTime();
202
+ }
203
+ function merge() {
204
+ var args = [];
205
+ for (var _i = 0; _i < arguments.length; _i++) {
206
+ args[_i] = arguments[_i];
207
+ }
208
+ var result = Object.create(null);
209
+ args.forEach(function (obj) {
210
+ if (obj) {
211
+ Object.keys(obj).forEach(function (key) {
212
+ var val = obj[key];
213
+ if (isObject(val)) {
214
+ if (isObject(result[key])) {
215
+ result[key] = merge(result[key], val);
216
+ }
217
+ else {
218
+ result[key] = merge(val);
219
+ }
220
+ }
221
+ else {
222
+ result[key] = val;
223
+ }
224
+ });
225
+ }
226
+ });
227
+ return result;
228
+ }
229
+ function stripEmptyProperties(obj) {
230
+ return Object.keys(obj).reduce(function (acc, key) {
231
+ if (isValid(obj[key]) && obj[key] !== '') {
232
+ acc[key] = obj[key];
233
+ }
234
+ return acc;
235
+ }, {});
236
+ }
237
+ /**
238
+ * 返回URL对象
239
+ * @param url
240
+ */
241
+ function getURL(url) {
242
+ var urlObj = {};
243
+ try {
244
+ urlObj = new URL(url);
245
+ }
246
+ catch (e) { }
247
+ return urlObj;
248
+ }
249
+ /**
250
+ * 获取URL上的search参数
251
+ * @param queryString
252
+ */
253
+ function getURLSearchParams(queryString) {
254
+ queryString = queryString || '';
255
+ var args = {};
256
+ var searchParams = new URLSearchParams(queryString);
257
+ searchParams.forEach(function (value, key) {
258
+ args[key] = value;
259
+ });
260
+ return args;
261
+ }
262
+ function formatDecimal(num, decimal) {
263
+ if (!num) {
264
+ return num;
265
+ }
266
+ var str = num.toString();
267
+ var index = str.indexOf('.');
268
+ if (index !== -1) {
269
+ str = str.substring(0, index + decimal + 1);
270
+ }
271
+ else {
272
+ str = str.substring(0);
273
+ }
274
+ return parseFloat(str);
275
+ }
276
+ /**
277
+ * 获取cookie顶级域名
278
+ * @param hostname
279
+ */
280
+ function getCookieTopLevelDomain(hostname) {
281
+ hostname = hostname || window.location.hostname;
282
+ if (!/^[a-zA-Z0-9\u4e00-\u9fa5\-\\.]+$/.exec(hostname)) {
283
+ hostname = '';
284
+ }
285
+ var splitResult = hostname.split('.');
286
+ if (splitResult.length >= 2 && !/^(\d+\.)+\d+$/.test(hostname)) {
287
+ var domainStr = ".".concat(splitResult.splice(splitResult.length - 1, 1));
288
+ while (splitResult.length > 0) {
289
+ domainStr = ".".concat(splitResult.splice(splitResult.length - 1, 1)).concat(domainStr);
290
+ document.cookie = "".concat(COOKIE_TEST_NAME, "=true; path=/; domain=").concat(domainStr);
291
+ if (document.cookie.indexOf("".concat(COOKIE_TEST_NAME, "=true")) !== -1) {
292
+ document.cookie = "".concat(COOKIE_TEST_NAME, "=true; path=/; domain=").concat(domainStr, "; max-age=0");
293
+ return domainStr;
294
+ }
295
+ }
296
+ }
297
+ return '';
298
+ }
299
+ /**
300
+ * 获取当前页面的domain
301
+ * 注意这里的domain,并不是普通的window.location.hostname值,而是拥有相同子域名的域名,因为浏览器的cookie是二级域名共享的
302
+ */
303
+ function getCurrentDomain() {
304
+ var cookieDomain = getCookieTopLevelDomain();
305
+ if (cookieDomain === '') {
306
+ return 'url解析失败';
307
+ }
308
+ return cookieDomain;
309
+ }
310
+ /**
311
+ * 获取当前页面的referrer
312
+ */
313
+ function getReferrer(value) {
314
+ var referrer = value || document.referrer;
315
+ if (typeof referrer !== 'string') {
316
+ return "referrer exception".concat(String(referrer));
317
+ }
318
+ if (referrer.startsWith('https://www.baidu.com/')) {
319
+ referrer = referrer.split('?')[0];
320
+ }
321
+ referrer = referrer.slice(0, MAX_REFERRER_STRING_LENGTH);
322
+ return typeof referrer === 'string' ? referrer : '';
323
+ }
324
+ /**
325
+ * 获取hostname
326
+ * @param url
327
+ * @param defaultValue
328
+ */
329
+ function getHostname(url, defaultValue) {
330
+ if (!defaultValue || typeof defaultValue !== 'string') {
331
+ defaultValue = 'hostname解析异常';
332
+ }
333
+ if (!url) {
334
+ return defaultValue;
335
+ }
336
+ var hostname = getURL(url).hostname || '';
337
+ return hostname || defaultValue;
338
+ }
339
+ /**
340
+ * 此函数有两个作用
341
+ * 1:referrer为空时,直接返回true
342
+ * 2:referrer不为空时,判断是否是外链流量 document.referrer对应的hostname是否和当前URL的hostname是否相同
343
+ * @param referrer
344
+ */
345
+ function isReferralTraffic(referrer) {
346
+ referrer = referrer || document.referrer;
347
+ if (referrer === '') {
348
+ return true;
349
+ }
350
+ return (getCookieTopLevelDomain(getHostname(referrer)) !== getCookieTopLevelDomain());
351
+ }
352
+ /**
353
+ * 获取浏览器scrollTop
354
+ */
355
+ function getScrollTop() {
356
+ return document.documentElement.scrollTop || document.body.scrollTop || 0;
357
+ }
358
+ /**
359
+ * 获取浏览器scrollLeft
360
+ */
361
+ function getScrollLeft() {
362
+ return document.documentElement.scrollLeft || document.body.scrollLeft || 0;
363
+ }
364
+ /**
365
+ * 获取浏览器可视高度
366
+ */
367
+ function getScreenHeight() {
368
+ return (window.innerHeight ||
369
+ document.documentElement.clientHeight ||
370
+ document.body.clientHeight ||
371
+ 0);
372
+ }
373
+ /**
374
+ * 获取浏览器可视宽度
375
+ */
376
+ function getScreenWidth() {
377
+ return (window.innerWidth ||
378
+ document.documentElement.clientWidth ||
379
+ document.body.clientWidth ||
380
+ 0);
381
+ }
382
+ /**
383
+ * 获取浏览器网络类型
384
+ */
385
+ function networkType() {
386
+ if (navigator.connection === undefined)
387
+ return 'unknown';
388
+ var connection = navigator.connection;
389
+ if (connection.effectiveType) {
390
+ return connection.effectiveType;
391
+ }
392
+ if (connection.type) {
393
+ return connection.type;
394
+ }
395
+ return '取值异常';
396
+ }
397
+ /**
398
+ * 生成随机数
399
+ */
400
+ function getRandom() {
401
+ var date = new Date();
402
+ var seed = date.getTime();
403
+ var num = Math.floor(Math.random() * 1000000);
404
+ return "".concat(seed, "_").concat(num);
405
+ }
406
+ var ListenPageState = /** @class */ (function () {
407
+ function ListenPageState(payload) {
408
+ this.visibleHandler = function () { };
409
+ this.hiddenHandler = function () { };
410
+ var visible = payload.visible, hidden = payload.hidden;
411
+ if (isFunction(visible)) {
412
+ this.visibleHandler = visible;
413
+ }
414
+ if (isFunction(hidden)) {
415
+ this.hiddenHandler = hidden;
416
+ }
417
+ this.init();
418
+ }
419
+ ListenPageState.prototype.isSupport = function () {
420
+ return typeof document.hidden !== 'undefined';
421
+ };
422
+ ListenPageState.prototype.init = function () {
423
+ var _this = this;
424
+ if (this.isSupport()) {
425
+ document.addEventListener('visibilitychange', function () {
426
+ if (document.hidden) {
427
+ _this.hiddenHandler();
428
+ }
429
+ else {
430
+ _this.visibleHandler();
431
+ }
432
+ });
433
+ }
434
+ else {
435
+ window.addEventListener('focus', this.visibleHandler);
436
+ window.addEventListener('blur', this.hiddenHandler);
437
+ }
438
+ };
439
+ return ListenPageState;
440
+ }());
441
+ function generatorUUID() {
442
+ var T = function () {
443
+ var d = nowStamp();
444
+ var i = 0;
445
+ while (d === nowStamp()) {
446
+ i++;
447
+ }
448
+ return d.toString(16) + i.toString(16);
449
+ };
450
+ var R = function () {
451
+ return Math.random().toString(16).replace('.', '');
452
+ };
453
+ var UA = function () {
454
+ var ua = navigator.userAgent;
455
+ var i;
456
+ var ch;
457
+ var buffer = [];
458
+ var ret = 0;
459
+ function xor(result, byteArray) {
460
+ var j;
461
+ var tmp = 0;
462
+ for (j = 0; j < byteArray.length; j++) {
463
+ tmp |= buffer[j] << (j * 8);
464
+ }
465
+ return result ^ tmp;
466
+ }
467
+ for (i = 0; i < ua.length; i++) {
468
+ ch = ua.charCodeAt(i);
469
+ buffer.unshift(ch & 0xff);
470
+ if (buffer.length >= 4) {
471
+ ret = xor(ret, buffer);
472
+ buffer = [];
473
+ }
474
+ }
475
+ if (buffer.length > 0) {
476
+ ret = xor(ret, buffer);
477
+ }
478
+ return ret.toString(16);
479
+ };
480
+ var se = String(window.screen.height * window.screen.width);
481
+ if (se && /\d{5,}/.test(se)) {
482
+ // @ts-ignore
483
+ se = se.toString(16);
484
+ }
485
+ else {
486
+ se = String(Math.random() * 31242)
487
+ .replace('.', '')
488
+ .slice(0, 8);
489
+ }
490
+ var val = "".concat(T(), "-").concat(R(), "-").concat(UA(), "-").concat(se, "-").concat(T());
491
+ if (val) {
492
+ return val;
493
+ }
494
+ return (String(Math.random()) +
495
+ String(Math.random()) +
496
+ String(Math.random())).slice(2, 15);
497
+ }
498
+ /**
499
+ * 查找指定url中的参数
500
+ * replace(/[\[]/, "\\[") 将 [ 替换为 \[。
501
+ * replace(/[\]]/, "\\]") 将 ] 替换为 \]。
502
+ * example[123]=>example\[123\]
503
+ * @param url
504
+ * @param key
505
+ */
506
+ function getQueryParam(url, key) {
507
+ key = key.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
508
+ url = decodeURIComponent(url);
509
+ var regex = new RegExp("[\\?&]".concat(key, "=([^&#]*)"));
510
+ var results = regex.exec(url);
511
+ if (results === null ||
512
+ (results && typeof results[1] !== 'string' && results[1].length)) {
513
+ return '';
514
+ }
515
+ return decodeURIComponent(results[1]);
516
+ }
517
+ function base64Encode(str) {
518
+ try {
519
+ return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (e, t) {
520
+ return String.fromCharCode(Number("0x".concat(t)));
521
+ }));
522
+ }
523
+ catch (e) {
524
+ return str;
525
+ }
526
+ }
527
+ function handleDecodeURLComponent(val) {
528
+ var result = val;
529
+ try {
530
+ result = decodeURIComponent(val);
531
+ }
532
+ catch (e) { }
533
+ return result;
534
+ }
535
+ function handleEncodeURLComponent(val) {
536
+ var result = val;
537
+ try {
538
+ result = encodeURIComponent(val);
539
+ }
540
+ catch (e) { }
541
+ return result;
542
+ }
543
+ /**
544
+ * 对原生方法进行重写
545
+ * @param source 需要被重写的对象
546
+ * @param name 重写方法名
547
+ * @param replacement 重写方法
548
+ * @param isForced 是否强制重写(可能原先没有该属性)
549
+ */
550
+ function replaceOld(source, name, replacement, isForced) {
551
+ if (source === undefined)
552
+ return;
553
+ if (name in source || isForced) {
554
+ var original = source[name];
555
+ var wrapped = replacement(original);
556
+ if (isFunction(wrapped)) {
557
+ source[name] = wrapped;
558
+ }
559
+ }
560
+ }
561
+ function supportHistory() {
562
+ return window && !!window.history.pushState && !!window.history.replaceState;
563
+ }
564
+
565
+ /**
566
+ * cookie 操作
567
+ */
568
+ var CookieStorage = /** @class */ (function () {
569
+ function CookieStorage() {
570
+ this.name = 'CookieStorage';
571
+ }
572
+ /**
573
+ * 用于判断是否支持cookie
574
+ * @param testKey
575
+ * @param testValue
576
+ */
577
+ CookieStorage.prototype.isSupport = function (testKey, testValue) {
578
+ var _this = this;
579
+ if (testKey === void 0) { testKey = 'cookie_support_test'; }
580
+ if (testValue === void 0) { testValue = '1'; }
581
+ var test = function () {
582
+ _this.set(testKey, testValue);
583
+ var value = _this.get(testKey);
584
+ if (value !== testValue)
585
+ return false;
586
+ _this.remove(testKey);
587
+ return true;
588
+ };
589
+ return navigator.cookieEnabled && test();
590
+ };
591
+ /**
592
+ * 获取指定的cookie值
593
+ * @param name
594
+ */
595
+ CookieStorage.prototype.get = function (name) {
596
+ var e_1, _a;
597
+ var cookieList = document.cookie.split(';');
598
+ try {
599
+ for (var cookieList_1 = __values(cookieList), cookieList_1_1 = cookieList_1.next(); !cookieList_1_1.done; cookieList_1_1 = cookieList_1.next()) {
600
+ var cookie = cookieList_1_1.value;
601
+ var cookiePair = cookie.split('=');
602
+ if (cookiePair[0].trim() === name) {
603
+ return decodeURIComponent(cookiePair[1]);
604
+ }
605
+ }
606
+ }
607
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
608
+ finally {
609
+ try {
610
+ if (cookieList_1_1 && !cookieList_1_1.done && (_a = cookieList_1.return)) _a.call(cookieList_1);
611
+ }
612
+ finally { if (e_1) throw e_1.error; }
613
+ }
614
+ // 如果没有找到对应的cookie,则返回null
615
+ return null;
616
+ };
617
+ /**
618
+ * 设置cookie
619
+ * @param name cookie名称
620
+ * @param value cookie值
621
+ * @param timeStamp 过期时间戳 单位s
622
+ * @param path 路径
623
+ * @param domain cookie域名
624
+ * @param sameSite 跨域设置
625
+ * @param secure 是否仅通过 HTTPS 协议传输
626
+ */
627
+ CookieStorage.prototype.set = function (name, value, timeStamp, path, domain, sameSite, secure) {
628
+ path = path || '/';
629
+ name = name.trim();
630
+ value = value.trim();
631
+ var cookieStr = "".concat(name, "=").concat(encodeURIComponent(value), "; path=").concat(path, ";");
632
+ timeStamp = isValid(timeStamp) ? timeStamp : 73000;
633
+ // 设置过期时间
634
+ cookieStr += " max-age=".concat(timeStamp, ";");
635
+ // 是否仅通过 HTTPS 协议传输
636
+ if (secure) {
637
+ cookieStr += ' secure;';
638
+ }
639
+ // 设置域名
640
+ if (domain) {
641
+ cookieStr += " domain=".concat(domain, ";");
642
+ }
643
+ // 设置跨域
644
+ if (['Strict', 'Lax', 'None'].includes(sameSite)) {
645
+ cookieStr += " SameSite=".concat(sameSite, ";");
646
+ }
647
+ document.cookie = cookieStr;
648
+ };
649
+ /**
650
+ * 删除指定cookie
651
+ * @param name
652
+ * @param path
653
+ */
654
+ CookieStorage.prototype.remove = function (name, path) {
655
+ if (path === void 0) { path = '/'; }
656
+ this.set(name, '1', 0, path);
657
+ };
658
+ /**
659
+ * 将cookie设置到当前子域名下,用于跨站共享
660
+ * @param name
661
+ * @param value
662
+ * @param timeStamp
663
+ */
664
+ CookieStorage.prototype.setDomain = function (name, value, timeStamp) {
665
+ var domain = getCurrentDomain();
666
+ if (domain === 'url解析失败') {
667
+ domain = '';
668
+ }
669
+ this.set(name, value, timeStamp, '/', domain);
670
+ };
671
+ return CookieStorage;
672
+ }());
673
+ /**
674
+ * localStorage 操作
675
+ */
676
+ var LocalStorage = /** @class */ (function () {
677
+ function LocalStorage() {
678
+ this.name = 'LocalStorage';
679
+ }
680
+ /**
681
+ * 判断是否支持localStorage
682
+ */
683
+ LocalStorage.prototype.isSupport = function () {
684
+ var supported = true;
685
+ try {
686
+ var supportName = '__localStorageSupport__';
687
+ var val = 'testIsSupportStorage';
688
+ this.set(supportName, val);
689
+ if (this.get(supportName) !== val) {
690
+ supported = false;
691
+ }
692
+ this.remove(supportName);
693
+ }
694
+ catch (e) {
695
+ supported = false;
696
+ }
697
+ return supported;
698
+ };
699
+ LocalStorage.prototype.key = function (index) {
700
+ return window.localStorage.key(index);
701
+ };
702
+ LocalStorage.prototype.get = function (key) {
703
+ return window.localStorage.getItem(key);
704
+ };
705
+ LocalStorage.prototype.length = function () {
706
+ return window.localStorage.length;
707
+ };
708
+ LocalStorage.prototype.set = function (key, value) {
709
+ try {
710
+ window.localStorage.setItem(key, value);
711
+ }
712
+ catch (e) { }
713
+ };
714
+ LocalStorage.prototype.remove = function (key) {
715
+ window.localStorage.removeItem(key);
716
+ };
717
+ LocalStorage.prototype.parse = function (key) {
718
+ var result = this.get(key);
719
+ try {
720
+ result = JSON.parse(result);
721
+ }
722
+ catch (e) {
723
+ result = '';
724
+ }
725
+ return result;
726
+ };
727
+ return LocalStorage;
728
+ }());
729
+ /**
730
+ * memoryStorage 操作
731
+ */
732
+ var MemoryStorage = /** @class */ (function () {
733
+ function MemoryStorage() {
734
+ this.name = 'MemoryStorage';
735
+ this.data = {};
736
+ }
737
+ MemoryStorage.prototype.get = function (key) {
738
+ var result = this.data[key];
739
+ if (isValid(result === null || result === void 0 ? void 0 : result.expireTime)) {
740
+ if (result.expireTime < nowStamp()) {
741
+ return null;
742
+ }
743
+ return result.value;
744
+ }
745
+ return result === null || result === void 0 ? void 0 : result.value;
746
+ };
747
+ /**
748
+ * 存储数据
749
+ * @param key
750
+ * @param value
751
+ * @param expires 单位 s
752
+ */
753
+ MemoryStorage.prototype.set = function (key, value, expires) {
754
+ if (isValid(expires)) {
755
+ var expireTime = nowStamp() + expires * 1000;
756
+ this.data[key] = {
757
+ value: value,
758
+ expireTime: expireTime
759
+ };
760
+ }
761
+ this.data[key] = { value: value };
762
+ };
763
+ MemoryStorage.prototype.setDomain = function (name, value, timeStamp) {
764
+ this.set(name, value, timeStamp);
765
+ };
766
+ return MemoryStorage;
767
+ }());
768
+
769
+ function isElement(val) {
770
+ return (val === null || val === void 0 ? void 0 : val.nodeType) === 1;
771
+ }
772
+ /**
773
+ * 获取指定元素以及其父元素组成的路径
774
+ * @param element
775
+ */
776
+ function getElementParents(element) {
777
+ var pathArr = [element];
778
+ try {
779
+ if (!isElement(element)) {
780
+ return pathArr;
781
+ }
782
+ if (element === null || element.parentElement === null) {
783
+ return pathArr;
784
+ }
785
+ while (element.parentElement !== null) {
786
+ element = element.parentElement;
787
+ pathArr.push(element);
788
+ }
789
+ return pathArr;
790
+ }
791
+ catch (error) { }
792
+ return pathArr;
793
+ }
794
+ /**
795
+ * 获取input元素的内容
796
+ * @param element
797
+ * @param isCollectInput 是否采集input
798
+ */
799
+ function getInputElementContent(element, isCollectInput) {
800
+ var _a;
801
+ var tagName = (_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
802
+ if (tagName === 'input') {
803
+ if (['button', 'submit'].includes(element.type) || isCollectInput) {
804
+ return element.value || '';
805
+ }
806
+ return '';
807
+ }
808
+ var textContent = '';
809
+ if (element.textContent) {
810
+ textContent = element.textContent.trim();
811
+ }
812
+ else if (element.innerText) {
813
+ textContent = element.innerText.trim();
814
+ }
815
+ if (textContent) {
816
+ textContent = textContent
817
+ .replace(/[\r\n]/g, ' ')
818
+ .replace(/[ ]+/g, ' ')
819
+ .substring(0, 255);
820
+ }
821
+ return textContent || '';
822
+ }
823
+ /**
824
+ * 获取元素信息
825
+ * @param element 元素
826
+ * @param isCollectInput 是否采集input
827
+ */
828
+ function getElementProperties(element, isCollectInput) {
829
+ var _a;
830
+ if (!isElement(element))
831
+ return {};
832
+ var tagName = (_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
833
+ var props = {
834
+ H_element_type: tagName,
835
+ H_element_name: element.getAttribute('name'),
836
+ H_element_id: element.getAttribute('id'),
837
+ H_element_target_url: element.getAttribute('href'),
838
+ H_element_class_name: element.getAttribute('className'),
839
+ H_element_content: getInputElementContent(element, isCollectInput)
840
+ };
841
+ return stripEmptyProperties(props);
842
+ }
843
+ /**
844
+ * 获取页面信息
845
+ */
846
+ function getPageProperties() {
847
+ var referrer = getReferrer();
848
+ var url_domain = getCurrentDomain();
849
+ var viewportPosition = Math.round(getScrollTop());
850
+ var props = {
851
+ H_referrer: referrer,
852
+ H_referrer_host: referrer ? getHostname(referrer) : '',
853
+ H_url: window.location.href,
854
+ H_url_host: getHostname(window.location.href, 'url_host取值异常'),
855
+ H_url_domain: url_domain,
856
+ H_url_path: window.location.pathname,
857
+ H_url_hash: window.location.hash,
858
+ H_title: document.title,
859
+ H_viewport_position: viewportPosition
860
+ };
861
+ return stripEmptyProperties(props);
862
+ }
863
+
864
+ var SearchKeyword = /** @class */ (function () {
865
+ function SearchKeyword() {
866
+ }
867
+ SearchKeyword.getSourceFromReferrer = function () {
868
+ var getMatchStrFromArr = function (arr, str) {
869
+ for (var i = 0; i < arr.length; i++) {
870
+ if (str.split('?')[0].indexOf(arr[i]) !== -1) {
871
+ return true;
872
+ }
873
+ }
874
+ };
875
+ var utm_reg = "(".concat(utmTypes.join('|'), ")\\=[^&]+");
876
+ var referrer = document.referrer || '';
877
+ var url = window.location.href;
878
+ if (url) {
879
+ var utm_match = url.match(new RegExp(utm_reg));
880
+ if (utm_match && utm_match[0]) {
881
+ return '付费广告流量';
882
+ }
883
+ if (getMatchStrFromArr(searchTypes, referrer)) {
884
+ return '自然搜索流量';
885
+ }
886
+ if (getMatchStrFromArr(socialTypes, referrer)) {
887
+ return '社交网站流量';
888
+ }
889
+ if (referrer === '') {
890
+ return '直接流量';
891
+ }
892
+ return '引荐流量';
893
+ }
894
+ return '获取url异常';
895
+ };
896
+ SearchKeyword.getReferSearchEngine = function (referrerUrl) {
897
+ var e_1, _a;
898
+ var hostname = getHostname(referrerUrl);
899
+ if (!hostname || hostname === 'hostname解析异常') {
900
+ return '';
901
+ }
902
+ var regexps = {
903
+ baidu: [/^.*\.baidu\.com$/],
904
+ bing: [/^.*\.bing\.com$/],
905
+ google: [
906
+ /^www\.google\.com$/,
907
+ /^www\.google\.com\.[a-z]{2}$/,
908
+ /^www\.google\.[a-z]{2}$/
909
+ ],
910
+ sm: [/^m\.sm\.cn$/],
911
+ so: [/^.+\.so\.com$/],
912
+ sogou: [/^.*\.sogou\.com$/],
913
+ yahoo: [/^.*\.yahoo\.com$/]
914
+ };
915
+ for (var regexp in regexps) {
916
+ var regexList = regexps[regexp];
917
+ try {
918
+ 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()) {
919
+ var regex = regexList_1_1.value;
920
+ if (regex.test(hostname)) {
921
+ return regexp;
922
+ }
923
+ }
924
+ }
925
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
926
+ finally {
927
+ try {
928
+ if (regexList_1_1 && !regexList_1_1.done && (_a = regexList_1.return)) _a.call(regexList_1);
929
+ }
930
+ finally { if (e_1) throw e_1.error; }
931
+ }
932
+ }
933
+ return '未知搜索引擎';
934
+ };
935
+ SearchKeyword.getKeywordFromReferrer = function () {
936
+ var referrerUrl = document.referrer || '';
937
+ if (referrerUrl.indexOf('http') === 0) {
938
+ var searchEngine = this.getReferSearchEngine(referrerUrl);
939
+ var query = getURLSearchParams(getURL(referrerUrl).search);
940
+ if (isEmptyObject(query)) {
941
+ return '未取到值';
942
+ }
943
+ for (var key in searchKeywords) {
944
+ var value = searchKeywords[key];
945
+ if (key === searchEngine) {
946
+ if (isArray(value)) {
947
+ for (var i = 0; i < value.length; i++) {
948
+ var val = query[value[i]];
949
+ if (val) {
950
+ return val;
951
+ }
952
+ }
953
+ }
954
+ else if (query[value]) {
955
+ return query[value];
956
+ }
957
+ }
958
+ }
959
+ return '未取到值';
960
+ }
961
+ if (referrerUrl === '') {
962
+ return '未取到值_直接打开';
963
+ }
964
+ return '未取到值_非http的url';
965
+ };
966
+ return SearchKeyword;
967
+ }());
968
+ /**
969
+ * 广告参数
970
+ * @param prefix
971
+ */
972
+ function getUmtsParams(prefix) {
973
+ if (prefix === void 0) { prefix = ''; }
974
+ var utms = getUtm();
975
+ var allUtms = {};
976
+ Object.keys(utms).forEach(function (key) {
977
+ allUtms[prefix + key] = utms[key];
978
+ });
979
+ return allUtms;
980
+ }
981
+ function getUtm() {
982
+ var params = {};
983
+ utmTypes.forEach(function (key) {
984
+ var result = getQueryParam(window.location.href, key);
985
+ if (result.length) {
986
+ params[key] = result;
987
+ }
988
+ });
989
+ return params;
990
+ }
991
+
992
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
993
+
994
+ function getDefaultExportFromCjs (x) {
995
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
996
+ }
997
+
998
+ var uaParser = {exports: {}};
999
+
1000
+ (function (module, exports) {
1001
+ /////////////////////////////////////////////////////////////////////////////////
1002
+ /* UAParser.js v1.0.38
1003
+ Copyright © 2012-2021 Faisal Salman <f@faisalman.com>
1004
+ MIT License *//*
1005
+ Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data.
1006
+ Supports browser & node.js environment.
1007
+ Demo : https://faisalman.github.io/ua-parser-js
1008
+ Source : https://github.com/faisalman/ua-parser-js */
1009
+ /////////////////////////////////////////////////////////////////////////////////
1010
+
1011
+ (function (window, undefined$1) {
1012
+
1013
+ //////////////
1014
+ // Constants
1015
+ /////////////
1016
+
1017
+
1018
+ var LIBVERSION = '1.0.38',
1019
+ EMPTY = '',
1020
+ UNKNOWN = '?',
1021
+ FUNC_TYPE = 'function',
1022
+ UNDEF_TYPE = 'undefined',
1023
+ OBJ_TYPE = 'object',
1024
+ STR_TYPE = 'string',
1025
+ MAJOR = 'major',
1026
+ MODEL = 'model',
1027
+ NAME = 'name',
1028
+ TYPE = 'type',
1029
+ VENDOR = 'vendor',
1030
+ VERSION = 'version',
1031
+ ARCHITECTURE= 'architecture',
1032
+ CONSOLE = 'console',
1033
+ MOBILE = 'mobile',
1034
+ TABLET = 'tablet',
1035
+ SMARTTV = 'smarttv',
1036
+ WEARABLE = 'wearable',
1037
+ EMBEDDED = 'embedded',
1038
+ UA_MAX_LENGTH = 500;
1039
+
1040
+ var AMAZON = 'Amazon',
1041
+ APPLE = 'Apple',
1042
+ ASUS = 'ASUS',
1043
+ BLACKBERRY = 'BlackBerry',
1044
+ BROWSER = 'Browser',
1045
+ CHROME = 'Chrome',
1046
+ EDGE = 'Edge',
1047
+ FIREFOX = 'Firefox',
1048
+ GOOGLE = 'Google',
1049
+ HUAWEI = 'Huawei',
1050
+ LG = 'LG',
1051
+ MICROSOFT = 'Microsoft',
1052
+ MOTOROLA = 'Motorola',
1053
+ OPERA = 'Opera',
1054
+ SAMSUNG = 'Samsung',
1055
+ SHARP = 'Sharp',
1056
+ SONY = 'Sony',
1057
+ XIAOMI = 'Xiaomi',
1058
+ ZEBRA = 'Zebra',
1059
+ FACEBOOK = 'Facebook',
1060
+ CHROMIUM_OS = 'Chromium OS',
1061
+ MAC_OS = 'Mac OS';
1062
+
1063
+ ///////////
1064
+ // Helper
1065
+ //////////
1066
+
1067
+ var extend = function (regexes, extensions) {
1068
+ var mergedRegexes = {};
1069
+ for (var i in regexes) {
1070
+ if (extensions[i] && extensions[i].length % 2 === 0) {
1071
+ mergedRegexes[i] = extensions[i].concat(regexes[i]);
1072
+ } else {
1073
+ mergedRegexes[i] = regexes[i];
1074
+ }
1075
+ }
1076
+ return mergedRegexes;
1077
+ },
1078
+ enumerize = function (arr) {
1079
+ var enums = {};
1080
+ for (var i=0; i<arr.length; i++) {
1081
+ enums[arr[i].toUpperCase()] = arr[i];
1082
+ }
1083
+ return enums;
1084
+ },
1085
+ has = function (str1, str2) {
1086
+ return typeof str1 === STR_TYPE ? lowerize(str2).indexOf(lowerize(str1)) !== -1 : false;
1087
+ },
1088
+ lowerize = function (str) {
1089
+ return str.toLowerCase();
1090
+ },
1091
+ majorize = function (version) {
1092
+ return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g, EMPTY).split('.')[0] : undefined$1;
1093
+ },
1094
+ trim = function (str, len) {
1095
+ if (typeof(str) === STR_TYPE) {
1096
+ str = str.replace(/^\s\s*/, EMPTY);
1097
+ return typeof(len) === UNDEF_TYPE ? str : str.substring(0, UA_MAX_LENGTH);
1098
+ }
1099
+ };
1100
+
1101
+ ///////////////
1102
+ // Map helper
1103
+ //////////////
1104
+
1105
+ var rgxMapper = function (ua, arrays) {
1106
+
1107
+ var i = 0, j, k, p, q, matches, match;
1108
+
1109
+ // loop through all regexes maps
1110
+ while (i < arrays.length && !matches) {
1111
+
1112
+ var regex = arrays[i], // even sequence (0,2,4,..)
1113
+ props = arrays[i + 1]; // odd sequence (1,3,5,..)
1114
+ j = k = 0;
1115
+
1116
+ // try matching uastring with regexes
1117
+ while (j < regex.length && !matches) {
1118
+
1119
+ if (!regex[j]) { break; }
1120
+ matches = regex[j++].exec(ua);
1121
+
1122
+ if (!!matches) {
1123
+ for (p = 0; p < props.length; p++) {
1124
+ match = matches[++k];
1125
+ q = props[p];
1126
+ // check if given property is actually array
1127
+ if (typeof q === OBJ_TYPE && q.length > 0) {
1128
+ if (q.length === 2) {
1129
+ if (typeof q[1] == FUNC_TYPE) {
1130
+ // assign modified match
1131
+ this[q[0]] = q[1].call(this, match);
1132
+ } else {
1133
+ // assign given value, ignore regex match
1134
+ this[q[0]] = q[1];
1135
+ }
1136
+ } else if (q.length === 3) {
1137
+ // check whether function or regex
1138
+ if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
1139
+ // call function (usually string mapper)
1140
+ this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined$1;
1141
+ } else {
1142
+ // sanitize match using given regex
1143
+ this[q[0]] = match ? match.replace(q[1], q[2]) : undefined$1;
1144
+ }
1145
+ } else if (q.length === 4) {
1146
+ this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined$1;
1147
+ }
1148
+ } else {
1149
+ this[q] = match ? match : undefined$1;
1150
+ }
1151
+ }
1152
+ }
1153
+ }
1154
+ i += 2;
1155
+ }
1156
+ },
1157
+
1158
+ strMapper = function (str, map) {
1159
+
1160
+ for (var i in map) {
1161
+ // check if current value is array
1162
+ if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
1163
+ for (var j = 0; j < map[i].length; j++) {
1164
+ if (has(map[i][j], str)) {
1165
+ return (i === UNKNOWN) ? undefined$1 : i;
1166
+ }
1167
+ }
1168
+ } else if (has(map[i], str)) {
1169
+ return (i === UNKNOWN) ? undefined$1 : i;
1170
+ }
1171
+ }
1172
+ return str;
1173
+ };
1174
+
1175
+ ///////////////
1176
+ // String map
1177
+ //////////////
1178
+
1179
+ // Safari < 3.0
1180
+ var oldSafariMap = {
1181
+ '1.0' : '/8',
1182
+ '1.2' : '/1',
1183
+ '1.3' : '/3',
1184
+ '2.0' : '/412',
1185
+ '2.0.2' : '/416',
1186
+ '2.0.3' : '/417',
1187
+ '2.0.4' : '/419',
1188
+ '?' : '/'
1189
+ },
1190
+ windowsVersionMap = {
1191
+ 'ME' : '4.90',
1192
+ 'NT 3.11' : 'NT3.51',
1193
+ 'NT 4.0' : 'NT4.0',
1194
+ '2000' : 'NT 5.0',
1195
+ 'XP' : ['NT 5.1', 'NT 5.2'],
1196
+ 'Vista' : 'NT 6.0',
1197
+ '7' : 'NT 6.1',
1198
+ '8' : 'NT 6.2',
1199
+ '8.1' : 'NT 6.3',
1200
+ '10' : ['NT 6.4', 'NT 10.0'],
1201
+ 'RT' : 'ARM'
1202
+ };
1203
+
1204
+ //////////////
1205
+ // Regex map
1206
+ /////////////
1207
+
1208
+ var regexes = {
1209
+
1210
+ browser : [[
1211
+
1212
+ /\b(?:crmo|crios)\/([\w\.]+)/i // Chrome for Android/iOS
1213
+ ], [VERSION, [NAME, 'Chrome']], [
1214
+ /edg(?:e|ios|a)?\/([\w\.]+)/i // Microsoft Edge
1215
+ ], [VERSION, [NAME, 'Edge']], [
1216
+
1217
+ // Presto based
1218
+ /(opera mini)\/([-\w\.]+)/i, // Opera Mini
1219
+ /(opera [mobiletab]{3,6})\b.+version\/([-\w\.]+)/i, // Opera Mobi/Tablet
1220
+ /(opera)(?:.+version\/|[\/ ]+)([\w\.]+)/i // Opera
1221
+ ], [NAME, VERSION], [
1222
+ /opios[\/ ]+([\w\.]+)/i // Opera mini on iphone >= 8.0
1223
+ ], [VERSION, [NAME, OPERA+' Mini']], [
1224
+ /\bop(?:rg)?x\/([\w\.]+)/i // Opera GX
1225
+ ], [VERSION, [NAME, OPERA+' GX']], [
1226
+ /\bopr\/([\w\.]+)/i // Opera Webkit
1227
+ ], [VERSION, [NAME, OPERA]], [
1228
+
1229
+ // Mixed
1230
+ /\bb[ai]*d(?:uhd|[ub]*[aekoprswx]{5,6})[\/ ]?([\w\.]+)/i // Baidu
1231
+ ], [VERSION, [NAME, 'Baidu']], [
1232
+ /(kindle)\/([\w\.]+)/i, // Kindle
1233
+ /(lunascape|maxthon|netfront|jasmine|blazer)[\/ ]?([\w\.]*)/i, // Lunascape/Maxthon/Netfront/Jasmine/Blazer
1234
+ // Trident based
1235
+ /(avant|iemobile|slim)\s?(?:browser)?[\/ ]?([\w\.]*)/i, // Avant/IEMobile/SlimBrowser
1236
+ /(?:ms|\()(ie) ([\w\.]+)/i, // Internet Explorer
1237
+
1238
+ // Webkit/KHTML based // Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
1239
+ /(flock|rockmelt|midori|epiphany|silk|skyfire|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon|rekonq|puffin|brave|whale(?!.+naver)|qqbrowserlite|qq|duckduckgo)\/([-\w\.]+)/i,
1240
+ // Rekonq/Puffin/Brave/Whale/QQBrowserLite/QQ, aka ShouQ
1241
+ /(heytap|ovi)browser\/([\d\.]+)/i, // Heytap/Ovi
1242
+ /(weibo)__([\d\.]+)/i // Weibo
1243
+ ], [NAME, VERSION], [
1244
+ /\bddg\/([\w\.]+)/i // DuckDuckGo
1245
+ ], [VERSION, [NAME, 'DuckDuckGo']], [
1246
+ /(?:\buc? ?browser|(?:juc.+)ucweb)[\/ ]?([\w\.]+)/i // UCBrowser
1247
+ ], [VERSION, [NAME, 'UC'+BROWSER]], [
1248
+ /microm.+\bqbcore\/([\w\.]+)/i, // WeChat Desktop for Windows Built-in Browser
1249
+ /\bqbcore\/([\w\.]+).+microm/i,
1250
+ /micromessenger\/([\w\.]+)/i // WeChat
1251
+ ], [VERSION, [NAME, 'WeChat']], [
1252
+ /konqueror\/([\w\.]+)/i // Konqueror
1253
+ ], [VERSION, [NAME, 'Konqueror']], [
1254
+ /trident.+rv[: ]([\w\.]{1,9})\b.+like gecko/i // IE11
1255
+ ], [VERSION, [NAME, 'IE']], [
1256
+ /ya(?:search)?browser\/([\w\.]+)/i // Yandex
1257
+ ], [VERSION, [NAME, 'Yandex']], [
1258
+ /slbrowser\/([\w\.]+)/i // Smart Lenovo Browser
1259
+ ], [VERSION, [NAME, 'Smart Lenovo '+BROWSER]], [
1260
+ /(avast|avg)\/([\w\.]+)/i // Avast/AVG Secure Browser
1261
+ ], [[NAME, /(.+)/, '$1 Secure '+BROWSER], VERSION], [
1262
+ /\bfocus\/([\w\.]+)/i // Firefox Focus
1263
+ ], [VERSION, [NAME, FIREFOX+' Focus']], [
1264
+ /\bopt\/([\w\.]+)/i // Opera Touch
1265
+ ], [VERSION, [NAME, OPERA+' Touch']], [
1266
+ /coc_coc\w+\/([\w\.]+)/i // Coc Coc Browser
1267
+ ], [VERSION, [NAME, 'Coc Coc']], [
1268
+ /dolfin\/([\w\.]+)/i // Dolphin
1269
+ ], [VERSION, [NAME, 'Dolphin']], [
1270
+ /coast\/([\w\.]+)/i // Opera Coast
1271
+ ], [VERSION, [NAME, OPERA+' Coast']], [
1272
+ /miuibrowser\/([\w\.]+)/i // MIUI Browser
1273
+ ], [VERSION, [NAME, 'MIUI '+BROWSER]], [
1274
+ /fxios\/([-\w\.]+)/i // Firefox for iOS
1275
+ ], [VERSION, [NAME, FIREFOX]], [
1276
+ /\bqihu|(qi?ho?o?|360)browser/i // 360
1277
+ ], [[NAME, '360 ' + BROWSER]], [
1278
+ /(oculus|sailfish|huawei|vivo)browser\/([\w\.]+)/i
1279
+ ], [[NAME, /(.+)/, '$1 ' + BROWSER], VERSION], [ // Oculus/Sailfish/HuaweiBrowser/VivoBrowser
1280
+ /samsungbrowser\/([\w\.]+)/i // Samsung Internet
1281
+ ], [VERSION, [NAME, SAMSUNG + ' Internet']], [
1282
+ /(comodo_dragon)\/([\w\.]+)/i // Comodo Dragon
1283
+ ], [[NAME, /_/g, ' '], VERSION], [
1284
+ /metasr[\/ ]?([\d\.]+)/i // Sogou Explorer
1285
+ ], [VERSION, [NAME, 'Sogou Explorer']], [
1286
+ /(sogou)mo\w+\/([\d\.]+)/i // Sogou Mobile
1287
+ ], [[NAME, 'Sogou Mobile'], VERSION], [
1288
+ /(electron)\/([\w\.]+) safari/i, // Electron-based App
1289
+ /(tesla)(?: qtcarbrowser|\/(20\d\d\.[-\w\.]+))/i, // Tesla
1290
+ /m?(qqbrowser|2345Explorer)[\/ ]?([\w\.]+)/i // QQBrowser/2345 Browser
1291
+ ], [NAME, VERSION], [
1292
+ /(lbbrowser)/i, // LieBao Browser
1293
+ /\[(linkedin)app\]/i // LinkedIn App for iOS & Android
1294
+ ], [NAME], [
1295
+
1296
+ // WebView
1297
+ /((?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/([\w\.]+);)/i // Facebook App for iOS & Android
1298
+ ], [[NAME, FACEBOOK], VERSION], [
1299
+ /(Klarna)\/([\w\.]+)/i, // Klarna Shopping Browser for iOS & Android
1300
+ /(kakao(?:talk|story))[\/ ]([\w\.]+)/i, // Kakao App
1301
+ /(naver)\(.*?(\d+\.[\w\.]+).*\)/i, // Naver InApp
1302
+ /safari (line)\/([\w\.]+)/i, // Line App for iOS
1303
+ /\b(line)\/([\w\.]+)\/iab/i, // Line App for Android
1304
+ /(alipay)client\/([\w\.]+)/i, // Alipay
1305
+ /(twitter)(?:and| f.+e\/([\w\.]+))/i, // Twitter
1306
+ /(chromium|instagram|snapchat)[\/ ]([-\w\.]+)/i // Chromium/Instagram/Snapchat
1307
+ ], [NAME, VERSION], [
1308
+ /\bgsa\/([\w\.]+) .*safari\//i // Google Search Appliance on iOS
1309
+ ], [VERSION, [NAME, 'GSA']], [
1310
+ /musical_ly(?:.+app_?version\/|_)([\w\.]+)/i // TikTok
1311
+ ], [VERSION, [NAME, 'TikTok']], [
1312
+
1313
+ /headlesschrome(?:\/([\w\.]+)| )/i // Chrome Headless
1314
+ ], [VERSION, [NAME, CHROME+' Headless']], [
1315
+
1316
+ / wv\).+(chrome)\/([\w\.]+)/i // Chrome WebView
1317
+ ], [[NAME, CHROME+' WebView'], VERSION], [
1318
+
1319
+ /droid.+ version\/([\w\.]+)\b.+(?:mobile safari|safari)/i // Android Browser
1320
+ ], [VERSION, [NAME, 'Android '+BROWSER]], [
1321
+
1322
+ /(chrome|omniweb|arora|[tizenoka]{5} ?browser)\/v?([\w\.]+)/i // Chrome/OmniWeb/Arora/Tizen/Nokia
1323
+ ], [NAME, VERSION], [
1324
+
1325
+ /version\/([\w\.\,]+) .*mobile\/\w+ (safari)/i // Mobile Safari
1326
+ ], [VERSION, [NAME, 'Mobile Safari']], [
1327
+ /version\/([\w(\.|\,)]+) .*(mobile ?safari|safari)/i // Safari & Safari Mobile
1328
+ ], [VERSION, NAME], [
1329
+ /webkit.+?(mobile ?safari|safari)(\/[\w\.]+)/i // Safari < 3.0
1330
+ ], [NAME, [VERSION, strMapper, oldSafariMap]], [
1331
+
1332
+ /(webkit|khtml)\/([\w\.]+)/i
1333
+ ], [NAME, VERSION], [
1334
+
1335
+ // Gecko based
1336
+ /(navigator|netscape\d?)\/([-\w\.]+)/i // Netscape
1337
+ ], [[NAME, 'Netscape'], VERSION], [
1338
+ /mobile vr; rv:([\w\.]+)\).+firefox/i // Firefox Reality
1339
+ ], [VERSION, [NAME, FIREFOX+' Reality']], [
1340
+ /ekiohf.+(flow)\/([\w\.]+)/i, // Flow
1341
+ /(swiftfox)/i, // Swiftfox
1342
+ /(icedragon|iceweasel|camino|chimera|fennec|maemo browser|minimo|conkeror|klar)[\/ ]?([\w\.\+]+)/i,
1343
+ // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror/Klar
1344
+ /(seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([-\w\.]+)$/i,
1345
+ // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
1346
+ /(firefox)\/([\w\.]+)/i, // Other Firefox-based
1347
+ /(mozilla)\/([\w\.]+) .+rv\:.+gecko\/\d+/i, // Mozilla
1348
+
1349
+ // Other
1350
+ /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir|obigo|mosaic|(?:go|ice|up)[\. ]?browser)[-\/ ]?v?([\w\.]+)/i,
1351
+ // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir/Obigo/Mosaic/Go/ICE/UP.Browser
1352
+ /(links) \(([\w\.]+)/i, // Links
1353
+ /panasonic;(viera)/i // Panasonic Viera
1354
+ ], [NAME, VERSION], [
1355
+
1356
+ /(cobalt)\/([\w\.]+)/i // Cobalt
1357
+ ], [NAME, [VERSION, /master.|lts./, ""]]
1358
+ ],
1359
+
1360
+ cpu : [[
1361
+
1362
+ /(?:(amd|x(?:(?:86|64)[-_])?|wow|win)64)[;\)]/i // AMD64 (x64)
1363
+ ], [[ARCHITECTURE, 'amd64']], [
1364
+
1365
+ /(ia32(?=;))/i // IA32 (quicktime)
1366
+ ], [[ARCHITECTURE, lowerize]], [
1367
+
1368
+ /((?:i[346]|x)86)[;\)]/i // IA32 (x86)
1369
+ ], [[ARCHITECTURE, 'ia32']], [
1370
+
1371
+ /\b(aarch64|arm(v?8e?l?|_?64))\b/i // ARM64
1372
+ ], [[ARCHITECTURE, 'arm64']], [
1373
+
1374
+ /\b(arm(?:v[67])?ht?n?[fl]p?)\b/i // ARMHF
1375
+ ], [[ARCHITECTURE, 'armhf']], [
1376
+
1377
+ // PocketPC mistakenly identified as PowerPC
1378
+ /windows (ce|mobile); ppc;/i
1379
+ ], [[ARCHITECTURE, 'arm']], [
1380
+
1381
+ /((?:ppc|powerpc)(?:64)?)(?: mac|;|\))/i // PowerPC
1382
+ ], [[ARCHITECTURE, /ower/, EMPTY, lowerize]], [
1383
+
1384
+ /(sun4\w)[;\)]/i // SPARC
1385
+ ], [[ARCHITECTURE, 'sparc']], [
1386
+
1387
+ /((?:avr32|ia64(?=;))|68k(?=\))|\barm(?=v(?:[1-7]|[5-7]1)l?|;|eabi)|(?=atmel )avr|(?:irix|mips|sparc)(?:64)?\b|pa-risc)/i
1388
+ // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
1389
+ ], [[ARCHITECTURE, lowerize]]
1390
+ ],
1391
+
1392
+ device : [[
1393
+
1394
+ //////////////////////////
1395
+ // MOBILES & TABLETS
1396
+ /////////////////////////
1397
+
1398
+ // Samsung
1399
+ /\b(sch-i[89]0\d|shw-m380s|sm-[ptx]\w{2,4}|gt-[pn]\d{2,4}|sgh-t8[56]9|nexus 10)/i
1400
+ ], [MODEL, [VENDOR, SAMSUNG], [TYPE, TABLET]], [
1401
+ /\b((?:s[cgp]h|gt|sm)-\w+|sc[g-]?[\d]+a?|galaxy nexus)/i,
1402
+ /samsung[- ]([-\w]+)/i,
1403
+ /sec-(sgh\w+)/i
1404
+ ], [MODEL, [VENDOR, SAMSUNG], [TYPE, MOBILE]], [
1405
+
1406
+ // Apple
1407
+ /(?:\/|\()(ip(?:hone|od)[\w, ]*)(?:\/|;)/i // iPod/iPhone
1408
+ ], [MODEL, [VENDOR, APPLE], [TYPE, MOBILE]], [
1409
+ /\((ipad);[-\w\),; ]+apple/i, // iPad
1410
+ /applecoremedia\/[\w\.]+ \((ipad)/i,
1411
+ /\b(ipad)\d\d?,\d\d?[;\]].+ios/i
1412
+ ], [MODEL, [VENDOR, APPLE], [TYPE, TABLET]], [
1413
+ /(macintosh);/i
1414
+ ], [MODEL, [VENDOR, APPLE]], [
1415
+
1416
+ // Sharp
1417
+ /\b(sh-?[altvz]?\d\d[a-ekm]?)/i
1418
+ ], [MODEL, [VENDOR, SHARP], [TYPE, MOBILE]], [
1419
+
1420
+ // Huawei
1421
+ /\b((?:ag[rs][23]?|bah2?|sht?|btv)-a?[lw]\d{2})\b(?!.+d\/s)/i
1422
+ ], [MODEL, [VENDOR, HUAWEI], [TYPE, TABLET]], [
1423
+ /(?:huawei|honor)([-\w ]+)[;\)]/i,
1424
+ /\b(nexus 6p|\w{2,4}e?-[atu]?[ln][\dx][012359c][adn]?)\b(?!.+d\/s)/i
1425
+ ], [MODEL, [VENDOR, HUAWEI], [TYPE, MOBILE]], [
1426
+
1427
+ // Xiaomi
1428
+ /\b(poco[\w ]+|m2\d{3}j\d\d[a-z]{2})(?: bui|\))/i, // Xiaomi POCO
1429
+ /\b; (\w+) build\/hm\1/i, // Xiaomi Hongmi 'numeric' models
1430
+ /\b(hm[-_ ]?note?[_ ]?(?:\d\w)?) bui/i, // Xiaomi Hongmi
1431
+ /\b(redmi[\-_ ]?(?:note|k)?[\w_ ]+)(?: bui|\))/i, // Xiaomi Redmi
1432
+ /oid[^\)]+; (m?[12][0-389][01]\w{3,6}[c-y])( bui|; wv|\))/i, // Xiaomi Redmi 'numeric' models
1433
+ /\b(mi[-_ ]?(?:a\d|one|one[_ ]plus|note lte|max|cc)?[_ ]?(?:\d?\w?)[_ ]?(?:plus|se|lite)?)(?: bui|\))/i // Xiaomi Mi
1434
+ ], [[MODEL, /_/g, ' '], [VENDOR, XIAOMI], [TYPE, MOBILE]], [
1435
+ /oid[^\)]+; (2\d{4}(283|rpbf)[cgl])( bui|\))/i, // Redmi Pad
1436
+ /\b(mi[-_ ]?(?:pad)(?:[\w_ ]+))(?: bui|\))/i // Mi Pad tablets
1437
+ ],[[MODEL, /_/g, ' '], [VENDOR, XIAOMI], [TYPE, TABLET]], [
1438
+
1439
+ // OPPO
1440
+ /; (\w+) bui.+ oppo/i,
1441
+ /\b(cph[12]\d{3}|p(?:af|c[al]|d\w|e[ar])[mt]\d0|x9007|a101op)\b/i
1442
+ ], [MODEL, [VENDOR, 'OPPO'], [TYPE, MOBILE]], [
1443
+ /\b(opd2\d{3}a?) bui/i
1444
+ ], [MODEL, [VENDOR, 'OPPO'], [TYPE, TABLET]], [
1445
+
1446
+ // Vivo
1447
+ /vivo (\w+)(?: bui|\))/i,
1448
+ /\b(v[12]\d{3}\w?[at])(?: bui|;)/i
1449
+ ], [MODEL, [VENDOR, 'Vivo'], [TYPE, MOBILE]], [
1450
+
1451
+ // Realme
1452
+ /\b(rmx[1-3]\d{3})(?: bui|;|\))/i
1453
+ ], [MODEL, [VENDOR, 'Realme'], [TYPE, MOBILE]], [
1454
+
1455
+ // Motorola
1456
+ /\b(milestone|droid(?:[2-4x]| (?:bionic|x2|pro|razr))?:?( 4g)?)\b[\w ]+build\//i,
1457
+ /\bmot(?:orola)?[- ](\w*)/i,
1458
+ /((?:moto[\w\(\) ]+|xt\d{3,4}|nexus 6)(?= bui|\)))/i
1459
+ ], [MODEL, [VENDOR, MOTOROLA], [TYPE, MOBILE]], [
1460
+ /\b(mz60\d|xoom[2 ]{0,2}) build\//i
1461
+ ], [MODEL, [VENDOR, MOTOROLA], [TYPE, TABLET]], [
1462
+
1463
+ // LG
1464
+ /((?=lg)?[vl]k\-?\d{3}) bui| 3\.[-\w; ]{10}lg?-([06cv9]{3,4})/i
1465
+ ], [MODEL, [VENDOR, LG], [TYPE, TABLET]], [
1466
+ /(lm(?:-?f100[nv]?|-[\w\.]+)(?= bui|\))|nexus [45])/i,
1467
+ /\blg[-e;\/ ]+((?!browser|netcast|android tv)\w+)/i,
1468
+ /\blg-?([\d\w]+) bui/i
1469
+ ], [MODEL, [VENDOR, LG], [TYPE, MOBILE]], [
1470
+
1471
+ // Lenovo
1472
+ /(ideatab[-\w ]+)/i,
1473
+ /lenovo ?(s[56]000[-\w]+|tab(?:[\w ]+)|yt[-\d\w]{6}|tb[-\d\w]{6})/i
1474
+ ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
1475
+
1476
+ // Nokia
1477
+ /(?:maemo|nokia).*(n900|lumia \d+)/i,
1478
+ /nokia[-_ ]?([-\w\.]*)/i
1479
+ ], [[MODEL, /_/g, ' '], [VENDOR, 'Nokia'], [TYPE, MOBILE]], [
1480
+
1481
+ // Google
1482
+ /(pixel c)\b/i // Google Pixel C
1483
+ ], [MODEL, [VENDOR, GOOGLE], [TYPE, TABLET]], [
1484
+ /droid.+; (pixel[\daxl ]{0,6})(?: bui|\))/i // Google Pixel
1485
+ ], [MODEL, [VENDOR, GOOGLE], [TYPE, MOBILE]], [
1486
+
1487
+ // Sony
1488
+ /droid.+ (a?\d[0-2]{2}so|[c-g]\d{4}|so[-gl]\w+|xq-a\w[4-7][12])(?= bui|\).+chrome\/(?![1-6]{0,1}\d\.))/i
1489
+ ], [MODEL, [VENDOR, SONY], [TYPE, MOBILE]], [
1490
+ /sony tablet [ps]/i,
1491
+ /\b(?:sony)?sgp\w+(?: bui|\))/i
1492
+ ], [[MODEL, 'Xperia Tablet'], [VENDOR, SONY], [TYPE, TABLET]], [
1493
+
1494
+ // OnePlus
1495
+ / (kb2005|in20[12]5|be20[12][59])\b/i,
1496
+ /(?:one)?(?:plus)? (a\d0\d\d)(?: b|\))/i
1497
+ ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [
1498
+
1499
+ // Amazon
1500
+ /(alexa)webm/i,
1501
+ /(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i, // Kindle Fire without Silk / Echo Show
1502
+ /(kf[a-z]+)( bui|\)).+silk\//i // Kindle Fire HD
1503
+ ], [MODEL, [VENDOR, AMAZON], [TYPE, TABLET]], [
1504
+ /((?:sd|kf)[0349hijorstuw]+)( bui|\)).+silk\//i // Fire Phone
1505
+ ], [[MODEL, /(.+)/g, 'Fire Phone $1'], [VENDOR, AMAZON], [TYPE, MOBILE]], [
1506
+
1507
+ // BlackBerry
1508
+ /(playbook);[-\w\),; ]+(rim)/i // BlackBerry PlayBook
1509
+ ], [MODEL, VENDOR, [TYPE, TABLET]], [
1510
+ /\b((?:bb[a-f]|st[hv])100-\d)/i,
1511
+ /\(bb10; (\w+)/i // BlackBerry 10
1512
+ ], [MODEL, [VENDOR, BLACKBERRY], [TYPE, MOBILE]], [
1513
+
1514
+ // Asus
1515
+ /(?:\b|asus_)(transfo[prime ]{4,10} \w+|eeepc|slider \w+|nexus 7|padfone|p00[cj])/i
1516
+ ], [MODEL, [VENDOR, ASUS], [TYPE, TABLET]], [
1517
+ / (z[bes]6[027][012][km][ls]|zenfone \d\w?)\b/i
1518
+ ], [MODEL, [VENDOR, ASUS], [TYPE, MOBILE]], [
1519
+
1520
+ // HTC
1521
+ /(nexus 9)/i // HTC Nexus 9
1522
+ ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
1523
+ /(htc)[-;_ ]{1,2}([\w ]+(?=\)| bui)|\w+)/i, // HTC
1524
+
1525
+ // ZTE
1526
+ /(zte)[- ]([\w ]+?)(?: bui|\/|\))/i,
1527
+ /(alcatel|geeksphone|nexian|panasonic(?!(?:;|\.))|sony(?!-bra))[-_ ]?([-\w]*)/i // Alcatel/GeeksPhone/Nexian/Panasonic/Sony
1528
+ ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
1529
+
1530
+ // Acer
1531
+ /droid.+; ([ab][1-7]-?[0178a]\d\d?)/i
1532
+ ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [
1533
+
1534
+ // Meizu
1535
+ /droid.+; (m[1-5] note) bui/i,
1536
+ /\bmz-([-\w]{2,})/i
1537
+ ], [MODEL, [VENDOR, 'Meizu'], [TYPE, MOBILE]], [
1538
+
1539
+ // Ulefone
1540
+ /; ((?:power )?armor(?:[\w ]{0,8}))(?: bui|\))/i
1541
+ ], [MODEL, [VENDOR, 'Ulefone'], [TYPE, MOBILE]], [
1542
+
1543
+ // MIXED
1544
+ /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron|infinix|tecno)[-_ ]?([-\w]*)/i,
1545
+ // BlackBerry/BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
1546
+ /(hp) ([\w ]+\w)/i, // HP iPAQ
1547
+ /(asus)-?(\w+)/i, // Asus
1548
+ /(microsoft); (lumia[\w ]+)/i, // Microsoft Lumia
1549
+ /(lenovo)[-_ ]?([-\w]+)/i, // Lenovo
1550
+ /(jolla)/i, // Jolla
1551
+ /(oppo) ?([\w ]+) bui/i // OPPO
1552
+ ], [VENDOR, MODEL, [TYPE, MOBILE]], [
1553
+
1554
+ /(kobo)\s(ereader|touch)/i, // Kobo
1555
+ /(archos) (gamepad2?)/i, // Archos
1556
+ /(hp).+(touchpad(?!.+tablet)|tablet)/i, // HP TouchPad
1557
+ /(kindle)\/([\w\.]+)/i, // Kindle
1558
+ /(nook)[\w ]+build\/(\w+)/i, // Nook
1559
+ /(dell) (strea[kpr\d ]*[\dko])/i, // Dell Streak
1560
+ /(le[- ]+pan)[- ]+(\w{1,9}) bui/i, // Le Pan Tablets
1561
+ /(trinity)[- ]*(t\d{3}) bui/i, // Trinity Tablets
1562
+ /(gigaset)[- ]+(q\w{1,9}) bui/i, // Gigaset Tablets
1563
+ /(vodafone) ([\w ]+)(?:\)| bui)/i // Vodafone
1564
+ ], [VENDOR, MODEL, [TYPE, TABLET]], [
1565
+
1566
+ /(surface duo)/i // Surface Duo
1567
+ ], [MODEL, [VENDOR, MICROSOFT], [TYPE, TABLET]], [
1568
+ /droid [\d\.]+; (fp\du?)(?: b|\))/i // Fairphone
1569
+ ], [MODEL, [VENDOR, 'Fairphone'], [TYPE, MOBILE]], [
1570
+ /(u304aa)/i // AT&T
1571
+ ], [MODEL, [VENDOR, 'AT&T'], [TYPE, MOBILE]], [
1572
+ /\bsie-(\w*)/i // Siemens
1573
+ ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
1574
+ /\b(rct\w+) b/i // RCA Tablets
1575
+ ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
1576
+ /\b(venue[\d ]{2,7}) b/i // Dell Venue Tablets
1577
+ ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
1578
+ /\b(q(?:mv|ta)\w+) b/i // Verizon Tablet
1579
+ ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
1580
+ /\b(?:barnes[& ]+noble |bn[rt])([\w\+ ]*) b/i // Barnes & Noble Tablet
1581
+ ], [MODEL, [VENDOR, 'Barnes & Noble'], [TYPE, TABLET]], [
1582
+ /\b(tm\d{3}\w+) b/i
1583
+ ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
1584
+ /\b(k88) b/i // ZTE K Series Tablet
1585
+ ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
1586
+ /\b(nx\d{3}j) b/i // ZTE Nubia
1587
+ ], [MODEL, [VENDOR, 'ZTE'], [TYPE, MOBILE]], [
1588
+ /\b(gen\d{3}) b.+49h/i // Swiss GEN Mobile
1589
+ ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
1590
+ /\b(zur\d{3}) b/i // Swiss ZUR Tablet
1591
+ ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
1592
+ /\b((zeki)?tb.*\b) b/i // Zeki Tablets
1593
+ ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
1594
+ /\b([yr]\d{2}) b/i,
1595
+ /\b(dragon[- ]+touch |dt)(\w{5}) b/i // Dragon Touch Tablet
1596
+ ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
1597
+ /\b(ns-?\w{0,9}) b/i // Insignia Tablets
1598
+ ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
1599
+ /\b((nxa|next)-?\w{0,9}) b/i // NextBook Tablets
1600
+ ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
1601
+ /\b(xtreme\_)?(v(1[045]|2[015]|[3469]0|7[05])) b/i // Voice Xtreme Phones
1602
+ ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [
1603
+ /\b(lvtel\-)?(v1[12]) b/i // LvTel Phones
1604
+ ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
1605
+ /\b(ph-1) /i // Essential PH-1
1606
+ ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [
1607
+ /\b(v(100md|700na|7011|917g).*\b) b/i // Envizen Tablets
1608
+ ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
1609
+ /\b(trio[-\w\. ]+) b/i // MachSpeed Tablets
1610
+ ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
1611
+ /\btu_(1491) b/i // Rotor Tablets
1612
+ ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
1613
+ /(shield[\w ]+) b/i // Nvidia Shield Tablets
1614
+ ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, TABLET]], [
1615
+ /(sprint) (\w+)/i // Sprint Phones
1616
+ ], [VENDOR, MODEL, [TYPE, MOBILE]], [
1617
+ /(kin\.[onetw]{3})/i // Microsoft Kin
1618
+ ], [[MODEL, /\./g, ' '], [VENDOR, MICROSOFT], [TYPE, MOBILE]], [
1619
+ /droid.+; (cc6666?|et5[16]|mc[239][23]x?|vc8[03]x?)\)/i // Zebra
1620
+ ], [MODEL, [VENDOR, ZEBRA], [TYPE, TABLET]], [
1621
+ /droid.+; (ec30|ps20|tc[2-8]\d[kx])\)/i
1622
+ ], [MODEL, [VENDOR, ZEBRA], [TYPE, MOBILE]], [
1623
+
1624
+ ///////////////////
1625
+ // SMARTTVS
1626
+ ///////////////////
1627
+
1628
+ /smart-tv.+(samsung)/i // Samsung
1629
+ ], [VENDOR, [TYPE, SMARTTV]], [
1630
+ /hbbtv.+maple;(\d+)/i
1631
+ ], [[MODEL, /^/, 'SmartTV'], [VENDOR, SAMSUNG], [TYPE, SMARTTV]], [
1632
+ /(nux; netcast.+smarttv|lg (netcast\.tv-201\d|android tv))/i // LG SmartTV
1633
+ ], [[VENDOR, LG], [TYPE, SMARTTV]], [
1634
+ /(apple) ?tv/i // Apple TV
1635
+ ], [VENDOR, [MODEL, APPLE+' TV'], [TYPE, SMARTTV]], [
1636
+ /crkey/i // Google Chromecast
1637
+ ], [[MODEL, CHROME+'cast'], [VENDOR, GOOGLE], [TYPE, SMARTTV]], [
1638
+ /droid.+aft(\w+)( bui|\))/i // Fire TV
1639
+ ], [MODEL, [VENDOR, AMAZON], [TYPE, SMARTTV]], [
1640
+ /\(dtv[\);].+(aquos)/i,
1641
+ /(aquos-tv[\w ]+)\)/i // Sharp
1642
+ ], [MODEL, [VENDOR, SHARP], [TYPE, SMARTTV]],[
1643
+ /(bravia[\w ]+)( bui|\))/i // Sony
1644
+ ], [MODEL, [VENDOR, SONY], [TYPE, SMARTTV]], [
1645
+ /(mitv-\w{5}) bui/i // Xiaomi
1646
+ ], [MODEL, [VENDOR, XIAOMI], [TYPE, SMARTTV]], [
1647
+ /Hbbtv.*(technisat) (.*);/i // TechniSAT
1648
+ ], [VENDOR, MODEL, [TYPE, SMARTTV]], [
1649
+ /\b(roku)[\dx]*[\)\/]((?:dvp-)?[\d\.]*)/i, // Roku
1650
+ /hbbtv\/\d+\.\d+\.\d+ +\([\w\+ ]*; *([\w\d][^;]*);([^;]*)/i // HbbTV devices
1651
+ ], [[VENDOR, trim], [MODEL, trim], [TYPE, SMARTTV]], [
1652
+ /\b(android tv|smart[- ]?tv|opera tv|tv; rv:)\b/i // SmartTV from Unidentified Vendors
1653
+ ], [[TYPE, SMARTTV]], [
1654
+
1655
+ ///////////////////
1656
+ // CONSOLES
1657
+ ///////////////////
1658
+
1659
+ /(ouya)/i, // Ouya
1660
+ /(nintendo) ([wids3utch]+)/i // Nintendo
1661
+ ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
1662
+ /droid.+; (shield) bui/i // Nvidia
1663
+ ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
1664
+ /(playstation [345portablevi]+)/i // Playstation
1665
+ ], [MODEL, [VENDOR, SONY], [TYPE, CONSOLE]], [
1666
+ /\b(xbox(?: one)?(?!; xbox))[\); ]/i // Microsoft Xbox
1667
+ ], [MODEL, [VENDOR, MICROSOFT], [TYPE, CONSOLE]], [
1668
+
1669
+ ///////////////////
1670
+ // WEARABLES
1671
+ ///////////////////
1672
+
1673
+ /((pebble))app/i // Pebble
1674
+ ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
1675
+ /(watch)(?: ?os[,\/]|\d,\d\/)[\d\.]+/i // Apple Watch
1676
+ ], [MODEL, [VENDOR, APPLE], [TYPE, WEARABLE]], [
1677
+ /droid.+; (glass) \d/i // Google Glass
1678
+ ], [MODEL, [VENDOR, GOOGLE], [TYPE, WEARABLE]], [
1679
+ /droid.+; (wt63?0{2,3})\)/i
1680
+ ], [MODEL, [VENDOR, ZEBRA], [TYPE, WEARABLE]], [
1681
+ /(quest( \d| pro)?)/i // Oculus Quest
1682
+ ], [MODEL, [VENDOR, FACEBOOK], [TYPE, WEARABLE]], [
1683
+
1684
+ ///////////////////
1685
+ // EMBEDDED
1686
+ ///////////////////
1687
+
1688
+ /(tesla)(?: qtcarbrowser|\/[-\w\.]+)/i // Tesla
1689
+ ], [VENDOR, [TYPE, EMBEDDED]], [
1690
+ /(aeobc)\b/i // Echo Dot
1691
+ ], [MODEL, [VENDOR, AMAZON], [TYPE, EMBEDDED]], [
1692
+
1693
+ ////////////////////
1694
+ // MIXED (GENERIC)
1695
+ ///////////////////
1696
+
1697
+ /droid .+?; ([^;]+?)(?: bui|; wv\)|\) applew).+? mobile safari/i // Android Phones from Unidentified Vendors
1698
+ ], [MODEL, [TYPE, MOBILE]], [
1699
+ /droid .+?; ([^;]+?)(?: bui|\) applew).+?(?! mobile) safari/i // Android Tablets from Unidentified Vendors
1700
+ ], [MODEL, [TYPE, TABLET]], [
1701
+ /\b((tablet|tab)[;\/]|focus\/\d(?!.+mobile))/i // Unidentifiable Tablet
1702
+ ], [[TYPE, TABLET]], [
1703
+ /(phone|mobile(?:[;\/]| [ \w\/\.]*safari)|pda(?=.+windows ce))/i // Unidentifiable Mobile
1704
+ ], [[TYPE, MOBILE]], [
1705
+ /(android[-\w\. ]{0,9});.+buil/i // Generic Android Device
1706
+ ], [MODEL, [VENDOR, 'Generic']]
1707
+ ],
1708
+
1709
+ engine : [[
1710
+
1711
+ /windows.+ edge\/([\w\.]+)/i // EdgeHTML
1712
+ ], [VERSION, [NAME, EDGE+'HTML']], [
1713
+
1714
+ /webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i // Blink
1715
+ ], [VERSION, [NAME, 'Blink']], [
1716
+
1717
+ /(presto)\/([\w\.]+)/i, // Presto
1718
+ /(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i, // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m/Goanna
1719
+ /ekioh(flow)\/([\w\.]+)/i, // Flow
1720
+ /(khtml|tasman|links)[\/ ]\(?([\w\.]+)/i, // KHTML/Tasman/Links
1721
+ /(icab)[\/ ]([23]\.[\d\.]+)/i, // iCab
1722
+ /\b(libweb)/i
1723
+ ], [NAME, VERSION], [
1724
+
1725
+ /rv\:([\w\.]{1,9})\b.+(gecko)/i // Gecko
1726
+ ], [VERSION, NAME]
1727
+ ],
1728
+
1729
+ os : [[
1730
+
1731
+ // Windows
1732
+ /microsoft (windows) (vista|xp)/i // Windows (iTunes)
1733
+ ], [NAME, VERSION], [
1734
+ /(windows (?:phone(?: os)?|mobile))[\/ ]?([\d\.\w ]*)/i // Windows Phone
1735
+ ], [NAME, [VERSION, strMapper, windowsVersionMap]], [
1736
+ /windows nt 6\.2; (arm)/i, // Windows RT
1737
+ /windows[\/ ]?([ntce\d\. ]+\w)(?!.+xbox)/i,
1738
+ /(?:win(?=3|9|n)|win 9x )([nt\d\.]+)/i
1739
+ ], [[VERSION, strMapper, windowsVersionMap], [NAME, 'Windows']], [
1740
+
1741
+ // iOS/macOS
1742
+ /ip[honead]{2,4}\b(?:.*os ([\w]+) like mac|; opera)/i, // iOS
1743
+ /(?:ios;fbsv\/|iphone.+ios[\/ ])([\d\.]+)/i,
1744
+ /cfnetwork\/.+darwin/i
1745
+ ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
1746
+ /(mac os x) ?([\w\. ]*)/i,
1747
+ /(macintosh|mac_powerpc\b)(?!.+haiku)/i // Mac OS
1748
+ ], [[NAME, MAC_OS], [VERSION, /_/g, '.']], [
1749
+
1750
+ // Mobile OSes
1751
+ /droid ([\w\.]+)\b.+(android[- ]x86|harmonyos)/i // Android-x86/HarmonyOS
1752
+ ], [VERSION, NAME], [ // Android/WebOS/QNX/Bada/RIM/Maemo/MeeGo/Sailfish OS
1753
+ /(android|webos|qnx|bada|rim tablet os|maemo|meego|sailfish)[-\/ ]?([\w\.]*)/i,
1754
+ /(blackberry)\w*\/([\w\.]*)/i, // Blackberry
1755
+ /(tizen|kaios)[\/ ]([\w\.]+)/i, // Tizen/KaiOS
1756
+ /\((series40);/i // Series 40
1757
+ ], [NAME, VERSION], [
1758
+ /\(bb(10);/i // BlackBerry 10
1759
+ ], [VERSION, [NAME, BLACKBERRY]], [
1760
+ /(?:symbian ?os|symbos|s60(?=;)|series60)[-\/ ]?([\w\.]*)/i // Symbian
1761
+ ], [VERSION, [NAME, 'Symbian']], [
1762
+ /mozilla\/[\d\.]+ \((?:mobile|tablet|tv|mobile; [\w ]+); rv:.+ gecko\/([\w\.]+)/i // Firefox OS
1763
+ ], [VERSION, [NAME, FIREFOX+' OS']], [
1764
+ /web0s;.+rt(tv)/i,
1765
+ /\b(?:hp)?wos(?:browser)?\/([\w\.]+)/i // WebOS
1766
+ ], [VERSION, [NAME, 'webOS']], [
1767
+ /watch(?: ?os[,\/]|\d,\d\/)([\d\.]+)/i // watchOS
1768
+ ], [VERSION, [NAME, 'watchOS']], [
1769
+
1770
+ // Google Chromecast
1771
+ /crkey\/([\d\.]+)/i // Google Chromecast
1772
+ ], [VERSION, [NAME, CHROME+'cast']], [
1773
+ /(cros) [\w]+(?:\)| ([\w\.]+)\b)/i // Chromium OS
1774
+ ], [[NAME, CHROMIUM_OS], VERSION],[
1775
+
1776
+ // Smart TVs
1777
+ /panasonic;(viera)/i, // Panasonic Viera
1778
+ /(netrange)mmh/i, // Netrange
1779
+ /(nettv)\/(\d+\.[\w\.]+)/i, // NetTV
1780
+
1781
+ // Console
1782
+ /(nintendo|playstation) ([wids345portablevuch]+)/i, // Nintendo/Playstation
1783
+ /(xbox); +xbox ([^\);]+)/i, // Microsoft Xbox (360, One, X, S, Series X, Series S)
1784
+
1785
+ // Other
1786
+ /\b(joli|palm)\b ?(?:os)?\/?([\w\.]*)/i, // Joli/Palm
1787
+ /(mint)[\/\(\) ]?(\w*)/i, // Mint
1788
+ /(mageia|vectorlinux)[; ]/i, // Mageia/VectorLinux
1789
+ /([kxln]?ubuntu|debian|suse|opensuse|gentoo|arch(?= linux)|slackware|fedora|mandriva|centos|pclinuxos|red ?hat|zenwalk|linpus|raspbian|plan 9|minix|risc os|contiki|deepin|manjaro|elementary os|sabayon|linspire)(?: gnu\/linux)?(?: enterprise)?(?:[- ]linux)?(?:-gnu)?[-\/ ]?(?!chrom|package)([-\w\.]*)/i,
1790
+ // Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware/Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus/Raspbian/Plan9/Minix/RISCOS/Contiki/Deepin/Manjaro/elementary/Sabayon/Linspire
1791
+ /(hurd|linux) ?([\w\.]*)/i, // Hurd/Linux
1792
+ /(gnu) ?([\w\.]*)/i, // GNU
1793
+ /\b([-frentopcghs]{0,5}bsd|dragonfly)[\/ ]?(?!amd|[ix346]{1,2}86)([\w\.]*)/i, // FreeBSD/NetBSD/OpenBSD/PC-BSD/GhostBSD/DragonFly
1794
+ /(haiku) (\w+)/i // Haiku
1795
+ ], [NAME, VERSION], [
1796
+ /(sunos) ?([\w\.\d]*)/i // Solaris
1797
+ ], [[NAME, 'Solaris'], VERSION], [
1798
+ /((?:open)?solaris)[-\/ ]?([\w\.]*)/i, // Solaris
1799
+ /(aix) ((\d)(?=\.|\)| )[\w\.])*/i, // AIX
1800
+ /\b(beos|os\/2|amigaos|morphos|openvms|fuchsia|hp-ux|serenityos)/i, // BeOS/OS2/AmigaOS/MorphOS/OpenVMS/Fuchsia/HP-UX/SerenityOS
1801
+ /(unix) ?([\w\.]*)/i // UNIX
1802
+ ], [NAME, VERSION]
1803
+ ]
1804
+ };
1805
+
1806
+ /////////////////
1807
+ // Constructor
1808
+ ////////////////
1809
+
1810
+ var UAParser = function (ua, extensions) {
1811
+
1812
+ if (typeof ua === OBJ_TYPE) {
1813
+ extensions = ua;
1814
+ ua = undefined$1;
1815
+ }
1816
+
1817
+ if (!(this instanceof UAParser)) {
1818
+ return new UAParser(ua, extensions).getResult();
1819
+ }
1820
+
1821
+ var _navigator = (typeof window !== UNDEF_TYPE && window.navigator) ? window.navigator : undefined$1;
1822
+ var _ua = ua || ((_navigator && _navigator.userAgent) ? _navigator.userAgent : EMPTY);
1823
+ var _uach = (_navigator && _navigator.userAgentData) ? _navigator.userAgentData : undefined$1;
1824
+ var _rgxmap = extensions ? extend(regexes, extensions) : regexes;
1825
+ var _isSelfNav = _navigator && _navigator.userAgent == _ua;
1826
+
1827
+ this.getBrowser = function () {
1828
+ var _browser = {};
1829
+ _browser[NAME] = undefined$1;
1830
+ _browser[VERSION] = undefined$1;
1831
+ rgxMapper.call(_browser, _ua, _rgxmap.browser);
1832
+ _browser[MAJOR] = majorize(_browser[VERSION]);
1833
+ // Brave-specific detection
1834
+ if (_isSelfNav && _navigator && _navigator.brave && typeof _navigator.brave.isBrave == FUNC_TYPE) {
1835
+ _browser[NAME] = 'Brave';
1836
+ }
1837
+ return _browser;
1838
+ };
1839
+ this.getCPU = function () {
1840
+ var _cpu = {};
1841
+ _cpu[ARCHITECTURE] = undefined$1;
1842
+ rgxMapper.call(_cpu, _ua, _rgxmap.cpu);
1843
+ return _cpu;
1844
+ };
1845
+ this.getDevice = function () {
1846
+ var _device = {};
1847
+ _device[VENDOR] = undefined$1;
1848
+ _device[MODEL] = undefined$1;
1849
+ _device[TYPE] = undefined$1;
1850
+ rgxMapper.call(_device, _ua, _rgxmap.device);
1851
+ if (_isSelfNav && !_device[TYPE] && _uach && _uach.mobile) {
1852
+ _device[TYPE] = MOBILE;
1853
+ }
1854
+ // iPadOS-specific detection: identified as Mac, but has some iOS-only properties
1855
+ if (_isSelfNav && _device[MODEL] == 'Macintosh' && _navigator && typeof _navigator.standalone !== UNDEF_TYPE && _navigator.maxTouchPoints && _navigator.maxTouchPoints > 2) {
1856
+ _device[MODEL] = 'iPad';
1857
+ _device[TYPE] = TABLET;
1858
+ }
1859
+ return _device;
1860
+ };
1861
+ this.getEngine = function () {
1862
+ var _engine = {};
1863
+ _engine[NAME] = undefined$1;
1864
+ _engine[VERSION] = undefined$1;
1865
+ rgxMapper.call(_engine, _ua, _rgxmap.engine);
1866
+ return _engine;
1867
+ };
1868
+ this.getOS = function () {
1869
+ var _os = {};
1870
+ _os[NAME] = undefined$1;
1871
+ _os[VERSION] = undefined$1;
1872
+ rgxMapper.call(_os, _ua, _rgxmap.os);
1873
+ if (_isSelfNav && !_os[NAME] && _uach && _uach.platform && _uach.platform != 'Unknown') {
1874
+ _os[NAME] = _uach.platform
1875
+ .replace(/chrome os/i, CHROMIUM_OS)
1876
+ .replace(/macos/i, MAC_OS); // backward compatibility
1877
+ }
1878
+ return _os;
1879
+ };
1880
+ this.getResult = function () {
1881
+ return {
1882
+ ua : this.getUA(),
1883
+ browser : this.getBrowser(),
1884
+ engine : this.getEngine(),
1885
+ os : this.getOS(),
1886
+ device : this.getDevice(),
1887
+ cpu : this.getCPU()
1888
+ };
1889
+ };
1890
+ this.getUA = function () {
1891
+ return _ua;
1892
+ };
1893
+ this.setUA = function (ua) {
1894
+ _ua = (typeof ua === STR_TYPE && ua.length > UA_MAX_LENGTH) ? trim(ua, UA_MAX_LENGTH) : ua;
1895
+ return this;
1896
+ };
1897
+ this.setUA(_ua);
1898
+ return this;
1899
+ };
1900
+
1901
+ UAParser.VERSION = LIBVERSION;
1902
+ UAParser.BROWSER = enumerize([NAME, VERSION, MAJOR]);
1903
+ UAParser.CPU = enumerize([ARCHITECTURE]);
1904
+ UAParser.DEVICE = enumerize([MODEL, VENDOR, TYPE, CONSOLE, MOBILE, SMARTTV, TABLET, WEARABLE, EMBEDDED]);
1905
+ UAParser.ENGINE = UAParser.OS = enumerize([NAME, VERSION]);
1906
+
1907
+ ///////////
1908
+ // Export
1909
+ //////////
1910
+
1911
+ // check js environment
1912
+ {
1913
+ // nodejs env
1914
+ if (module.exports) {
1915
+ exports = module.exports = UAParser;
1916
+ }
1917
+ exports.UAParser = UAParser;
1918
+ }
1919
+
1920
+ // jQuery/Zepto specific (optional)
1921
+ // Note:
1922
+ // In AMD env the global scope should be kept clean, but jQuery is an exception.
1923
+ // jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
1924
+ // and we should catch that.
1925
+ var $ = typeof window !== UNDEF_TYPE && (window.jQuery || window.Zepto);
1926
+ if ($ && !$.ua) {
1927
+ var parser = new UAParser();
1928
+ $.ua = parser.getResult();
1929
+ $.ua.get = function () {
1930
+ return parser.getUA();
1931
+ };
1932
+ $.ua.set = function (ua) {
1933
+ parser.setUA(ua);
1934
+ var result = parser.getResult();
1935
+ for (var prop in result) {
1936
+ $.ua[prop] = result[prop];
1937
+ }
1938
+ };
1939
+ }
1940
+
1941
+ })(typeof window === 'object' ? window : commonjsGlobal);
1942
+ } (uaParser, uaParser.exports));
1943
+
1944
+ var uaParserExports = uaParser.exports;
1945
+ var UAParser = /*@__PURE__*/getDefaultExportFromCjs(uaParserExports);
1946
+
1947
+ function getBrowserInfo() {
1948
+ var _a = new UAParser().getResult(), browser = _a.browser, device = _a.device, os = _a.os;
1949
+ var data = {
1950
+ H_timezone_offset: new Date().getTimezoneOffset(),
1951
+ H_viewport_width: getScreenWidth(),
1952
+ H_viewport_height: getScreenHeight(),
1953
+ H_screen_width: window.screen.width,
1954
+ H_screen_height: window.screen.height,
1955
+ H_lib_version: PV_LIB_VERSION,
1956
+ H_lib: 'js',
1957
+ H_lib_method: 'code',
1958
+ H_browser: browser.name.toLowerCase(),
1959
+ H_browser_version: browser.version,
1960
+ H_os: os.name,
1961
+ H_os_version: os.version,
1962
+ H_language: isString(navigator.language)
1963
+ ? navigator.language.toLowerCase()
1964
+ : '取值异常',
1965
+ H_network_type: networkType()
1966
+ };
1967
+ if (device.type === 'mobile') {
1968
+ data.H_model = device.vendor ? device.model : 'UnknownPhone';
1969
+ }
1970
+ else {
1971
+ data.H_model = device.model;
1972
+ }
1973
+ return data;
1974
+ }
1975
+
1976
+ var Request = /** @class */ (function () {
1977
+ function Request(options) {
1978
+ this.options = options;
1979
+ }
1980
+ return Request;
1981
+ }());
1982
+ /**
1983
+ * 图片请求
1984
+ */
1985
+ var ImageRequest = /** @class */ (function (_super) {
1986
+ __extends(ImageRequest, _super);
1987
+ function ImageRequest(options) {
1988
+ var _this = _super.call(this, options) || this;
1989
+ _this.options = options;
1990
+ return _this;
1991
+ }
1992
+ ImageRequest.prototype.run = function () {
1993
+ var _this = this;
1994
+ return new Promise(function (resolve) {
1995
+ var _a = _this.options, imgUseCrossOrigin = _a.imgUseCrossOrigin, url = _a.url, data = _a.data;
1996
+ var img = new Image();
1997
+ if (imgUseCrossOrigin) {
1998
+ img.crossOrigin = 'anonymous';
1999
+ }
2000
+ var spliceStr = url.indexOf('?') === -1 ? '?' : '&';
2001
+ img.src = "".concat(url).concat(spliceStr, "data=").concat(data);
2002
+ var callback = function (type) {
2003
+ img.src = null;
2004
+ img = null;
2005
+ resolve({ type: type });
2006
+ };
2007
+ img.onload = function () {
2008
+ callback('success');
2009
+ };
2010
+ img.onerror = function () {
2011
+ callback('error');
2012
+ };
2013
+ img.onabort = function () {
2014
+ callback('abort');
2015
+ };
2016
+ });
2017
+ };
2018
+ return ImageRequest;
2019
+ }(Request));
2020
+ /**
2021
+ * ajax请求
2022
+ */
2023
+ var AjaxRequest = /** @class */ (function (_super) {
2024
+ __extends(AjaxRequest, _super);
2025
+ function AjaxRequest(options) {
2026
+ var _this = _super.call(this, options) || this;
2027
+ _this.options = options;
2028
+ return _this;
2029
+ }
2030
+ AjaxRequest.prototype.run = function () {
2031
+ var _this = this;
2032
+ return new Promise(function (resolve) {
2033
+ var _a = _this.options, url = _a.url, data = _a.data, timeout = _a.timeout;
2034
+ var xhr = new XMLHttpRequest();
2035
+ xhr.open('POST', url, true);
2036
+ xhr.timeout = timeout || 20000;
2037
+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
2038
+ xhr.send(data || null);
2039
+ xhr.onreadystatechange = function () {
2040
+ if (xhr.readyState === 4) {
2041
+ if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
2042
+ resolve({
2043
+ type: 'success'
2044
+ });
2045
+ }
2046
+ else {
2047
+ resolve({
2048
+ type: 'error',
2049
+ msg: "\u7F51\u7EDC\u5F02\u5E38, \u8BF7\u6C42\u5931\u8D25".concat(xhr.status)
2050
+ });
2051
+ }
2052
+ }
2053
+ };
2054
+ });
2055
+ };
2056
+ return AjaxRequest;
2057
+ }(Request));
2058
+ /**
2059
+ * beacon请求
2060
+ */
2061
+ var BeaconRequest = /** @class */ (function (_super) {
2062
+ __extends(BeaconRequest, _super);
2063
+ function BeaconRequest(options) {
2064
+ var _this = _super.call(this, options) || this;
2065
+ _this.options = options;
2066
+ return _this;
2067
+ }
2068
+ BeaconRequest.prototype.run = function () {
2069
+ var _this = this;
2070
+ return new Promise(function (resolve) {
2071
+ var _a = _this.options, url = _a.url, data = _a.data;
2072
+ if (navigator.sendBeacon) {
2073
+ var isSuccess = navigator.sendBeacon(url, data);
2074
+ if (isSuccess) {
2075
+ resolve({
2076
+ type: 'success'
2077
+ });
2078
+ }
2079
+ else {
2080
+ resolve({
2081
+ type: 'error',
2082
+ msg: 'sendBeacon 请求失败'
2083
+ });
2084
+ }
2085
+ }
2086
+ });
2087
+ };
2088
+ return BeaconRequest;
2089
+ }(Request));
2090
+
2091
+ var Mitt = /** @class */ (function () {
2092
+ function Mitt() {
2093
+ this.all = new Map();
2094
+ }
2095
+ Mitt.prototype.on = function (type, handler) {
2096
+ var handlers = this.all.get(type);
2097
+ if (handlers) {
2098
+ handlers.push(handler);
2099
+ }
2100
+ else {
2101
+ this.all.set(type, [handler]);
2102
+ }
2103
+ };
2104
+ Mitt.prototype.emit = function (type) {
2105
+ var args = [];
2106
+ for (var _i = 1; _i < arguments.length; _i++) {
2107
+ args[_i - 1] = arguments[_i];
2108
+ }
2109
+ var handlers = this.all.get(type);
2110
+ if (handlers) {
2111
+ handlers.forEach(function (handler) {
2112
+ handler.apply(void 0, __spreadArray([], __read(args), false));
2113
+ });
2114
+ }
2115
+ };
2116
+ Mitt.prototype.off = function (type, handler) {
2117
+ var handlers = this.all.get(type);
2118
+ if (handlers) {
2119
+ if (handler) {
2120
+ var index = handlers.indexOf(handler);
2121
+ if (index >= 0) {
2122
+ handlers.splice(index, 1);
2123
+ }
2124
+ }
2125
+ else {
2126
+ this.all.set(type, []);
2127
+ }
2128
+ }
2129
+ };
2130
+ return Mitt;
2131
+ }());
2132
+ var mitt = new Mitt();
2133
+
2134
+ /**
2135
+ * 是否支持console
2136
+ */
2137
+ function supportConsole() {
2138
+ return typeof console !== 'undefined';
2139
+ }
2140
+ /**
2141
+ * 打印日志
2142
+ * @param message
2143
+ * @param type
2144
+ */
2145
+ function log(message, type) {
2146
+ if (type === void 0) { type = ConsoleTypes.LOG; }
2147
+ var func = console[type] || console.log;
2148
+ if (typeof func === 'function') {
2149
+ func(message);
2150
+ }
2151
+ }
2152
+
2153
+ var IS_NEW_USER_KEY = 'hinasdk_isNewUser';
2154
+ var State = /** @class */ (function () {
2155
+ function State(options) {
2156
+ this.options = options;
2157
+ this.storeName = 'hinasdk_crossdata';
2158
+ /**
2159
+ * 存储对象
2160
+ */
2161
+ this.state = {
2162
+ accountId: null,
2163
+ deviceId: null,
2164
+ anonymousId: null,
2165
+ firstVisitTime: nowStamp(),
2166
+ props: {}
2167
+ };
2168
+ /**
2169
+ * 首次触发事件
2170
+ */
2171
+ this.isFirstTime = false;
2172
+ /**
2173
+ * 首日触发事件
2174
+ */
2175
+ this.isFirstDay = false;
2176
+ /**
2177
+ * 是否设置第一次访问属性
2178
+ */
2179
+ this.isSetFirstVisit = true;
2180
+ }
2181
+ State.prototype.log = function (message, type) {
2182
+ if (type === void 0) { type = ConsoleTypes.LOG; }
2183
+ var showLog = this.options.showLog;
2184
+ if (!supportConsole() || !showLog)
2185
+ return;
2186
+ log(message, type);
2187
+ };
2188
+ /**
2189
+ * 初始化存储
2190
+ */
2191
+ State.prototype.init = function () {
2192
+ var cookieStorage = new CookieStorage();
2193
+ var memoryStorage = new MemoryStorage();
2194
+ var localStorage = new LocalStorage();
2195
+ if (cookieStorage.isSupport()) {
2196
+ this.storage = cookieStorage;
2197
+ }
2198
+ else {
2199
+ this.log('Cookie storage is not supported, SDK internal cache has been enabled', ConsoleTypes.WARN);
2200
+ this.storage = memoryStorage;
2201
+ }
2202
+ if (localStorage.isSupport()) {
2203
+ this.localStorage = localStorage;
2204
+ }
2205
+ else {
2206
+ this.log('localStorage is not supported, SDK internal cache has been enabled', ConsoleTypes.WARN);
2207
+ }
2208
+ var oldState;
2209
+ oldState = this.storage.get(this.storeName);
2210
+ if (!oldState && this.localStorage) {
2211
+ oldState = this.localStorage.get(this.storeName);
2212
+ }
2213
+ if (oldState && isJSONString(oldState)) {
2214
+ try {
2215
+ oldState = JSON.parse(oldState);
2216
+ this.state = merge(this.state, oldState);
2217
+ }
2218
+ catch (e) {
2219
+ this.log(e, ConsoleTypes.ERROR);
2220
+ }
2221
+ }
2222
+ // 如果不存在hinasdk_crossdata的存储数据,则说明是第一次访问sdk
2223
+ if (oldState) {
2224
+ this.isSetFirstVisit = false;
2225
+ this.save();
2226
+ }
2227
+ else {
2228
+ this.isFirstDay = true;
2229
+ this.isFirstTime = true;
2230
+ var date = new Date();
2231
+ var dateObj = {
2232
+ h: 23 - date.getHours(),
2233
+ m: 59 - date.getMinutes(),
2234
+ s: 59 - date.getSeconds()
2235
+ };
2236
+ var second = dateObj.h * 3600 + dateObj.m * 60 + dateObj.s;
2237
+ // todo 设置这个值似乎没有什么用
2238
+ this.storage.set(IS_NEW_USER_KEY, 'true', second);
2239
+ }
2240
+ // 第一次需要生成匿名ID和设备ID,此时这两个ID是一致的,其中设备ID可以修改,但是匿名ID设置了之后 就不能再改变了
2241
+ var uuid = generatorUUID();
2242
+ if (!this.getAnonymousId()) {
2243
+ this.setAnonymousId(uuid);
2244
+ }
2245
+ if (!this.getDeviceId()) {
2246
+ this.setDeviceId(uuid);
2247
+ }
2248
+ };
2249
+ /**
2250
+ * 清空state数据
2251
+ */
2252
+ State.prototype.clear = function () {
2253
+ this.state = {};
2254
+ this.save();
2255
+ };
2256
+ /**
2257
+ * 缓存state数据
2258
+ */
2259
+ State.prototype.save = function () {
2260
+ // cookie存于子域名中,用于跨站共享
2261
+ this.storage.setDomain(this.storeName, JSON.stringify(this.state));
2262
+ if (this.localStorage) {
2263
+ this.localStorage.set(this.storeName, JSON.stringify(this.state));
2264
+ }
2265
+ };
2266
+ /**
2267
+ * 设置共享数据
2268
+ * @param name
2269
+ * @param value
2270
+ */
2271
+ State.prototype.set = function (name, value) {
2272
+ this.state[name] = value;
2273
+ this.save();
2274
+ };
2275
+ /**
2276
+ * 检查设置值是否合法
2277
+ * @param name
2278
+ * @param value
2279
+ */
2280
+ State.prototype.checkSetValue = function (name, value) {
2281
+ value = value !== null && value !== void 0 ? value : '';
2282
+ if (isNumber(value) || isString(value)) {
2283
+ return true;
2284
+ }
2285
+ this.log("".concat(name, ": id must be string or number"), ConsoleTypes.WARN);
2286
+ return false;
2287
+ };
2288
+ /**
2289
+ * 设置deviceId
2290
+ * @param id
2291
+ */
2292
+ State.prototype.setDeviceId = function (id) {
2293
+ if (id === void 0) { id = ''; }
2294
+ if (this.checkSetValue('deviceId', id)) {
2295
+ this.set('deviceId', id);
2296
+ }
2297
+ };
2298
+ /**
2299
+ * 设置账号id
2300
+ * @param id
2301
+ */
2302
+ State.prototype.setAccountId = function (id) {
2303
+ if (id === void 0) { id = ''; }
2304
+ if (this.checkSetValue('accountId', id)) {
2305
+ this.set('accountId', id);
2306
+ }
2307
+ };
2308
+ /**
2309
+ * 设置匿名id
2310
+ * @param id
2311
+ */
2312
+ State.prototype.setAnonymousId = function (id) {
2313
+ if (this.state.anonymousId) {
2314
+ this.log("Current anonymousId is ".concat(this.getAnonymousId(), ", it has been set"), ConsoleTypes.WARN);
2315
+ return;
2316
+ }
2317
+ if (this.checkSetValue('anonymousId', id)) {
2318
+ this.set('anonymousId', id);
2319
+ }
2320
+ };
2321
+ /**
2322
+ * 设置广告参数
2323
+ * @param props
2324
+ */
2325
+ State.prototype.setProps = function (props) {
2326
+ var newProps = merge(this.state.props || {}, props);
2327
+ for (var key in newProps) {
2328
+ if (typeof newProps[key] === 'string') {
2329
+ newProps[key] = newProps[key].slice(0, MAX_REFERRER_STRING_LENGTH);
2330
+ }
2331
+ }
2332
+ this.set('props', newProps);
2333
+ };
2334
+ /**
2335
+ * 获取匿名ID
2336
+ */
2337
+ State.prototype.getAnonymousId = function () {
2338
+ return this.state.anonymousId;
2339
+ };
2340
+ /**
2341
+ * 获取设备ID
2342
+ */
2343
+ State.prototype.getDeviceId = function () {
2344
+ return this.state.deviceId;
2345
+ };
2346
+ /**
2347
+ * 获取账户ID
2348
+ */
2349
+ State.prototype.getAccountId = function () {
2350
+ return this.state.accountId;
2351
+ };
2352
+ /**
2353
+ * 获取cookie值
2354
+ */
2355
+ State.prototype.getCookie = function () {
2356
+ return this.storage.get(this.storeName);
2357
+ };
2358
+ return State;
2359
+ }());
2360
+
2361
+ var BaseCore = /** @class */ (function () {
2362
+ function BaseCore(options, useInstancing) {
2363
+ if (useInstancing === void 0) { useInstancing = true; }
2364
+ /**
2365
+ * SDK是否已准备就绪
2366
+ */
2367
+ this.isReady = false;
2368
+ /**
2369
+ * 控制台前缀
2370
+ */
2371
+ this.consolePrefix = '';
2372
+ /**
2373
+ * 初始化SDK的方式,默认为true,即通过new的方式初始化SDK,如果使用函数调用初始化SDK,则设置为false
2374
+ */
2375
+ this.useInstancing = true;
2376
+ this.options = options;
2377
+ this.useInstancing = useInstancing;
2378
+ }
2379
+ /**
2380
+ * 打印日志
2381
+ * @param message 日志消息
2382
+ * @param type 日志类型
2383
+ */
2384
+ BaseCore.prototype.log = function (message, type) {
2385
+ if (type === void 0) { type = ConsoleTypes.LOG; }
2386
+ var showLog = this.options.showLog;
2387
+ if (!supportConsole() || !showLog)
2388
+ return;
2389
+ if (typeof message === 'string' && this.consolePrefix) {
2390
+ message = "".concat(this.consolePrefix, "\uFF1A").concat(message);
2391
+ }
2392
+ log(message, type);
2393
+ };
2394
+ /**
2395
+ * 执行插件
2396
+ * @param plugins
2397
+ */
2398
+ BaseCore.prototype.runPlugins = function (plugins) {
2399
+ var _this = this;
2400
+ var _loop_1 = function (i) {
2401
+ var plugin = plugins[i];
2402
+ plugin.init(function (data) {
2403
+ if (!plugin.transform)
2404
+ return;
2405
+ var result = plugin.transform(data);
2406
+ if (!result)
2407
+ return;
2408
+ _this.report(result);
2409
+ });
2410
+ };
2411
+ for (var i = 0; i < plugins.length; i++) {
2412
+ _loop_1(i);
2413
+ }
2414
+ };
2415
+ return BaseCore;
2416
+ }());
2417
+
2418
+ var GET_DEFAULT_OPTIONS = function () {
2419
+ return {
2420
+ name: '',
2421
+ serverUrl: '',
2422
+ showLog: false,
2423
+ autoTrackConfig: {
2424
+ clickAutoTrack: true,
2425
+ stayAutoTrack: true,
2426
+ isCollectUrl: function () { return true; },
2427
+ isCollectElement: function () { return true; },
2428
+ isCollectInput: function () { return false; },
2429
+ addCustomProperty: function () { },
2430
+ stayDelayTime: 4000,
2431
+ maxStayPageDuration: 18000,
2432
+ collectTags: {
2433
+ div: false
2434
+ },
2435
+ trackAttr: ['hn-click'],
2436
+ pageviewAutoTrack: false,
2437
+ pageLeaveAutoTrack: false
2438
+ },
2439
+ stayAutoTrackConfig: {
2440
+ isCollectUrl: function () { return true; }
2441
+ },
2442
+ imgUseCrossOrigin: false,
2443
+ isSinglePage: false,
2444
+ batchSend: false,
2445
+ appJsBridge: false,
2446
+ sendType: ReportType.IMAGE,
2447
+ dataSendTimeout: 3000,
2448
+ presetProperties: {
2449
+ latest_utm: true,
2450
+ latest_utm_source: true,
2451
+ latest_traffic_source_type: true,
2452
+ latest_search_keyword: true,
2453
+ latest_referrer: true,
2454
+ url: true,
2455
+ title: true
2456
+ }
2457
+ };
2458
+ };
2459
+ var ignoreTags = [
2460
+ 'mark',
2461
+ '/mark',
2462
+ 'strong',
2463
+ 'b',
2464
+ 'em',
2465
+ 'i',
2466
+ 'u',
2467
+ 'abbr',
2468
+ 'ins',
2469
+ 'del',
2470
+ 's',
2471
+ 'sup'
2472
+ ];
2473
+ var defaultTags = ['a', 'input', 'button', 'textarea'];
2474
+
2475
+ /**
2476
+ * @description 批量发送数据
2477
+ */
2478
+ var BatchSend = /** @class */ (function () {
2479
+ function BatchSend(context) {
2480
+ this.context = context;
2481
+ this.batchKey = 'hinasdk_tab';
2482
+ this.batchDataKey = 'hinasdk_data_';
2483
+ this.batchInterval();
2484
+ }
2485
+ BatchSend.prototype.getBatchConfig = function () {
2486
+ var batchSend = this.context.options.batchSend;
2487
+ return batchSend;
2488
+ };
2489
+ BatchSend.prototype.getStorageList = function () {
2490
+ var _a;
2491
+ var list = [];
2492
+ var tabStorage = (_a = this.context.store.localStorage) === null || _a === void 0 ? void 0 : _a.get(this.batchKey);
2493
+ if (tabStorage) {
2494
+ list = safeJSONParse(tabStorage);
2495
+ if (!isArray(list)) {
2496
+ list = [];
2497
+ }
2498
+ }
2499
+ return list;
2500
+ };
2501
+ BatchSend.prototype.batchInterval = function () {
2502
+ var _this = this;
2503
+ var sendInterval = this.getBatchConfig().sendInterval;
2504
+ setTimeout(function () {
2505
+ _this.send().then(function () {
2506
+ _this.batchInterval();
2507
+ });
2508
+ }, sendInterval);
2509
+ };
2510
+ BatchSend.prototype.send = function () {
2511
+ var _this = this;
2512
+ return new Promise(function (resolve) {
2513
+ var _a;
2514
+ var tabStorageList = _this.getStorageList();
2515
+ if (tabStorageList.length > 0) {
2516
+ var _b = _this.getBatchConfig(), storageLimit = _b.storageLimit, dataSendTimeout = _b.dataSendTimeout;
2517
+ var now = nowStamp();
2518
+ var list = [];
2519
+ var removeKeys_1 = [];
2520
+ var len = tabStorageList.length;
2521
+ for (var i = 0; i < len; i++) {
2522
+ var _c = tabStorageList[i], dataKey = _c.dataKey, expireTime = _c.expireTime;
2523
+ removeKeys_1.push(dataKey);
2524
+ if (expireTime >= now) {
2525
+ var data = (_a = _this.context.store.localStorage) === null || _a === void 0 ? void 0 : _a.get(dataKey);
2526
+ if (data) {
2527
+ list.push(safeJSONParse(data));
2528
+ }
2529
+ }
2530
+ }
2531
+ list = list.filter(Boolean);
2532
+ if (list.length > storageLimit) {
2533
+ list = list.slice(0, storageLimit);
2534
+ }
2535
+ if (list.length === 0) {
2536
+ resolve();
2537
+ }
2538
+ else {
2539
+ var serverUrl = _this.context.options.serverUrl;
2540
+ var listStr = JSON.stringify(list);
2541
+ new AjaxRequest({
2542
+ url: serverUrl,
2543
+ data: "data_list=".concat(base64Encode(listStr)),
2544
+ timeout: dataSendTimeout
2545
+ })
2546
+ .run()
2547
+ .then(function (res) {
2548
+ if (res.type === 'success') {
2549
+ _this.remove(removeKeys_1);
2550
+ }
2551
+ resolve();
2552
+ });
2553
+ }
2554
+ }
2555
+ });
2556
+ };
2557
+ BatchSend.prototype.remove = function (removeKeys) {
2558
+ var _this = this;
2559
+ var _a;
2560
+ var firstKey = removeKeys[0];
2561
+ var tabStorageList = this.getStorageList();
2562
+ // 删除hinasdk_data_开头的数据
2563
+ removeKeys.forEach(function (key) {
2564
+ var _a;
2565
+ (_a = _this.context.store.localStorage) === null || _a === void 0 ? void 0 : _a.remove(key);
2566
+ });
2567
+ // 删除hinasdk_tab数据
2568
+ var index = tabStorageList.findIndex(function (item) { return item.dataKey === firstKey; });
2569
+ if (index >= 0) {
2570
+ var list = tabStorageList.slice(0, index);
2571
+ (_a = this.context.store.localStorage) === null || _a === void 0 ? void 0 : _a.set(this.batchKey, JSON.stringify(list));
2572
+ }
2573
+ };
2574
+ BatchSend.prototype.add = function (data) {
2575
+ var _a, _b;
2576
+ var _c = this.getBatchConfig(), sendInterval = _c.sendInterval, storageLimit = _c.storageLimit;
2577
+ var dataKey = this.batchDataKey + getRandom();
2578
+ var tabStorage = this.getStorageList();
2579
+ tabStorage.unshift({
2580
+ dataKey: dataKey,
2581
+ expireTime: nowStamp() + sendInterval * 2
2582
+ });
2583
+ (_a = this.context.store.localStorage) === null || _a === void 0 ? void 0 : _a.set(this.batchKey, JSON.stringify(tabStorage));
2584
+ (_b = this.context.store.localStorage) === null || _b === void 0 ? void 0 : _b.set(dataKey, JSON.stringify(data));
2585
+ /**
2586
+ * 满足以下条件,则发送数据
2587
+ * 1. localStorage 条数超过最大限制
2588
+ * 2. 发送类型为 track_signup 或 H_pageview
2589
+ */
2590
+ if (tabStorage.length > storageLimit ||
2591
+ data.type === 'track_signup' ||
2592
+ data.event === 'H_pageview') {
2593
+ this.send();
2594
+ }
2595
+ };
2596
+ return BatchSend;
2597
+ }());
2598
+
2599
+ var ClickTrackPlugin = /** @class */ (function (_super) {
2600
+ __extends(ClickTrackPlugin, _super);
2601
+ function ClickTrackPlugin(options, context) {
2602
+ var _this = _super.call(this, options, context) || this;
2603
+ _this.options = options;
2604
+ _this.context = context;
2605
+ /**
2606
+ * 插件名
2607
+ */
2608
+ _this.name = 'ClickTrackPlugin';
2609
+ /**
2610
+ * 默认采集标签
2611
+ */
2612
+ _this.isTrackList = {
2613
+ a: true,
2614
+ button: true
2615
+ };
2616
+ return _this;
2617
+ }
2618
+ ClickTrackPlugin.prototype.init = function (notify) {
2619
+ var _this = this;
2620
+ var _a = this.options.autoTrackConfig, clickAutoTrack = _a.clickAutoTrack, isCollectUrl = _a.isCollectUrl, isCollectElement = _a.isCollectElement, addCustomProperty = _a.addCustomProperty;
2621
+ if (clickAutoTrack !== true)
2622
+ return;
2623
+ document.addEventListener('click', function (e) {
2624
+ if (!isCollectUrl())
2625
+ return;
2626
+ var event = e || window.event;
2627
+ if (!event)
2628
+ return;
2629
+ var eventTarget = event.target || event.srcElement;
2630
+ var target = _this.getTargetElement(eventTarget, event);
2631
+ if (target) {
2632
+ // 判断是否要上报此元素的点击事件
2633
+ if (isFunction(isCollectElement) && !isCollectElement(target)) {
2634
+ return false;
2635
+ }
2636
+ var props = _this.getClickElementInfo(target);
2637
+ var _a = _this.getPageXYInfo(event, target), H_page_x = _a.H_page_x, H_page_y = _a.H_page_y;
2638
+ props.H_page_x = H_page_x;
2639
+ props.H_page_y = H_page_y;
2640
+ if (isFunction(addCustomProperty)) {
2641
+ var customProperty = addCustomProperty(target);
2642
+ if (isObject(customProperty)) {
2643
+ props = merge(props, customProperty);
2644
+ }
2645
+ }
2646
+ notify(props);
2647
+ }
2648
+ }, true);
2649
+ };
2650
+ ClickTrackPlugin.prototype.transform = function (data) {
2651
+ var props = this.context.getReportData('track', 'H_WebClick', data);
2652
+ return props;
2653
+ };
2654
+ ClickTrackPlugin.prototype.hasAttribute = function (element, attrName) {
2655
+ var _a;
2656
+ if (element.hasAttribute) {
2657
+ return element.hasAttribute(attrName);
2658
+ }
2659
+ if (element.attributes) {
2660
+ return !!((_a = element.attributes[attrName]) === null || _a === void 0 ? void 0 : _a.value);
2661
+ }
2662
+ };
2663
+ ClickTrackPlugin.prototype.hasAttributes = function (element, attrNames) {
2664
+ if (isArray(attrNames)) {
2665
+ for (var i = 0; i < attrNames.length; i++) {
2666
+ if (this.hasAttribute(element, attrNames[i])) {
2667
+ return true;
2668
+ }
2669
+ }
2670
+ }
2671
+ return false;
2672
+ };
2673
+ ClickTrackPlugin.prototype.hasElement = function (element) {
2674
+ var e_1, _a;
2675
+ var _b;
2676
+ var paths = getElementParents(element);
2677
+ var trackAttr = this.options.autoTrackConfig.trackAttr || [];
2678
+ if (isArray(paths) && paths.length > 0) {
2679
+ try {
2680
+ for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
2681
+ var path = paths_1_1.value;
2682
+ var tagName = (_b = path.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase();
2683
+ if (isElement(path) &&
2684
+ (this.isTrackList[tagName] || this.hasAttributes(path, trackAttr))) {
2685
+ return path;
2686
+ }
2687
+ }
2688
+ }
2689
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2690
+ finally {
2691
+ try {
2692
+ if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
2693
+ }
2694
+ finally { if (e_1) throw e_1.error; }
2695
+ }
2696
+ }
2697
+ };
2698
+ ClickTrackPlugin.prototype.getDivMaxLevel = function () {
2699
+ var _a;
2700
+ var collectTags = this.options.autoTrackConfig.collectTags;
2701
+ return ((_a = collectTags.div) === null || _a === void 0 ? void 0 : _a.maxLevel) || 1;
2702
+ };
2703
+ /**
2704
+ * 针对div标签,判断是否是忽略的样式标签
2705
+ * @param tagName
2706
+ */
2707
+ ClickTrackPlugin.prototype.isStyleTag = function (tagName) {
2708
+ var _a;
2709
+ var collectTags = this.options.autoTrackConfig.collectTags;
2710
+ var ignoreTags = ((_a = collectTags.div) === null || _a === void 0 ? void 0 : _a.ignoreTags) || [];
2711
+ return ignoreTags === null || ignoreTags === void 0 ? void 0 : ignoreTags.includes(tagName);
2712
+ };
2713
+ /**
2714
+ * 获取可采集元素的父元素
2715
+ * @param target
2716
+ */
2717
+ ClickTrackPlugin.prototype.getCollectableParent = function (target) {
2718
+ var _a;
2719
+ try {
2720
+ var parentNode = target.parentNode;
2721
+ var parentTagName = parentNode ? (_a = parentNode.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase() : '';
2722
+ if (parentTagName === 'body') {
2723
+ return false;
2724
+ }
2725
+ var maxLevel = this.getDivMaxLevel();
2726
+ if (parentTagName === 'div' &&
2727
+ (maxLevel > 1 || this.isCollectableDiv(parentNode))) {
2728
+ return parentNode;
2729
+ }
2730
+ if (parentNode && this.isStyleTag(parentTagName)) {
2731
+ return this.getCollectableParent(parentNode);
2732
+ }
2733
+ }
2734
+ catch (error) {
2735
+ this.context.log(error, ConsoleTypes.ERROR);
2736
+ }
2737
+ return false;
2738
+ };
2739
+ /**
2740
+ * 是否是可以收集的div
2741
+ * @param element
2742
+ */
2743
+ ClickTrackPlugin.prototype.isCollectableDiv = function (element) {
2744
+ var _a;
2745
+ try {
2746
+ var children = element.children || [];
2747
+ if (children.length === 0) {
2748
+ return true;
2749
+ }
2750
+ for (var i = 0; i < children.length; i++) {
2751
+ var child = children[i];
2752
+ if (isElement(child)) {
2753
+ var tagName = (_a = child.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
2754
+ var maxLevel = this.getDivMaxLevel();
2755
+ if ((tagName === 'div' && maxLevel > 1) || this.isStyleTag(tagName)) {
2756
+ if (!this.isCollectableDiv(child)) {
2757
+ return false;
2758
+ }
2759
+ }
2760
+ else {
2761
+ return false;
2762
+ }
2763
+ }
2764
+ }
2765
+ return true;
2766
+ }
2767
+ catch (error) {
2768
+ this.context.log(error, ConsoleTypes.ERROR);
2769
+ }
2770
+ return false;
2771
+ };
2772
+ /**
2773
+ * 判断div的层级是否有效
2774
+ * @param rootElement
2775
+ */
2776
+ ClickTrackPlugin.prototype.isDivLevelValid = function (rootElement) {
2777
+ var maxLevel = this.getDivMaxLevel();
2778
+ var htmlCollection = rootElement.getElementsByTagName('div');
2779
+ for (var i = htmlCollection.length - 1; i >= 0; i--) {
2780
+ if (this.getDivLevels(htmlCollection[i], rootElement) > maxLevel) {
2781
+ return false;
2782
+ }
2783
+ }
2784
+ return true;
2785
+ };
2786
+ /**
2787
+ * 获取指定元素的路径
2788
+ * @param element 当前元素
2789
+ * @param ignoreId 是否忽略id
2790
+ * @param rootElement 根元素
2791
+ */
2792
+ ClickTrackPlugin.prototype.getElementPath = function (element, ignoreId, rootElement) {
2793
+ var _a, _b;
2794
+ var names = [];
2795
+ while (isElement(element) && element.parentNode) {
2796
+ if (element.id &&
2797
+ !ignoreId &&
2798
+ /^[A-Za-z][-A-Za-z0-9_:.]*$/.test(element.id)) {
2799
+ var tagName = element.tagName || '';
2800
+ names.unshift("".concat(tagName.toLowerCase(), "#").concat(element.id));
2801
+ break;
2802
+ }
2803
+ else {
2804
+ if (rootElement && element === rootElement) {
2805
+ names.unshift((_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase());
2806
+ break;
2807
+ }
2808
+ else if (element === document.body) {
2809
+ names.unshift('body');
2810
+ break;
2811
+ }
2812
+ else {
2813
+ names.unshift((_b = element.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase());
2814
+ }
2815
+ element = element.parentNode;
2816
+ }
2817
+ }
2818
+ return names.join(' > ');
2819
+ };
2820
+ ClickTrackPlugin.prototype.getDivLevels = function (element, rootElement) {
2821
+ var path = this.getElementPath(element, true, rootElement);
2822
+ var pathArr = path.split(' > ');
2823
+ var level = 0;
2824
+ pathArr.forEach(function (tag) {
2825
+ if (tag === 'div') {
2826
+ level++;
2827
+ }
2828
+ });
2829
+ return level;
2830
+ };
2831
+ ClickTrackPlugin.prototype.getTargetElement = function (eventTarget, event) {
2832
+ var _a;
2833
+ if (!isElement(eventTarget)) {
2834
+ return null;
2835
+ }
2836
+ var tagName = (_a = eventTarget.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
2837
+ if (!isString(tagName)) {
2838
+ return null;
2839
+ }
2840
+ if (['body', 'html'].includes(tagName)) {
2841
+ return null;
2842
+ }
2843
+ if (this.context.trackTags.includes(tagName) && tagName !== 'div') {
2844
+ return eventTarget;
2845
+ }
2846
+ /**
2847
+ * div处理情况
2848
+ * 1.div为子结点(无子元素)时采集 div 的点击;
2849
+ * 2.div中有且只有样式标签([‘mark’,’strong’,’b’,’em’,’i’,’u’,’abbr’,’ins’,’del’,’s’,’sup’])时,点击 div 或者样式标签都采集 div 的点击。
2850
+ * 3.div 通过配置最多可以采集3层嵌套情况
2851
+ */
2852
+ if (tagName === 'div') {
2853
+ if (this.isDivLevelValid(eventTarget)) {
2854
+ var maxLevel = this.getDivMaxLevel();
2855
+ if (maxLevel > 1 || this.isCollectableDiv(eventTarget)) {
2856
+ return eventTarget;
2857
+ }
2858
+ }
2859
+ }
2860
+ if (this.isStyleTag(tagName) &&
2861
+ this.options.autoTrackConfig.collectTags.div) {
2862
+ var parentTrackDiv = this.getCollectableParent(eventTarget);
2863
+ if (parentTrackDiv && this.isDivLevelValid(parentTrackDiv)) {
2864
+ return parentTrackDiv;
2865
+ }
2866
+ }
2867
+ return this.hasElement(eventTarget) || null;
2868
+ };
2869
+ ClickTrackPlugin.prototype.getPageXYInfo = function (event, target) {
2870
+ if (!event) {
2871
+ return {};
2872
+ }
2873
+ var scrollLeft = getScrollLeft();
2874
+ var scrollTop = getScrollTop();
2875
+ var rect = target.getBoundingClientRect();
2876
+ var pageX = event.pageX ||
2877
+ event.clientX + scrollLeft ||
2878
+ event.offsetX + ((rect === null || rect === void 0 ? void 0 : rect.left) || 0) + scrollLeft;
2879
+ var pageY = event.pageY ||
2880
+ event.clientY + scrollTop ||
2881
+ event.offsetY + ((rect === null || rect === void 0 ? void 0 : rect.top) || 0) + scrollTop;
2882
+ return {
2883
+ H_page_x: formatDecimal(pageX, 3),
2884
+ H_page_y: formatDecimal(pageY, 3)
2885
+ };
2886
+ };
2887
+ ClickTrackPlugin.prototype.getClickElementInfo = function (element) {
2888
+ var isCollectInput = this.options.autoTrackConfig.isCollectInput;
2889
+ var isCollectInputValue = false;
2890
+ if (isFunction(isCollectInput)) {
2891
+ isCollectInputValue = isCollectInput(element);
2892
+ }
2893
+ var selector = this.getDomSelector(element);
2894
+ var props = getElementProperties(element, isCollectInputValue);
2895
+ props.H_element_selector = selector;
2896
+ props.H_element_path = this.getElementPath(element, false);
2897
+ return props;
2898
+ };
2899
+ ClickTrackPlugin.prototype.getDomSelector = function (element) {
2900
+ var _a;
2901
+ var paths = [];
2902
+ while (element) {
2903
+ var tagName = (_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
2904
+ if (tagName === 'body' || !isElement(element)) {
2905
+ paths.unshift('body');
2906
+ break;
2907
+ }
2908
+ paths.unshift(this.getSelector(element));
2909
+ if ((element === null || element === void 0 ? void 0 : element.getAttribute('id')) &&
2910
+ /^[A-Za-z][-A-Za-z0-9_:.]*$/.test(element.getAttribute('id'))) {
2911
+ break;
2912
+ }
2913
+ element = element.parentNode;
2914
+ }
2915
+ return paths.join(' > ');
2916
+ };
2917
+ ClickTrackPlugin.prototype.getSelector = function (element) {
2918
+ var _a, _b;
2919
+ var tagName = (_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
2920
+ var i = -1;
2921
+ if (((_b = element.parentNode) === null || _b === void 0 ? void 0 : _b.nodeType) !== 9) {
2922
+ i = this.getDomIndex(element);
2923
+ }
2924
+ var idValue = element.getAttribute('id');
2925
+ if (idValue && /^[A-Za-z][-A-Za-z0-9_:.]*$/.test(idValue)) {
2926
+ return "#".concat(idValue);
2927
+ }
2928
+ return tagName + (i > -1 ? ":nth-of-type(".concat(i + 1, ")") : '');
2929
+ };
2930
+ ClickTrackPlugin.prototype.getDomIndex = function (element) {
2931
+ var _a, _b;
2932
+ if (element.parentNode) {
2933
+ var index = 0;
2934
+ var tagName = (_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
2935
+ var children = element.parentNode.children;
2936
+ for (var i = 0; i < children.length; i++) {
2937
+ var child = children[i];
2938
+ var childTagName = (_b = child.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase();
2939
+ if (childTagName === tagName) {
2940
+ if (child === element) {
2941
+ return index;
2942
+ }
2943
+ index++;
2944
+ }
2945
+ }
2946
+ }
2947
+ return -1;
2948
+ };
2949
+ return ClickTrackPlugin;
2950
+ }(PluginBase));
2951
+
2952
+ var StayTrackPlugin = /** @class */ (function (_super) {
2953
+ __extends(StayTrackPlugin, _super);
2954
+ function StayTrackPlugin(options, context) {
2955
+ var _this = _super.call(this, options, context) || this;
2956
+ _this.options = options;
2957
+ _this.context = context;
2958
+ _this.name = 'StayTrackPlugin';
2959
+ _this.timer = null;
2960
+ _this.previousTime = nowStamp();
2961
+ _this.previousOffsetTop = 0;
2962
+ return _this;
2963
+ }
2964
+ StayTrackPlugin.prototype.init = function (notify) {
2965
+ var _this = this;
2966
+ var _a = this.options, autoTrackConfig = _a.autoTrackConfig, stayAutoTrackConfig = _a.stayAutoTrackConfig;
2967
+ if (autoTrackConfig.stayAutoTrack !== true) {
2968
+ return;
2969
+ }
2970
+ var isCollectUrl = stayAutoTrackConfig.isCollectUrl;
2971
+ if (!isFunction(isCollectUrl)) {
2972
+ isCollectUrl = function () { return true; };
2973
+ }
2974
+ if (this.timer) {
2975
+ clearTimeout(this.timer);
2976
+ this.timer = null;
2977
+ }
2978
+ this.previousTime = nowStamp();
2979
+ window.addEventListener('load', function () {
2980
+ _this.previousOffsetTop = getScrollTop();
2981
+ });
2982
+ window.addEventListener('scroll', function () {
2983
+ if (!isCollectUrl())
2984
+ return;
2985
+ if (_this.timer)
2986
+ return;
2987
+ _this.timer = setTimeout(function () {
2988
+ _this.run(notify);
2989
+ clearTimeout(_this.timer);
2990
+ _this.timer = null;
2991
+ }, 1000);
2992
+ });
2993
+ window.addEventListener('unload', function () {
2994
+ if (!isCollectUrl())
2995
+ return;
2996
+ _this.run(notify, true);
2997
+ });
2998
+ };
2999
+ StayTrackPlugin.prototype.transform = function (data) {
3000
+ var props = this.context.getReportData('track', 'H_WebStay', data);
3001
+ return props;
3002
+ };
3003
+ StayTrackPlugin.prototype.run = function (notify, isClosePage) {
3004
+ if (isClosePage === void 0) { isClosePage = false; }
3005
+ var autoTrackConfig = this.options.autoTrackConfig;
3006
+ var stayDelayTime = autoTrackConfig.stayDelayTime, maxStayPageDuration = autoTrackConfig.maxStayPageDuration;
3007
+ var offsetTop = getScrollTop();
3008
+ var nowTime = nowStamp();
3009
+ var duration = nowTime - this.previousTime;
3010
+ if (isClosePage ||
3011
+ (duration > stayDelayTime && offsetTop !== this.previousOffsetTop)) {
3012
+ var props = {
3013
+ H_viewport_position: this.previousOffsetTop,
3014
+ event_duration: Math.min(duration / 1000, maxStayPageDuration)
3015
+ };
3016
+ notify(props);
3017
+ }
3018
+ this.previousTime = nowTime;
3019
+ this.previousOffsetTop = offsetTop;
3020
+ };
3021
+ return StayTrackPlugin;
3022
+ }(PluginBase));
3023
+
3024
+ var PageLeavePluginName = 'PageLeavePlugin';
3025
+ var PageLeavePlugin = /** @class */ (function (_super) {
3026
+ __extends(PageLeavePlugin, _super);
3027
+ function PageLeavePlugin(options, context) {
3028
+ var _this = _super.call(this, options, context) || this;
3029
+ _this.options = options;
3030
+ _this.context = context;
3031
+ _this.name = PageLeavePluginName;
3032
+ _this.pageId = Number(String(getRandom()).slice(2, 5) +
3033
+ String(getRandom()).slice(2, 4) +
3034
+ String(nowStamp()).slice(-4));
3035
+ _this.storageName = 'hinasdk_pageleave_';
3036
+ _this.heartbeatIntervalTime = 5000; // 5s
3037
+ _this.maxDuration = 432000; // 5天
3038
+ _this.heartbeatIntervalTimer = null;
3039
+ _this.startTime = nowStamp();
3040
+ /**
3041
+ * 页面url
3042
+ */
3043
+ _this.url = window.location.href;
3044
+ /**
3045
+ * 上一个页面url
3046
+ */
3047
+ _this.previousUrl = document.referrer;
3048
+ /**
3049
+ * 页面显示状态
3050
+ */
3051
+ _this.pageShowStatus = true;
3052
+ return _this;
3053
+ }
3054
+ PageLeavePlugin.prototype.init = function () {
3055
+ var pageLeaveAutoTrack = this.options.autoTrackConfig.pageLeaveAutoTrack;
3056
+ if (!pageLeaveAutoTrack)
3057
+ return;
3058
+ var _a = this.normalizePageLeaveAutoTrack(), heartbeat_interval_time = _a.heartbeat_interval_time, max_duration = _a.max_duration;
3059
+ if (heartbeat_interval_time && heartbeat_interval_time > 0) {
3060
+ this.heartbeatIntervalTime = heartbeat_interval_time * 1000;
3061
+ }
3062
+ if (max_duration && max_duration > 0) {
3063
+ this.maxDuration = Number(max_duration);
3064
+ }
3065
+ this.startTime = nowStamp();
3066
+ this.addPageLeaveEventListener();
3067
+ if (document.hidden) {
3068
+ this.pageShowStatus = false;
3069
+ }
3070
+ else {
3071
+ this.addHeartBeatInterval();
3072
+ }
3073
+ };
3074
+ PageLeavePlugin.prototype.transform = function (data) {
3075
+ return undefined;
3076
+ };
3077
+ PageLeavePlugin.prototype.normalizePageLeaveAutoTrack = function () {
3078
+ var pageLeaveAutoTrack = this.options.autoTrackConfig.pageLeaveAutoTrack;
3079
+ return isObject(pageLeaveAutoTrack)
3080
+ ? pageLeaveAutoTrack
3081
+ : {};
3082
+ };
3083
+ PageLeavePlugin.prototype.addPageLeaveEventListener = function () {
3084
+ this.addPageStartListener();
3085
+ this.addPageSwitchListener();
3086
+ this.addSinglePageListener();
3087
+ this.addPageEndListener();
3088
+ };
3089
+ PageLeavePlugin.prototype.addPageStartListener = function () {
3090
+ var _this = this;
3091
+ if ('onpageshow' in window) {
3092
+ window.addEventListener('pageshow', function () {
3093
+ _this.pageStartHandler();
3094
+ });
3095
+ }
3096
+ };
3097
+ PageLeavePlugin.prototype.addPageSwitchListener = function () {
3098
+ var _this = this;
3099
+ new ListenPageState({
3100
+ visible: function () {
3101
+ _this.pageStartHandler();
3102
+ _this.addHeartBeatInterval();
3103
+ },
3104
+ hidden: function () {
3105
+ _this.url = window.location.href;
3106
+ _this.pageEndHandler();
3107
+ _this.stopHeartBeatInterval();
3108
+ }
3109
+ });
3110
+ };
3111
+ PageLeavePlugin.prototype.addSinglePageListener = function () {
3112
+ var _this = this;
3113
+ mitt.on('urlChange', function (params) {
3114
+ var fromHref = params.fromHref;
3115
+ if (fromHref !== window.location.href) {
3116
+ _this.url = fromHref;
3117
+ _this.pageEndHandler();
3118
+ _this.stopHeartBeatInterval();
3119
+ _this.pageStartHandler();
3120
+ _this.addHeartBeatInterval();
3121
+ }
3122
+ });
3123
+ };
3124
+ PageLeavePlugin.prototype.addPageEndListener = function () {
3125
+ var _this = this;
3126
+ var events = ['pagehide', 'beforeunload', 'unload'];
3127
+ events.forEach(function (event) {
3128
+ if ("on".concat(events) in window) {
3129
+ window.addEventListener(event, function () {
3130
+ _this.pageEndHandler();
3131
+ _this.stopHeartBeatInterval();
3132
+ });
3133
+ }
3134
+ });
3135
+ };
3136
+ PageLeavePlugin.prototype.pageStartHandler = function () {
3137
+ this.startTime = nowStamp();
3138
+ this.pageShowStatus = !document.hidden;
3139
+ this.url = window.location.href;
3140
+ };
3141
+ PageLeavePlugin.prototype.pageEndHandler = function () {
3142
+ if (!this.pageShowStatus)
3143
+ return;
3144
+ this.pageShowStatus = false;
3145
+ if (this.isCollectUrl()) {
3146
+ var properties = this.getPageLeaveProperties();
3147
+ var data = this.context.getReportData('track', 'H_WebPageLeave', properties);
3148
+ this.context.report(data);
3149
+ }
3150
+ this.delHeartBeatData();
3151
+ };
3152
+ PageLeavePlugin.prototype.addHeartBeatInterval = function () {
3153
+ if (!this.context.store.localStorage)
3154
+ return;
3155
+ this.startHeartBeatInterval();
3156
+ };
3157
+ PageLeavePlugin.prototype.startHeartBeatInterval = function () {
3158
+ var _this = this;
3159
+ if (this.heartbeatIntervalTimer) {
3160
+ this.stopHeartBeatInterval();
3161
+ }
3162
+ if (this.isCollectUrl()) {
3163
+ this.heartbeatIntervalTimer = setInterval(function () {
3164
+ _this.saveHeartBeatData();
3165
+ }, this.heartbeatIntervalTime);
3166
+ this.saveHeartBeatData('first_heartbeat');
3167
+ }
3168
+ this.reissueHeartBeatData();
3169
+ };
3170
+ PageLeavePlugin.prototype.reissueHeartBeatData = function () {
3171
+ var localStorage = this.context.store.localStorage;
3172
+ var storageLen = localStorage.length();
3173
+ for (var i = 0; i < storageLen; i++) {
3174
+ var itemKey = localStorage.key(i);
3175
+ if (itemKey &&
3176
+ itemKey !== this.storageName + this.pageId &&
3177
+ itemKey.includes(this.storageName)) {
3178
+ var value = localStorage.get(itemKey);
3179
+ var result = safeJSONParse(value);
3180
+ if (isObject(result) &&
3181
+ nowStamp() - result.time > result.heartbeat_interval_time + 5000) {
3182
+ delete result.heartbeat_interval_time;
3183
+ this.context.report(result);
3184
+ }
3185
+ this.delHeartBeatData(itemKey);
3186
+ }
3187
+ }
3188
+ };
3189
+ PageLeavePlugin.prototype.stopHeartBeatInterval = function () {
3190
+ if (this.heartbeatIntervalTimer) {
3191
+ clearInterval(this.heartbeatIntervalTimer);
3192
+ this.heartbeatIntervalTimer = null;
3193
+ }
3194
+ };
3195
+ PageLeavePlugin.prototype.delHeartBeatData = function (storageKey) {
3196
+ if (this.context.store.localStorage) {
3197
+ this.context.store.localStorage.remove(storageKey || this.storageName + this.pageId);
3198
+ }
3199
+ };
3200
+ PageLeavePlugin.prototype.isCollectUrl = function () {
3201
+ var isCollectUrl = this.normalizePageLeaveAutoTrack().isCollectUrl;
3202
+ if (isFunction(isCollectUrl)) {
3203
+ return isCollectUrl(this.url);
3204
+ }
3205
+ return true;
3206
+ };
3207
+ PageLeavePlugin.prototype.saveHeartBeatData = function (type) {
3208
+ var properties = this.getPageLeaveProperties();
3209
+ properties.H_time = nowStamp();
3210
+ if (type === 'first_heartbeat') {
3211
+ properties.event_duration = 3;
3212
+ }
3213
+ var props = this.context.getReportData('track', 'H_WebPageLeave', properties);
3214
+ props.heartbeat_interval_time = this.heartbeatIntervalTime;
3215
+ this.context.store.localStorage.set(this.storageName + this.pageId, JSON.stringify(props));
3216
+ };
3217
+ PageLeavePlugin.prototype.getPageLeaveProperties = function () {
3218
+ var duration = (nowStamp() - this.startTime) / 1000;
3219
+ if (duration <= 0 || duration > this.maxDuration) {
3220
+ duration = 0;
3221
+ }
3222
+ else {
3223
+ duration = formatDecimal(duration, 3);
3224
+ }
3225
+ var _a = getURL(this.url), pathname = _a.pathname, hash = _a.hash;
3226
+ var referrer = getReferrer(this.previousUrl);
3227
+ var properties = {
3228
+ H_url: this.url,
3229
+ H_url_path: pathname,
3230
+ H_url_hash: hash,
3231
+ H_referrer: referrer,
3232
+ H_referrer_host: referrer ? getHostname(referrer) : ''
3233
+ };
3234
+ if (duration) {
3235
+ properties.event_duration = duration;
3236
+ }
3237
+ var custom_props = this.normalizePageLeaveAutoTrack().custom_props;
3238
+ if (isObject(custom_props)) {
3239
+ properties = __assign(__assign({}, properties), (custom_props || {}));
3240
+ }
3241
+ return properties;
3242
+ };
3243
+ return PageLeavePlugin;
3244
+ }(PluginBase));
3245
+
3246
+ var SiteLinkerPluginName = 'SiteLinkerPlugin';
3247
+ var SiteLinkerPlugin = /** @class */ (function (_super) {
3248
+ __extends(SiteLinkerPlugin, _super);
3249
+ function SiteLinkerPlugin(options, context) {
3250
+ var _this = _super.call(this, options, context) || this;
3251
+ _this.options = options;
3252
+ _this.context = context;
3253
+ _this.name = SiteLinkerPluginName;
3254
+ _this.linker = [];
3255
+ return _this;
3256
+ }
3257
+ SiteLinkerPlugin.prototype.init = function () {
3258
+ var linker = this.getLinkerConfig().linker;
3259
+ if (!(isArray(linker) && linker.length > 0)) {
3260
+ this.context.log('siteLinker plugin: Please configure the linker parameter', ConsoleTypes.WARN);
3261
+ return;
3262
+ }
3263
+ // 处理配置
3264
+ this.resolveOption();
3265
+ this.setRefferId();
3266
+ this.addClickListen();
3267
+ };
3268
+ SiteLinkerPlugin.prototype.transform = function () {
3269
+ return undefined;
3270
+ };
3271
+ SiteLinkerPlugin.prototype.getLinkerConfig = function () {
3272
+ var _a = this.options.siteLinkerConfig || {}, _b = _a.linker, linker = _b === void 0 ? [] : _b, re_login = _a.re_login;
3273
+ return {
3274
+ linker: linker || [],
3275
+ re_login: re_login
3276
+ };
3277
+ };
3278
+ SiteLinkerPlugin.prototype.resolveOption = function () {
3279
+ var linker = this.getLinkerConfig().linker;
3280
+ var len = linker.length;
3281
+ var arr = [];
3282
+ for (var i = 0; i < len; i++) {
3283
+ var _a = linker[i], part_url = _a.part_url, after_hash = _a.after_hash;
3284
+ if (/[A-Za-z0-9]+\./.test(part_url) && isBoolean(after_hash)) {
3285
+ arr.push({
3286
+ part_url: part_url,
3287
+ after_hash: after_hash
3288
+ });
3289
+ }
3290
+ else {
3291
+ this.context.log("The configuration of linker ".concat(i + 1, " is not supported.Please check format"), ConsoleTypes.WARN);
3292
+ }
3293
+ }
3294
+ this.linker = arr;
3295
+ };
3296
+ /**
3297
+ * 多域名打通设置
3298
+ */
3299
+ SiteLinkerPlugin.prototype.setRefferId = function () {
3300
+ var re_login = this.getLinkerConfig().re_login;
3301
+ var urlId = this.getUrlId();
3302
+ var isAnonymousId = urlId.startsWith('a');
3303
+ urlId = urlId.substring(1);
3304
+ if (urlId === '')
3305
+ return;
3306
+ var anonymousId = this.context.store.getAnonymousId();
3307
+ var accountId = this.context.store.getAccountId();
3308
+ if (isAnonymousId) {
3309
+ if (urlId !== anonymousId) {
3310
+ this.context.store.state.anonymousId = urlId;
3311
+ this.context.store.save();
3312
+ }
3313
+ if (accountId) {
3314
+ var props = this.context.getReportData('track_signup', 'H_SignUp', {});
3315
+ this.context.report(props);
3316
+ }
3317
+ }
3318
+ else if (!accountId || (re_login && accountId !== urlId)) {
3319
+ this.context.setUserUId(urlId);
3320
+ }
3321
+ };
3322
+ /**
3323
+ * 获取链接上的id
3324
+ */
3325
+ SiteLinkerPlugin.prototype.getUrlId = function () {
3326
+ /**
3327
+ * 匿名ID:a 登录ID:u
3328
+ * 如果是匿名ID:返回的是a+匿名ID 如果是登录ID:返回的是u+登录ID
3329
+ */
3330
+ var hnId = window.location.href.match(/_hnsdk=([au][^\?\#\&\=]+)/);
3331
+ if (isArray(hnId) && hnId[1]) {
3332
+ return handleDecodeURLComponent(hnId[1]);
3333
+ }
3334
+ return '';
3335
+ };
3336
+ /**
3337
+ * 判断url链接是否包含part_url
3338
+ * @param url
3339
+ */
3340
+ SiteLinkerPlugin.prototype.getPartUrl = function (url) {
3341
+ var len = this.linker.length;
3342
+ for (var i = 0; i < len; i++) {
3343
+ if (url.includes(this.linker[i].part_url)) {
3344
+ return true;
3345
+ }
3346
+ }
3347
+ return false;
3348
+ };
3349
+ /**
3350
+ * 获取url链接对应的linker配置中after_hash的值
3351
+ * @param url
3352
+ */
3353
+ SiteLinkerPlugin.prototype.getPartHash = function (url) {
3354
+ var len = this.linker.length;
3355
+ for (var i = 0; i < len; i++) {
3356
+ if (url.includes(this.linker[i].part_url)) {
3357
+ return this.linker[i].after_hash;
3358
+ }
3359
+ }
3360
+ return false;
3361
+ };
3362
+ /**
3363
+ * 获取当前的匿名ID和当前的登录ID
3364
+ */
3365
+ SiteLinkerPlugin.prototype.getCurrentId = function () {
3366
+ var accountId = this.context.store.getAccountId();
3367
+ var anonymousId = this.context.store.getAnonymousId();
3368
+ var hnId = accountId ? "u".concat(accountId) : "a".concat(anonymousId);
3369
+ return handleEncodeURLComponent(hnId);
3370
+ };
3371
+ /**
3372
+ * 重写a 标签的href链接
3373
+ * @param url
3374
+ * @param dom
3375
+ */
3376
+ SiteLinkerPlugin.prototype.rewriteUrl = function (url, dom) {
3377
+ /**
3378
+ * ([^?#]+):匹配直到遇到 ? 或 # 之前的任何字符,并将这部分捕获为第一组。
3379
+ * (\?[^#]*)?:可选地匹配 ? 后面直到遇到 # 之前的任何字符,并将这部分捕获为第二组。
3380
+ * (#.*)?:可选地匹配 # 后面的任何字符,并将这部分捕获为第三组。
3381
+ */
3382
+ var reg = /([^?#]+)(\?[^#]*)?(#.*)?/;
3383
+ var arr = reg.exec(url);
3384
+ var normalizeUrl = '';
3385
+ if (!arr)
3386
+ return;
3387
+ var host = arr[1] || ''; // 'http://www.xx.com'
3388
+ var search = arr[2] || ''; // '?xxx=xxx'
3389
+ var hash = arr[3] || ''; // '#xxx=xxx'
3390
+ var hnId = "_hnsdk=".concat(this.getCurrentId());
3391
+ var changeHnId = function (str) {
3392
+ var list = str.split('&');
3393
+ var result = [];
3394
+ list.forEach(function (value) {
3395
+ if (value.includes('_hnsdk')) {
3396
+ result.push(hnId);
3397
+ }
3398
+ else {
3399
+ result.push(value);
3400
+ }
3401
+ });
3402
+ return result.join('&');
3403
+ };
3404
+ if (this.getPartHash(url)) {
3405
+ var hasQuery = hash.includes('?'); // 判断是#xxx?xxx=xxx的格式
3406
+ var index = hash.indexOf('_hnsdk');
3407
+ if (hasQuery) {
3408
+ if (index >= 0) {
3409
+ normalizeUrl = "".concat(host).concat(search, "#").concat(hash.substring(1, index)).concat(changeHnId(hash.substring(index, hash.length)));
3410
+ }
3411
+ else {
3412
+ normalizeUrl = "".concat(host).concat(search, "#").concat(hash.substring(1), "&").concat(hnId);
3413
+ }
3414
+ }
3415
+ else {
3416
+ normalizeUrl = "".concat(host).concat(search, "#").concat(hash.substring(1), "?").concat(hnId);
3417
+ }
3418
+ }
3419
+ else {
3420
+ var hasQuery = /^\?(\w)+/.test(search); // 判断是否有?xxx=xxx的格式
3421
+ if (hasQuery) {
3422
+ if (search.includes('_hnsdk')) {
3423
+ normalizeUrl = "".concat(host, "?").concat(changeHnId(search.substring(1))).concat(hash);
3424
+ }
3425
+ else {
3426
+ normalizeUrl = "".concat(host).concat(search, "&").concat(hnId).concat(hash);
3427
+ }
3428
+ }
3429
+ else {
3430
+ normalizeUrl = "".concat(host, "?").concat(hnId).concat(hash);
3431
+ }
3432
+ }
3433
+ if (dom) {
3434
+ dom.href = normalizeUrl;
3435
+ }
3436
+ return normalizeUrl;
3437
+ };
3438
+ SiteLinkerPlugin.prototype.addClickListen = function () {
3439
+ var _this = this;
3440
+ var handleClick = function (event) {
3441
+ var _a, _b;
3442
+ var target = event.target;
3443
+ if (!target)
3444
+ return;
3445
+ var tagName = (_a = target.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
3446
+ var parentNode = target.parentNode;
3447
+ var parentTagName = (_b = parentNode === null || parentNode === void 0 ? void 0 : parentNode.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase();
3448
+ if ((tagName === 'a' && target.href) ||
3449
+ (parentTagName === 'a' && parentNode.href)) {
3450
+ var sdkUrl = void 0;
3451
+ var sdkTarget = void 0;
3452
+ if (tagName === 'a' && target.href) {
3453
+ sdkUrl = target.href;
3454
+ sdkTarget = target;
3455
+ }
3456
+ else {
3457
+ sdkUrl = parentNode.href;
3458
+ sdkTarget = parentNode;
3459
+ }
3460
+ var protocol = getURL(sdkUrl).protocol;
3461
+ if (protocol === 'http:' || protocol === 'https:') {
3462
+ if (_this.getPartUrl(sdkUrl)) {
3463
+ _this.rewriteUrl(sdkUrl, sdkTarget);
3464
+ }
3465
+ }
3466
+ }
3467
+ };
3468
+ if ('PointerEvent' in window) {
3469
+ document.addEventListener('pointerdown', handleClick);
3470
+ }
3471
+ else {
3472
+ document.addEventListener('mousedown', handleClick);
3473
+ }
3474
+ };
3475
+ return SiteLinkerPlugin;
3476
+ }(PluginBase));
3477
+
3478
+ var HistoryPlugin = /** @class */ (function (_super) {
3479
+ __extends(HistoryPlugin, _super);
3480
+ function HistoryPlugin(options, context) {
3481
+ var _this = _super.call(this, options, context) || this;
3482
+ _this.options = options;
3483
+ _this.context = context;
3484
+ _this.name = 'HistoryPlugin';
3485
+ /**
3486
+ * 上一次页面url
3487
+ */
3488
+ _this.lastHref = window.location.href;
3489
+ /**
3490
+ * 上一次路由path
3491
+ */
3492
+ _this.lastPath = window.location.pathname;
3493
+ return _this;
3494
+ }
3495
+ HistoryPlugin.prototype.init = function (notify) {
3496
+ if (!supportHistory())
3497
+ return;
3498
+ var _a = this.options, isSinglePage = _a.isSinglePage, pageviewAutoTrack = _a.autoTrackConfig.pageviewAutoTrack;
3499
+ var self = this;
3500
+ var originalOnpopstate = window.onpopstate;
3501
+ var handleRouterChange = function (currentPath, currentHref) {
3502
+ var params = {
3503
+ fromPath: self.lastPath,
3504
+ fromHref: self.lastHref,
3505
+ toPath: currentPath,
3506
+ toHref: currentHref
3507
+ };
3508
+ self.lastPath = currentPath;
3509
+ self.lastHref = currentHref;
3510
+ mitt.emit('urlChange', __assign(__assign({}, params), { mode: 'history' }));
3511
+ if (isSinglePage || pageviewAutoTrack === 'singlePage') {
3512
+ if (isFunction(isSinglePage)) {
3513
+ var extra = isSinglePage();
3514
+ if (isObject(extra)) {
3515
+ params = __assign(__assign({}, params), extra);
3516
+ }
3517
+ }
3518
+ notify(__assign(__assign({}, params), { H_referrer: self.lastHref }));
3519
+ }
3520
+ };
3521
+ window.onpopstate = function () {
3522
+ var args = [];
3523
+ for (var _i = 0; _i < arguments.length; _i++) {
3524
+ args[_i] = arguments[_i];
3525
+ }
3526
+ var currentPath = window.location.pathname;
3527
+ var currentHref = window.location.href;
3528
+ handleRouterChange(currentPath, currentHref);
3529
+ originalOnpopstate && originalOnpopstate.apply(this, args);
3530
+ };
3531
+ function historyReplaceFn(originalHistoryFn) {
3532
+ return function () {
3533
+ var args = [];
3534
+ for (var _i = 0; _i < arguments.length; _i++) {
3535
+ args[_i] = arguments[_i];
3536
+ }
3537
+ var currentPath = args[2];
3538
+ originalHistoryFn.apply(this, args);
3539
+ var currentHref = window.location.href;
3540
+ handleRouterChange(currentPath, currentHref);
3541
+ };
3542
+ }
3543
+ replaceOld(window.history, 'pushState', historyReplaceFn);
3544
+ replaceOld(window.history, 'replaceState', historyReplaceFn);
3545
+ };
3546
+ HistoryPlugin.prototype.transform = function (data) {
3547
+ this.context.autoTrack(data);
3548
+ return undefined;
3549
+ };
3550
+ return HistoryPlugin;
3551
+ }(PluginBase));
3552
+
3553
+ var HashPlugin = /** @class */ (function (_super) {
3554
+ __extends(HashPlugin, _super);
3555
+ function HashPlugin(options, context) {
3556
+ var _this = _super.call(this, options, context) || this;
3557
+ _this.options = options;
3558
+ _this.context = context;
3559
+ _this.name = 'HashPlugin';
3560
+ /**
3561
+ * 上一次页面url
3562
+ */
3563
+ _this.lastHref = window.location.href;
3564
+ /**
3565
+ * 上一次路由path
3566
+ */
3567
+ _this.lastPath = window.location.hash;
3568
+ return _this;
3569
+ }
3570
+ HashPlugin.prototype.init = function (notify) {
3571
+ var _this = this;
3572
+ var _a = this.options, isSinglePage = _a.isSinglePage, pageviewAutoTrack = _a.autoTrackConfig.pageviewAutoTrack;
3573
+ window.addEventListener('hashchange', function (event) {
3574
+ var newURL = event.newURL;
3575
+ var currentPath = getURL(newURL).hash;
3576
+ var params = {
3577
+ fromPath: _this.lastPath,
3578
+ fromHref: _this.lastHref,
3579
+ toPath: currentPath,
3580
+ toHref: newURL
3581
+ };
3582
+ mitt.emit('urlChange', __assign(__assign({}, params), { mode: 'history' }));
3583
+ _this.lastHref = newURL;
3584
+ _this.lastPath = currentPath;
3585
+ if (isSinglePage || pageviewAutoTrack === 'singlePage') {
3586
+ if (isFunction(isSinglePage)) {
3587
+ var extra = isSinglePage();
3588
+ if (isObject(extra)) {
3589
+ params = __assign(__assign({}, params), extra);
3590
+ }
3591
+ }
3592
+ notify(__assign(__assign({}, params), { H_referrer: _this.lastHref }));
3593
+ }
3594
+ });
3595
+ };
3596
+ HashPlugin.prototype.transform = function (data) {
3597
+ this.context.autoTrack(data);
3598
+ return undefined;
3599
+ };
3600
+ return HashPlugin;
3601
+ }(PluginBase));
3602
+
3603
+ var HinaTrack = /** @class */ (function (_super) {
3604
+ __extends(HinaTrack, _super);
3605
+ function HinaTrack(options, useInstancing) {
3606
+ if (useInstancing === void 0) { useInstancing = true; }
3607
+ var _this = _super.call(this, options, useInstancing) || this;
3608
+ /**
3609
+ * 上报数据的dom元素 默认有 'a', 'input', 'button', 'textarea'
3610
+ */
3611
+ _this.trackTags = defaultTags;
3612
+ /**
3613
+ * 事件静态公共属性
3614
+ */
3615
+ _this.presetProps = {};
3616
+ /**
3617
+ * 插件列表
3618
+ */
3619
+ _this.plugins = [];
3620
+ _this.consolePrefix = '埋点SDK';
3621
+ // 使用new的方式初始化SDK,需要默认调用init方法进行初始化
3622
+ if (_this.useInstancing) {
3623
+ _this.init(options);
3624
+ }
3625
+ return _this;
3626
+ }
3627
+ /**
3628
+ * 注册/初始化SDK
3629
+ * @param options
3630
+ */
3631
+ HinaTrack.prototype.init = function (options) {
3632
+ if (this.isReady) {
3633
+ this.log('hinaSDK has been initialized', ConsoleTypes.ERROR);
3634
+ return;
3635
+ }
3636
+ // 默认配置项
3637
+ var default_config = GET_DEFAULT_OPTIONS();
3638
+ // 将用户配置项和默认配置项合并
3639
+ this.options = merge(default_config, options);
3640
+ // 处理配置信息
3641
+ this.normalizeConfig();
3642
+ // 初始化state
3643
+ this.initState();
3644
+ // 处理广告参数
3645
+ this.initAdvProps();
3646
+ // 插件初始化
3647
+ this.initPlugins();
3648
+ // SDK初始化成功,一切准备就绪
3649
+ this.isReady = true;
3650
+ this.log('hinaSDK initialized successfully');
3651
+ };
3652
+ /**
3653
+ * 处理配置信息
3654
+ */
3655
+ HinaTrack.prototype.normalizeConfig = function () {
3656
+ var _a = this.options, serverUrl = _a.serverUrl, sendType = _a.sendType, batchSend = _a.batchSend, _b = _a.autoTrackConfig, _c = _b === void 0 ? {} : _b, _d = _c.trackAttr, trackAttr = _d === void 0 ? [] : _d, collectTags = _c.collectTags, pageLeaveAutoTrack = _c.pageLeaveAutoTrack, pageviewAutoTrack = _c.pageviewAutoTrack;
3657
+ serverUrl = serverUrl || '';
3658
+ serverUrl = serverUrl.trim();
3659
+ if (serverUrl === '') {
3660
+ this.log('当前 serverUrl 为空或不正确,network 中不会发数据,请配置正确的 serverUrl!', ConsoleTypes.WARN);
3661
+ }
3662
+ else {
3663
+ var href = window.location.href;
3664
+ var currentProtocol = getURL(href).protocol || '';
3665
+ var serverProtocol = getURL(serverUrl).protocol || '';
3666
+ if (serverProtocol !== currentProtocol) {
3667
+ this.log('SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。因为:https 下面发送 http 的图片请求会失败。', ConsoleTypes.WARN);
3668
+ }
3669
+ }
3670
+ if (![ReportType.IMAGE, ReportType.AJAX, ReportType.BEACON].includes(sendType)) {
3671
+ this.setConfig({
3672
+ sendType: ReportType.IMAGE
3673
+ });
3674
+ }
3675
+ // 处理pageLeaveAutoTrack
3676
+ if (pageLeaveAutoTrack === true) {
3677
+ this.options.autoTrackConfig.pageLeaveAutoTrack = {
3678
+ heartbeat_interval_time: 5000,
3679
+ max_duration: 432000
3680
+ };
3681
+ }
3682
+ // 处理trackAttr
3683
+ if (isArray(trackAttr)) {
3684
+ trackAttr = trackAttr.filter(function (v) { return isString(v); });
3685
+ if (!trackAttr.includes('hn-click'))
3686
+ trackAttr.push('hn-click');
3687
+ }
3688
+ else {
3689
+ trackAttr = ['hn-click'];
3690
+ }
3691
+ this.options.autoTrackConfig.trackAttr = trackAttr;
3692
+ // 处理collectTags
3693
+ if (isObject(collectTags)) {
3694
+ if (collectTags.div === true) {
3695
+ this.options.autoTrackConfig.collectTags.div = {
3696
+ ignoreTags: ignoreTags,
3697
+ maxLevel: 1
3698
+ };
3699
+ }
3700
+ else if (isObject(collectTags.div)) {
3701
+ var maxLevel = 1;
3702
+ var oDiv = collectTags.div;
3703
+ if (isNumber(oDiv.maxLevel) && [1, 2, 3].includes(oDiv.maxLevel)) {
3704
+ maxLevel = oDiv.maxLevel;
3705
+ }
3706
+ this.options.autoTrackConfig.collectTags.div = {
3707
+ ignoreTags: ignoreTags,
3708
+ maxLevel: maxLevel
3709
+ };
3710
+ }
3711
+ else {
3712
+ this.options.autoTrackConfig.collectTags.div = false;
3713
+ }
3714
+ }
3715
+ else {
3716
+ this.options.autoTrackConfig.collectTags = {
3717
+ div: false
3718
+ };
3719
+ }
3720
+ this.updateTrackTags();
3721
+ // 处理批量发送
3722
+ if (batchSend === true || isObject(batchSend)) {
3723
+ this.options.batchSend = __assign({ dataSendTimeout: 6000, sendInterval: 6000, storageLimit: 200 }, batchSend);
3724
+ this.batchSender = new BatchSend(this);
3725
+ }
3726
+ // 处理pageviewAutoTrack
3727
+ if (pageviewAutoTrack === 'auto') {
3728
+ this.autoTrack();
3729
+ }
3730
+ };
3731
+ /**
3732
+ * 初始化广告参数
3733
+ */
3734
+ HinaTrack.prototype.initAdvProps = function () {
3735
+ var advProps = {};
3736
+ var presetProperties = this.options.presetProperties || {};
3737
+ Object.keys(presetProperties).forEach(function (key) {
3738
+ var value = presetProperties[key];
3739
+ if (key.includes('latest_')) {
3740
+ key = key.slice(7);
3741
+ if (value) {
3742
+ var url_domain = getCurrentDomain();
3743
+ if (key !== 'utm' && url_domain === 'url解析失败') {
3744
+ advProps["H_latest_".concat(key)] = 'url的domain解析失败';
3745
+ }
3746
+ else if (isReferralTraffic()) {
3747
+ switch (key) {
3748
+ case 'traffic_source_type':
3749
+ advProps.H_latest_traffic_source_type =
3750
+ SearchKeyword.getSourceFromReferrer();
3751
+ break;
3752
+ case 'search_keyword':
3753
+ var searchKeyword = SearchKeyword.getKeywordFromReferrer();
3754
+ if (searchKeyword) {
3755
+ advProps.H_latest_search_keyword = searchKeyword;
3756
+ }
3757
+ break;
3758
+ case 'referrer': // todo 这块似乎没有什么用
3759
+ advProps.H_latest_referrer = '';
3760
+ break;
3761
+ }
3762
+ }
3763
+ }
3764
+ }
3765
+ });
3766
+ this.store.state.props = advProps;
3767
+ if (presetProperties.latest_utm) {
3768
+ this.getUmtsParams('H_latest_');
3769
+ }
3770
+ this.getUmtsParams('H_');
3771
+ this.store.setProps(this.store.state.props);
3772
+ };
3773
+ /**
3774
+ * 处理广告参数
3775
+ * @param prefix
3776
+ */
3777
+ HinaTrack.prototype.getUmtsParams = function (prefix) {
3778
+ if (prefix === void 0) { prefix = ''; }
3779
+ var allUtms = getUmtsParams(prefix);
3780
+ if (this.store.state.props && this.store.state.props.H_latest_utm_source) {
3781
+ this.store.state.props = __assign(__assign({}, this.store.state.props), allUtms);
3782
+ }
3783
+ return allUtms;
3784
+ };
3785
+ /**
3786
+ * 初始化共享数据
3787
+ */
3788
+ HinaTrack.prototype.initState = function () {
3789
+ this.store = new State(this.options);
3790
+ this.store.init();
3791
+ };
3792
+ /**
3793
+ * 更新采集的dom元素
3794
+ */
3795
+ HinaTrack.prototype.updateTrackTags = function () {
3796
+ var collectTags = this.options.autoTrackConfig.collectTags;
3797
+ var tags = __spreadArray([], __read(defaultTags), false);
3798
+ Object.keys(collectTags || {}).forEach(function (key) {
3799
+ var value = collectTags[key];
3800
+ if ((value === true || isObject(value)) && !tags.includes(key)) {
3801
+ tags.push(key);
3802
+ }
3803
+ });
3804
+ this.trackTags = tags;
3805
+ };
3806
+ /**
3807
+ * 应用插件
3808
+ */
3809
+ HinaTrack.prototype.initPlugins = function () {
3810
+ var _this = this;
3811
+ var _a = this.options.plugins, plugins = _a === void 0 ? [] : _a;
3812
+ plugins = plugins || [];
3813
+ var clickCrackPlugin = new ClickTrackPlugin(this.options, this);
3814
+ var stayTrackPlugin = new StayTrackPlugin(this.options, this);
3815
+ var pageLeavePlugin = new PageLeavePlugin(this.options, this);
3816
+ var siteLinkerPlugin = new SiteLinkerPlugin(this.options, this);
3817
+ var historyPlugin = new HistoryPlugin(this.options, this);
3818
+ var hashPlugin = new HashPlugin(this.options, this);
3819
+ this.plugins = [
3820
+ clickCrackPlugin,
3821
+ stayTrackPlugin,
3822
+ pageLeavePlugin,
3823
+ siteLinkerPlugin,
3824
+ historyPlugin,
3825
+ hashPlugin
3826
+ ];
3827
+ plugins.forEach(function (Plugin) {
3828
+ var instance = new Plugin(_this.options, _this);
3829
+ _this.plugins.push(instance);
3830
+ });
3831
+ this.runPlugins(this.plugins);
3832
+ };
3833
+ /**
3834
+ * @deprecated
3835
+ * 启动内置插件,v4版本后不建议使用该方法启动插件
3836
+ * 建议通过配置项的方式启动内置插件
3837
+ */
3838
+ HinaTrack.prototype.use = function (pluginName, options) {
3839
+ var _this = this;
3840
+ var _a = this.options, autoTrackConfig = _a.autoTrackConfig, siteLinkerConfig = _a.siteLinkerConfig;
3841
+ var pageLeaveAutoTrack = autoTrackConfig.pageLeaveAutoTrack;
3842
+ var startPlugin = function (pluginName) {
3843
+ var pluginInstance = _this.plugins.find(function (plugin) { return plugin.name === pluginName; });
3844
+ if (pluginInstance)
3845
+ pluginInstance.init();
3846
+ };
3847
+ if (!isObject(options)) {
3848
+ this.log("".concat(pluginName, "\u63D2\u4EF6\u914D\u7F6E\u9879\u5FC5\u987B\u662F\u4E00\u4E2A\u5BF9\u8C61\u7C7B\u578B"), ConsoleTypes.WARN);
3849
+ return;
3850
+ }
3851
+ if (pluginName === 'PageLeave') {
3852
+ if (isObject(pageLeaveAutoTrack)) {
3853
+ this.log('PageLeave插件已通过pageLeaveAutoTrack的配置参数启动,不可重复启动,如果想通过use方式启动,请删除配置项中的pageLeaveAutoTrack', ConsoleTypes.WARN);
3854
+ }
3855
+ else {
3856
+ this.options.autoTrackConfig.pageLeaveAutoTrack =
3857
+ options;
3858
+ startPlugin(PageLeavePluginName);
3859
+ }
3860
+ }
3861
+ else if (pluginName === 'SiteLinker') {
3862
+ if (isObject(siteLinkerConfig)) {
3863
+ this.log('SiteLinker插件已通过siteLinkerConfig的配置参数启动,不可重复启动,如果想通过use方式启动,请删除配置项中的siteLinkerConfig', ConsoleTypes.WARN);
3864
+ }
3865
+ else {
3866
+ this.options.siteLinkerConfig = options;
3867
+ startPlugin(SiteLinkerPluginName);
3868
+ }
3869
+ }
3870
+ };
3871
+ /**
3872
+ * 设置配置选项
3873
+ * @param options 配置对象
3874
+ */
3875
+ HinaTrack.prototype.setConfig = function (options) {
3876
+ this.options = merge(this.options, options);
3877
+ this.normalizeConfig();
3878
+ };
3879
+ /**
3880
+ * 获取配置选项 参数为空时 返回整个配置对象
3881
+ * @param key
3882
+ */
3883
+ HinaTrack.prototype.getConfig = function (key) {
3884
+ if (!key) {
3885
+ return this.options;
3886
+ }
3887
+ return this.options[key];
3888
+ };
3889
+ /**
3890
+ * 上报数据
3891
+ * @param data
3892
+ * @param callback
3893
+ * @param type
3894
+ */
3895
+ HinaTrack.prototype.report = function (data, callback, type) {
3896
+ console.log('report', data);
3897
+ var _a = this.options, batchSend = _a.batchSend, globalCallback = _a.globalCallback, serverUrl = _a.serverUrl, dataSendTimeout = _a.dataSendTimeout, sendType = _a.sendType, imgUseCrossOrigin = _a.imgUseCrossOrigin;
3898
+ sendType = type || sendType;
3899
+ // 批量发送
3900
+ if (batchSend) {
3901
+ this.batchSender.add(data);
3902
+ }
3903
+ else {
3904
+ var dataStr_1 = data;
3905
+ if (!isString(data)) {
3906
+ dataStr_1 = JSON.stringify(data);
3907
+ }
3908
+ var base64Data = base64Encode(dataStr_1);
3909
+ var params = {
3910
+ data: "data=".concat(base64Data),
3911
+ url: serverUrl,
3912
+ timeout: dataSendTimeout,
3913
+ imgUseCrossOrigin: imgUseCrossOrigin
3914
+ };
3915
+ var request = void 0;
3916
+ if (sendType === ReportType.BEACON && navigator.sendBeacon) {
3917
+ request = new BeaconRequest(params);
3918
+ }
3919
+ else if (sendType === ReportType.IMAGE && params.data.length < 2048) {
3920
+ request = new ImageRequest(params);
3921
+ }
3922
+ else {
3923
+ request = new AjaxRequest(params);
3924
+ }
3925
+ return request.run().then(function (res) {
3926
+ if (isFunction(globalCallback)) {
3927
+ globalCallback(serverUrl, dataStr_1, res.type, res.msg);
3928
+ }
3929
+ if (isFunction(callback)) {
3930
+ callback(serverUrl, dataStr_1, res.type, res.msg);
3931
+ }
3932
+ return res;
3933
+ });
3934
+ }
3935
+ };
3936
+ /**
3937
+ * 设置用户登录的唯一标识
3938
+ * @param uid
3939
+ * @param callback
3940
+ */
3941
+ HinaTrack.prototype.setUserUId = function (uid, callback) {
3942
+ uid = uid !== null && uid !== void 0 ? uid : '';
3943
+ if (isNumber(uid) || isString(uid)) {
3944
+ uid = String(uid).trim();
3945
+ if (!uid) {
3946
+ this.log('setUserUId: uid is empty', ConsoleTypes.WARN);
3947
+ }
3948
+ var accountId = this.store.getAccountId();
3949
+ if (accountId !== uid) {
3950
+ this.store.setAccountId(uid);
3951
+ var props = this.getReportData('track_signup', 'H_SignUp', {});
3952
+ this.report(props, callback);
3953
+ }
3954
+ else {
3955
+ this.log('setUserUId: uid is equal to account_id, , failed to execute setUserUId', ConsoleTypes.WARN);
3956
+ }
3957
+ }
3958
+ else {
3959
+ this.log('setUserUId: uid must be string or number', ConsoleTypes.WARN);
3960
+ }
3961
+ };
3962
+ /**
3963
+ * 设置设备ID
3964
+ * @param uid
3965
+ */
3966
+ HinaTrack.prototype.setDeviceUId = function (uid) {
3967
+ this.store.setDeviceId(uid);
3968
+ };
3969
+ /**
3970
+ * 获取设备ID
3971
+ */
3972
+ HinaTrack.prototype.getDeviceUId = function () {
3973
+ return this.store.getDeviceId();
3974
+ };
3975
+ /**
3976
+ * 自定义埋点事件
3977
+ * @param event
3978
+ * @param properties
3979
+ * @param callback
3980
+ */
3981
+ HinaTrack.prototype.track = function (event, properties, callback) {
3982
+ callback = callback || (function () { });
3983
+ if (isString(event)) {
3984
+ properties = isObject(properties) ? properties : {};
3985
+ var props = this.getReportData('track', event, properties);
3986
+ this.report(props, callback);
3987
+ }
3988
+ else {
3989
+ this.log('eventName must be a sting and properties must be an object', ConsoleTypes.WARN);
3990
+ }
3991
+ };
3992
+ /**
3993
+ * @param name
3994
+ * @param data
3995
+ * @param callback
3996
+ */
3997
+ HinaTrack.prototype.quick = function (name, data, callback) {
3998
+ var params = {};
3999
+ callback = callback || (function () { });
4000
+ if (isObject(data)) {
4001
+ params = data;
4002
+ }
4003
+ else if (isFunction(data)) {
4004
+ callback = data;
4005
+ }
4006
+ this.autoTrack(params, callback);
4007
+ };
4008
+ /**
4009
+ * 开启页面浏览采集
4010
+ * @param data
4011
+ * @param callback
4012
+ */
4013
+ HinaTrack.prototype.autoTrack = function (data, callback) {
4014
+ if (data === void 0) { data = {}; }
4015
+ if (callback === void 0) { callback = noop; }
4016
+ var props = this.getReportData('track', 'H_pageview', data);
4017
+ this.report(props, callback);
4018
+ if (this.store.isSetFirstVisit) {
4019
+ this.store.isSetFirstVisit = false;
4020
+ var referrer = getReferrer();
4021
+ this.userSetOnce({
4022
+ H_first_visit_time: nowStamp(),
4023
+ H_first_referrer: referrer,
4024
+ H_first_host: referrer ? getHostname(referrer, '取值异常') : '',
4025
+ H_first_browser_language: isString(navigator.language)
4026
+ ? navigator.language.toLowerCase()
4027
+ : '取值异常',
4028
+ H_first_traffic_source_type: SearchKeyword.getSourceFromReferrer(),
4029
+ H_first_search_keyword: SearchKeyword.getKeywordFromReferrer()
4030
+ });
4031
+ }
4032
+ };
4033
+ /**
4034
+ * 添加用户属性
4035
+ * 直接设置用户的属性,如果存在则覆盖。
4036
+ * @param data
4037
+ * @param callback
4038
+ */
4039
+ HinaTrack.prototype.userSet = function (data, callback) {
4040
+ if (isObject(data) && !isEmptyObject(data)) {
4041
+ var props = this.getReportData('user_set', '', data);
4042
+ this.report(props, callback);
4043
+ }
4044
+ };
4045
+ /**
4046
+ * 添加用户属性
4047
+ * 如果不存在则设置,存在就不设置
4048
+ * @param data
4049
+ * @param callback
4050
+ */
4051
+ HinaTrack.prototype.userSetOnce = function (data, callback) {
4052
+ if (isObject(data) && !isEmptyObject(data)) {
4053
+ var props = this.getReportData('user_setOnce', '', data);
4054
+ this.report(props, callback);
4055
+ }
4056
+ };
4057
+ /**
4058
+ * 对当前用户的属性做递增或者递减
4059
+ * @param data
4060
+ * @param callback
4061
+ */
4062
+ HinaTrack.prototype.userAdd = function (data, callback) {
4063
+ var _a;
4064
+ var _this = this;
4065
+ if (isString(data)) {
4066
+ data = (_a = {},
4067
+ _a[data] = 1,
4068
+ _a);
4069
+ }
4070
+ var isValid = function (params) {
4071
+ for (var key in params) {
4072
+ if (!/-*\d+/.test(String(params[key]))) {
4073
+ _this.log('userAdd: value is must be number', ConsoleTypes.WARN);
4074
+ return false;
4075
+ }
4076
+ }
4077
+ return true;
4078
+ };
4079
+ if (isObject(data) && !isEmptyObject(data) && isValid(data)) {
4080
+ var props = this.getReportData('user_add', '', data);
4081
+ this.report(props, callback);
4082
+ }
4083
+ };
4084
+ /**
4085
+ * 删除当前用户的一些属性
4086
+ * @param data
4087
+ * @param callback
4088
+ */
4089
+ HinaTrack.prototype.userUnset = function (data, callback) {
4090
+ var _this = this;
4091
+ var obj = {};
4092
+ if (isString(data)) {
4093
+ data = [data];
4094
+ }
4095
+ if (isArray(data)) {
4096
+ data.forEach(function (value) {
4097
+ if (isString(value)) {
4098
+ obj[value] = true;
4099
+ }
4100
+ else {
4101
+ _this.log("userUnset: value inside the array must be string and have already been filtered out:".concat(value), ConsoleTypes.WARN);
4102
+ }
4103
+ });
4104
+ if (!isEmptyObject(obj)) {
4105
+ var props = this.getReportData('user_unset', '', obj);
4106
+ this.report(props, callback);
4107
+ }
4108
+ }
4109
+ else {
4110
+ this.log('userUnset: param must be an array or string', ConsoleTypes.WARN);
4111
+ }
4112
+ };
4113
+ /**
4114
+ * 删除当前用户及他的所有属性。
4115
+ * @param callback
4116
+ */
4117
+ HinaTrack.prototype.userDelete = function (callback) {
4118
+ var props = this.getReportData('user_delete', '', {});
4119
+ this.report(props, callback);
4120
+ this.store.setAccountId('');
4121
+ };
4122
+ /**
4123
+ * 添加事件属性
4124
+ * 当使用函数类型作为属性值、函数返回值只能是string、bool、number、date、array类型
4125
+ * @param params
4126
+ */
4127
+ HinaTrack.prototype.registerCommonProperties = function (params) {
4128
+ this.presetProps = merge(this.presetProps, params);
4129
+ };
4130
+ /**
4131
+ * 获取预置属性
4132
+ * 此方法可获取,页面地址,页面标题,前向地址,SDK 类型及版本,屏幕宽高,最近一次的相关属性
4133
+ */
4134
+ HinaTrack.prototype.getPresetProperties = function () {
4135
+ return {
4136
+ H_is_first_day: this.store.isFirstDay,
4137
+ H_is_first_time: this.store.isFirstTime,
4138
+ device_id: this.store.getDeviceId(),
4139
+ anonymous_id: this.store.getAnonymousId(),
4140
+ account_id: this.store.getAccountId(),
4141
+ properties: __assign(__assign(__assign({}, this.presetProps), getPageProperties()), getBrowserInfo())
4142
+ };
4143
+ };
4144
+ /**
4145
+ * 清空预置属性
4146
+ * @param payload
4147
+ */
4148
+ HinaTrack.prototype.clearPageRegister = function (payload) {
4149
+ var _this = this;
4150
+ if (payload === void 0) { payload = true; }
4151
+ if (payload === true) {
4152
+ this.presetProps = {};
4153
+ }
4154
+ else if (isArray(payload)) {
4155
+ payload.forEach(function (key) {
4156
+ if (key in _this.presetProps)
4157
+ delete _this.presetProps[key];
4158
+ });
4159
+ }
4160
+ };
4161
+ /**
4162
+ * 检查发送数据
4163
+ * @param props
4164
+ */
4165
+ HinaTrack.prototype.checkReportProperties = function (props) {
4166
+ var _this = this;
4167
+ Object.keys(props).forEach(function (key) {
4168
+ var value = props[key];
4169
+ if (isString(value) && value.length > MAX_STRING_LENGTH) {
4170
+ _this.log("\u5C5E\u6027--".concat(key, " \u5185\u5BB9\u8FC7\u957F\uFF0C\u5DF2\u88AB\u5220\u9664"), ConsoleTypes.WARN);
4171
+ delete props[key];
4172
+ }
4173
+ else if (isObject(value)) {
4174
+ _this.checkReportProperties(value);
4175
+ }
4176
+ else if (isFunction(value)) {
4177
+ props[key] = value(props);
4178
+ if (isObject(props[key])) {
4179
+ _this.checkReportProperties(props[key]);
4180
+ }
4181
+ else if (isString(props[key]) &&
4182
+ props[key].length > MAX_STRING_LENGTH) {
4183
+ _this.log("\u5C5E\u6027--".concat(key, " \u5185\u5BB9\u8FC7\u957F\uFF0C\u5DF2\u88AB\u5220\u9664"), ConsoleTypes.WARN);
4184
+ delete props[key];
4185
+ }
4186
+ }
4187
+ });
4188
+ };
4189
+ /**
4190
+ * 获取上报数据
4191
+ * @param type
4192
+ * @param event
4193
+ * @param data
4194
+ */
4195
+ HinaTrack.prototype.getReportData = function (type, event, data) {
4196
+ var anonymous_id = this.store.getAnonymousId();
4197
+ var accountId = this.store.getAccountId();
4198
+ var time = nowStamp();
4199
+ var reportProperties = this.getReportProperties(type, event);
4200
+ var properties = __assign(__assign({}, reportProperties), (data || {}));
4201
+ this.checkReportProperties(properties);
4202
+ var props = {
4203
+ anonymous_id: anonymous_id,
4204
+ type: type,
4205
+ event: event,
4206
+ time: time,
4207
+ _track_id: Number(String(getRandom()).slice(2, 5) +
4208
+ String(getRandom()).slice(2, 4) +
4209
+ String(nowStamp()).slice(-4)),
4210
+ properties: properties
4211
+ };
4212
+ if (accountId) {
4213
+ props.account_id = accountId;
4214
+ }
4215
+ props.send_time = nowStamp();
4216
+ return props;
4217
+ };
4218
+ /**
4219
+ * 获取通用的上报数据
4220
+ * @param type 上报类型
4221
+ * @param event 事件名称
4222
+ */
4223
+ HinaTrack.prototype.getReportProperties = function (type, event) {
4224
+ if (type === void 0) { type = ''; }
4225
+ if (event === void 0) { event = ''; }
4226
+ // 这里对预置属性进行merge是为了防止影响this.presetProps的自身结构,深拷贝的操作
4227
+ var presetProps = merge(this.presetProps);
4228
+ var properties = __assign(__assign({ device_id: this.store.getDeviceId() }, this.store.state.props), presetProps);
4229
+ // user_set、user_setOnce、user_add、user_unset、user_delete
4230
+ if (!type || type.slice(0, 4) !== 'user') {
4231
+ properties = __assign(__assign(__assign({}, properties), getPageProperties()), getBrowserInfo());
4232
+ }
4233
+ if (type === 'track') {
4234
+ properties.H_is_first_day = this.store.isFirstDay;
4235
+ this.store.isFirstDay = false;
4236
+ if (event === 'H_pageview') {
4237
+ properties.H_is_first_time = this.store.isFirstTime;
4238
+ this.store.isFirstTime = false;
4239
+ }
4240
+ }
4241
+ return properties;
4242
+ };
4243
+ return HinaTrack;
4244
+ }(BaseCore));
4245
+
4246
+ function createInstance(options) {
4247
+ return new HinaTrack(options, false);
4248
+ }
4249
+ var hinaSdk = createInstance({});
4250
+
4251
+ exports.HinaTrack = HinaTrack;
4252
+ exports.default = hinaSdk;
4253
+
4254
+ Object.defineProperty(exports, '__esModule', { value: true });
4255
+
4256
+ return exports;
4257
+
4258
+ })({});
4259
+ //# sourceMappingURL=index.global.js.map