hina-cloud-js-sdk 3.1.8 → 4.0.0

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