@datarangers/sdk-javascript 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.min.js CHANGED
@@ -435,7 +435,10 @@ var cookie = createCommonjsModule(function (module, exports) {
435
435
  });
436
436
 
437
437
  // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
438
- var Memory$1 = /** @class */function () {
438
+ /**
439
+ * cacheStorage
440
+ */
441
+ var Memory = /** @class */function () {
439
442
  function Memory() {
440
443
  this.cache = {};
441
444
  }
@@ -448,36 +451,26 @@ var Memory$1 = /** @class */function () {
448
451
  Memory.prototype.removeItem = function (cacheKey) {
449
452
  this.cache[cacheKey] = undefined;
450
453
  };
451
- Memory.prototype.getCookie = function (name) {
452
- this.getItem(name);
453
- };
454
- Memory.prototype.setCookie = function (key, value) {
455
- this.setItem(key, value);
456
- };
457
454
  return Memory;
458
455
  }();
459
- function isSupportLS() {
460
- try {
461
- localStorage.setItem('_ranger-test-key', 'hi');
462
- localStorage.getItem('_ranger-test-key');
463
- localStorage.removeItem('_ranger-test-key');
464
- return true;
465
- } catch (e) {
466
- return false;
467
- }
468
- }
469
- function isSupportSession() {
470
- try {
471
- sessionStorage.setItem('_ranger-test-key', 'hi');
472
- sessionStorage.getItem('_ranger-test-key');
473
- sessionStorage.removeItem('_ranger-test-key');
474
- return true;
475
- } catch (e) {
476
- return false;
456
+ /**
457
+ * localStorage
458
+ */
459
+ var Local = /** @class */function () {
460
+ function Local() {
461
+ this.support = this.isSupportLS();
477
462
  }
478
- }
479
- var local = {
480
- getItem: function getItem(key) {
463
+ Local.prototype.isSupportLS = function () {
464
+ try {
465
+ localStorage.setItem('_applogtest-test-key', 'hi');
466
+ localStorage.getItem('_applogtest-test-key');
467
+ localStorage.removeItem('_applogtest-test-key');
468
+ return true;
469
+ } catch (e) {
470
+ return false;
471
+ }
472
+ };
473
+ Local.prototype.getItem = function (key) {
481
474
  try {
482
475
  var value = localStorage.getItem(key);
483
476
  var ret = value;
@@ -489,42 +482,38 @@ var local = {
489
482
  return ret || {};
490
483
  } catch (e) {}
491
484
  return {};
492
- },
493
- setItem: function setItem(key, value) {
485
+ };
486
+ Local.prototype.setItem = function (key, value) {
494
487
  try {
495
488
  var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
496
489
  localStorage.setItem(key, stringValue);
497
490
  } catch (e) {}
498
- },
499
- removeItem: function removeItem(key) {
491
+ };
492
+ Local.prototype.removeItem = function (key) {
500
493
  try {
501
494
  localStorage.removeItem(key);
502
495
  } catch (e) {}
503
- },
504
- getCookie: function getCookie(name, domain) {
496
+ };
497
+ return Local;
498
+ }();
499
+ /**
500
+ * sessionStorage
501
+ */
502
+ var Session$1 = /** @class */function () {
503
+ function Session() {
504
+ this.support = this.isSupportSession();
505
+ }
506
+ Session.prototype.isSupportSession = function () {
505
507
  try {
506
- var _matches = cookie.get(name);
507
- return _matches;
508
+ sessionStorage.setItem('_applogtest-test-key', 'hi');
509
+ sessionStorage.getItem('_applogtest-test-key');
510
+ sessionStorage.removeItem('_applogtest-test-key');
511
+ return true;
508
512
  } catch (e) {
509
- return '';
513
+ return false;
510
514
  }
511
- },
512
- setCookie: function setCookie(name, value, expiresTime, domain) {
513
- try {
514
- var _domain = domain || document.domain;
515
- var timestamp = +new Date();
516
- var furureTimestamp = timestamp + expiresTime; // 3年
517
- cookie.set(name, value, {
518
- expires: new Date(furureTimestamp),
519
- path: '/',
520
- domain: _domain
521
- });
522
- } catch (e) {}
523
- },
524
- isSupportLS: isSupportLS()
525
- };
526
- var session = {
527
- getItem: function getItem(key) {
515
+ };
516
+ Session.prototype.getItem = function (key) {
528
517
  try {
529
518
  var value = sessionStorage.getItem(key);
530
519
  var ret = value;
@@ -536,56 +525,92 @@ var session = {
536
525
  return ret || {};
537
526
  } catch (e) {}
538
527
  return {};
539
- },
540
- setItem: function setItem(key, value) {
528
+ };
529
+ Session.prototype.setItem = function (key, value) {
541
530
  try {
542
531
  var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
543
532
  sessionStorage.setItem(key, stringValue);
544
533
  } catch (e) {}
545
- },
546
- removeItem: function removeItem(key) {
534
+ };
535
+ Session.prototype.removeItem = function (key) {
547
536
  try {
548
537
  sessionStorage.removeItem(key);
549
538
  } catch (e) {}
550
- },
551
- getCookie: function getCookie(name) {
552
- this.getItem(name);
553
- },
554
- setCookie: function setCookie(key, value) {
555
- this.setItem(key, value);
556
- },
557
- isSupportSession: isSupportSession()
558
- };
559
- var Storage = /** @class */function () {
560
- function Storage(isCache, type) {
561
- if (type && type === 'session') {
562
- this._storage = session;
563
- } else {
564
- this._storage = !isCache && local.isSupportLS ? local : new Memory$1();
565
- }
539
+ };
540
+ return Session;
541
+ }();
542
+ var StorageManager = /** @class */function () {
543
+ function StorageManager() {
544
+ this.defaultExpireTime = 7 * 1000 * 60 * 60 * 24;
545
+ this.local = new Local();
546
+ this.session = new Session$1();
547
+ this.cache = new Memory();
566
548
  }
567
- Storage.prototype.getItem = function (key) {
568
- return this._storage.getItem(key);
549
+ StorageManager.prototype.getLocalItem = function (key) {
550
+ return this.local.getItem(key);
569
551
  };
570
- Storage.prototype.setItem = function (key, value) {
571
- this._storage.setItem(key, value);
552
+ StorageManager.prototype.setLocalItem = function (key, value) {
553
+ this.local.setItem(key, value);
572
554
  };
573
- Storage.prototype.getCookie = function (name, domain) {
574
- return this._storage.getCookie(name, domain);
555
+ StorageManager.prototype.removeLocalItem = function (key) {
556
+ this.local.removeItem(key);
575
557
  };
576
- Storage.prototype.setCookie = function (key, value, expiresTime, domain) {
577
- this._storage.setCookie(key, value, expiresTime, domain);
558
+ StorageManager.prototype.getSessionItem = function (key) {
559
+ return this.session.getItem(key);
578
560
  };
579
- Storage.prototype.removeItem = function (key) {
580
- this._storage.removeItem(key);
561
+ StorageManager.prototype.setSessionItem = function (key, value) {
562
+ this.session.setItem(key, value);
581
563
  };
582
- return Storage;
564
+ StorageManager.prototype.removeSessionItem = function (key) {
565
+ this.session.removeItem(key);
566
+ };
567
+ StorageManager.prototype.getCacheItem = function (key) {
568
+ return this.cache.getItem(key);
569
+ };
570
+ StorageManager.prototype.setCacheItem = function (key, value) {
571
+ this.cache.setItem(key, value);
572
+ };
573
+ StorageManager.prototype.removeCacheItem = function (key) {
574
+ this.cache.removeItem(key);
575
+ };
576
+ StorageManager.prototype.getCookie = function (key, domain) {
577
+ try {
578
+ // const _matches = Cookies.get(name, { domain: domain || document.domain })
579
+ var _matches = cookie.get(key);
580
+ return _matches;
581
+ } catch (e) {
582
+ return '';
583
+ }
584
+ };
585
+ StorageManager.prototype.setCookie = function (key, value, expiresTime, domain) {
586
+ if (expiresTime === void 0) {
587
+ expiresTime = this.defaultExpireTime;
588
+ }
589
+ try {
590
+ var _domain = domain || document.domain;
591
+ var timestamp = +new Date();
592
+ var furureTimestamp = timestamp + expiresTime;
593
+ cookie.set(key, value, {
594
+ expires: new Date(furureTimestamp),
595
+ path: '/',
596
+ domain: _domain
597
+ });
598
+ } catch (e) {}
599
+ };
600
+ StorageManager.prototype.removeCookie = function (key, domain) {
601
+ try {
602
+ cookie.remove(key, {
603
+ path: '/',
604
+ domain: domain || ''
605
+ });
606
+ } catch (e) {}
607
+ };
608
+ return StorageManager;
583
609
  }();
584
610
 
585
611
  // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
586
612
  var UTM = function UTM(app_id, urlQueryObj, domain, cookie_expire) {
587
- var storage = new Storage(false);
588
- var session = new Storage(false, 'session');
613
+ var storage = new StorageManager();
589
614
  var cacheKey = app_id ? "_tea_utm_cache_" + app_id : '_tea_utm_cache';
590
615
  var sourceKey = app_id ? "_$utm_from_url_" + app_id : '_$utm_from_url';
591
616
  var utmObj = {};
@@ -623,7 +648,7 @@ var UTM = function UTM(app_id, urlQueryObj, domain, cookie_expire) {
623
648
  }
624
649
  if (utmFromUrl) {
625
650
  // 发现url上有则更新缓存,并上报
626
- session.setItem(sourceKey, '1');
651
+ storage.setSessionItem(sourceKey, '1');
627
652
  storage.setCookie(cacheKey, JSON.stringify(utmObj), cookie_expire, domain);
628
653
  } else {
629
654
  // url没有则取缓存
@@ -632,7 +657,7 @@ var UTM = function UTM(app_id, urlQueryObj, domain, cookie_expire) {
632
657
  utmObj = JSON.parse(cache);
633
658
  }
634
659
  }
635
- if (session.getItem(sourceKey)) {
660
+ if (storage.getSessionItem(sourceKey)) {
636
661
  if (!utmObj.hasOwnProperty('tracer_data')) {
637
662
  utmObj['tracer_data'] = {};
638
663
  }
@@ -939,180 +964,6 @@ var Client = /** @class */function () {
939
964
  return Client;
940
965
  }();
941
966
 
942
- // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
943
- /**
944
- * cacheStorage
945
- */
946
- var Memory = /** @class */function () {
947
- function Memory() {
948
- this.cache = {};
949
- }
950
- Memory.prototype.setItem = function (cacheKey, data) {
951
- this.cache[cacheKey] = data;
952
- };
953
- Memory.prototype.getItem = function (cacheKey) {
954
- return this.cache[cacheKey];
955
- };
956
- Memory.prototype.removeItem = function (cacheKey) {
957
- this.cache[cacheKey] = undefined;
958
- };
959
- return Memory;
960
- }();
961
- /**
962
- * localStorage
963
- */
964
- var Local = /** @class */function () {
965
- function Local() {
966
- this.support = this.isSupportLS();
967
- }
968
- Local.prototype.isSupportLS = function () {
969
- try {
970
- localStorage.setItem('_applogtest-test-key', 'hi');
971
- localStorage.getItem('_applogtest-test-key');
972
- localStorage.removeItem('_applogtest-test-key');
973
- return true;
974
- } catch (e) {
975
- return false;
976
- }
977
- };
978
- Local.prototype.getItem = function (key) {
979
- try {
980
- var value = localStorage.getItem(key);
981
- var ret = value;
982
- try {
983
- if (value && typeof value === 'string') {
984
- ret = JSON.parse(value);
985
- }
986
- } catch (e) {}
987
- return ret || {};
988
- } catch (e) {}
989
- return {};
990
- };
991
- Local.prototype.setItem = function (key, value) {
992
- try {
993
- var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
994
- localStorage.setItem(key, stringValue);
995
- } catch (e) {}
996
- };
997
- Local.prototype.removeItem = function (key) {
998
- try {
999
- localStorage.removeItem(key);
1000
- } catch (e) {}
1001
- };
1002
- return Local;
1003
- }();
1004
- /**
1005
- * sessionStorage
1006
- */
1007
- var Session$1 = /** @class */function () {
1008
- function Session() {
1009
- this.support = this.isSupportSession();
1010
- }
1011
- Session.prototype.isSupportSession = function () {
1012
- try {
1013
- sessionStorage.setItem('_applogtest-test-key', 'hi');
1014
- sessionStorage.getItem('_applogtest-test-key');
1015
- sessionStorage.removeItem('_applogtest-test-key');
1016
- return true;
1017
- } catch (e) {
1018
- return false;
1019
- }
1020
- };
1021
- Session.prototype.getItem = function (key) {
1022
- try {
1023
- var value = sessionStorage.getItem(key);
1024
- var ret = value;
1025
- try {
1026
- if (value && typeof value === 'string') {
1027
- ret = JSON.parse(value);
1028
- }
1029
- } catch (e) {}
1030
- return ret || {};
1031
- } catch (e) {}
1032
- return {};
1033
- };
1034
- Session.prototype.setItem = function (key, value) {
1035
- try {
1036
- var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
1037
- sessionStorage.setItem(key, stringValue);
1038
- } catch (e) {}
1039
- };
1040
- Session.prototype.removeItem = function (key) {
1041
- try {
1042
- sessionStorage.removeItem(key);
1043
- } catch (e) {}
1044
- };
1045
- return Session;
1046
- }();
1047
- var StorageManager = /** @class */function () {
1048
- function StorageManager() {
1049
- this.defaultExpireTime = 7 * 1000 * 60 * 60 * 24;
1050
- this.local = new Local();
1051
- this.session = new Session$1();
1052
- this.cache = new Memory();
1053
- }
1054
- StorageManager.prototype.getLocalItem = function (key) {
1055
- return this.local.getItem(key);
1056
- };
1057
- StorageManager.prototype.setLocalItem = function (key, value) {
1058
- this.local.setItem(key, value);
1059
- };
1060
- StorageManager.prototype.removeLocalItem = function (key) {
1061
- this.local.removeItem(key);
1062
- };
1063
- StorageManager.prototype.getSessionItem = function (key) {
1064
- return this.session.getItem(key);
1065
- };
1066
- StorageManager.prototype.setSessionItem = function (key, value) {
1067
- this.session.setItem(key, value);
1068
- };
1069
- StorageManager.prototype.removeSessionItem = function (key) {
1070
- this.session.removeItem(key);
1071
- };
1072
- StorageManager.prototype.getCacheItem = function (key) {
1073
- return this.cache.getItem(key);
1074
- };
1075
- StorageManager.prototype.setCacheItem = function (key, value) {
1076
- this.cache.setItem(key, value);
1077
- };
1078
- StorageManager.prototype.removeCacheItem = function (key) {
1079
- this.cache.removeItem(key);
1080
- };
1081
- StorageManager.prototype.getCookie = function (key, domain) {
1082
- try {
1083
- // const _matches = Cookies.get(name, { domain: domain || document.domain })
1084
- var _matches = cookie.get(key);
1085
- return _matches;
1086
- } catch (e) {
1087
- return '';
1088
- }
1089
- };
1090
- StorageManager.prototype.setCookie = function (key, value, expiresTime, domain) {
1091
- if (expiresTime === void 0) {
1092
- expiresTime = this.defaultExpireTime;
1093
- }
1094
- try {
1095
- var _domain = domain || document.domain;
1096
- var timestamp = +new Date();
1097
- var furureTimestamp = timestamp + expiresTime;
1098
- cookie.set(key, value, {
1099
- expires: new Date(furureTimestamp),
1100
- path: '/',
1101
- domain: _domain
1102
- });
1103
- } catch (e) {}
1104
- };
1105
- StorageManager.prototype.removeCookie = function (key, domain) {
1106
- try {
1107
- cookie.remove(key, {
1108
- path: '/',
1109
- domain: domain || ''
1110
- });
1111
- } catch (e) {}
1112
- };
1113
- return StorageManager;
1114
- }();
1115
-
1116
967
  // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
1117
968
  var LOG;
1118
969
  LOG = {
@@ -1122,7 +973,9 @@ LOG = {
1122
973
  };
1123
974
  // CN: https://mcs.volceapplog.com VA: https://mcs.itobsnssdk.com SG: https://mcs.tobsnssdk.com
1124
975
  var LOG_URL = LOG;
1125
- var SDK_VERSION = '0.1.3';
976
+ var SDK_VERSION = '0.1.4';
977
+ var SDK_USE_TYPE = 'npm';
978
+ var SDK_TYPE = SDK_USE_TYPE;
1126
979
  var AB_DOMAINS = {
1127
980
  cn: '1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k',
1128
981
  va: '1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k',
@@ -2963,6 +2816,559 @@ var RequestManager = /** @class */function () {
2963
2816
  return RequestManager;
2964
2817
  }();
2965
2818
 
2819
+ // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
2820
+ // debugger icon的可拖拽
2821
+ var DraggableButton = /** @class */function () {
2822
+ function DraggableButton(element) {
2823
+ var _this = this;
2824
+ this.onMove = function (e) {
2825
+ if (!_this.isDragging) return;
2826
+ // 判断是否达到拖拽阈值
2827
+ var currentX = e.clientX || e.touches[0].clientX;
2828
+ var currentY = e.clientY || e.touches[0].clientY;
2829
+ if (_this.clickAllowed) {
2830
+ var deltaX = Math.abs(currentX - _this.initialX);
2831
+ var deltaY = Math.abs(currentY - _this.initialY);
2832
+ if (deltaX > _this.dragThreshold || deltaY > _this.dragThreshold) {
2833
+ _this.clickAllowed = false;
2834
+ }
2835
+ }
2836
+ // 节流处理
2837
+ if (_this.animationFrameId) {
2838
+ cancelAnimationFrame(_this.animationFrameId);
2839
+ }
2840
+ _this.animationFrameId = requestAnimationFrame(function () {
2841
+ var clientX = e.touches ? e.touches[0].clientX : e.clientX;
2842
+ var clientY = e.touches ? e.touches[0].clientY : e.clientY;
2843
+ // 计算新位置
2844
+ var newX = clientX - _this.offsetX;
2845
+ var newY = clientY - _this.offsetY;
2846
+ // 边界限制
2847
+ var maxX = window.innerWidth - _this.element.offsetWidth;
2848
+ var maxY = window.innerHeight - _this.element.offsetHeight;
2849
+ newX = Math.max(0, Math.min(newX, maxX));
2850
+ newY = Math.max(0, Math.min(newY, maxY));
2851
+ // 直接应用transform(不修改left/top)
2852
+ _this.element.style.transform = "translate(\n " + (newX - _this.initialX) + "px, \n " + (newY - _this.initialY) + "px\n )";
2853
+ });
2854
+ };
2855
+ this.onEnd = function () {
2856
+ if (!_this.isDragging) return;
2857
+ _this.isDragging = false;
2858
+ // 将最终位置同步到left/top
2859
+ var matrix = new DOMMatrix(getComputedStyle(_this.element).transform);
2860
+ var finalX = _this.initialX + matrix.m41;
2861
+ var finalY = _this.initialY + matrix.m42;
2862
+ _this.element.style.left = finalX + "px";
2863
+ _this.element.style.top = finalY + "px";
2864
+ _this.element.style.transform = 'none';
2865
+ // 更新初始位置记录
2866
+ _this.initialX = finalX;
2867
+ _this.initialY = finalY;
2868
+ // 清理事件监听
2869
+ document.removeEventListener('mousemove', _this.onMove);
2870
+ document.removeEventListener('mouseup', _this.onEnd);
2871
+ document.removeEventListener('touchmove', _this.onMove);
2872
+ document.removeEventListener('touchend', _this.onEnd);
2873
+ setTimeout(function () {
2874
+ _this.clickAllowed = true;
2875
+ }, 50);
2876
+ };
2877
+ this.element = element;
2878
+ this.isDragging = false;
2879
+ this.enableClick = false;
2880
+ this.animationFrameId = null;
2881
+ this.lastX = 0;
2882
+ this.lastY = 0;
2883
+ this.initialX = 0; // 元素初始X坐标
2884
+ this.initialY = 0; // 元素初始Y坐标
2885
+ this.offsetX = 0;
2886
+ this.offsetY = 0;
2887
+ this.clickAllowed = true;
2888
+ this.dragThreshold = 1; // 移动超过5px视为拖拽
2889
+ this.initPosition();
2890
+ this.bindEvents();
2891
+ this.bindClickHandler();
2892
+ }
2893
+ // 初始化元素定位方式
2894
+ DraggableButton.prototype.initPosition = function () {
2895
+ var rect = this.element.getBoundingClientRect();
2896
+ this.element.style.position = 'fixed';
2897
+ this.element.style.left = rect.left + "px";
2898
+ this.element.style.top = rect.top + "px";
2899
+ this.element.style.transform = 'translate(0, 0)';
2900
+ };
2901
+ DraggableButton.prototype.bindEvents = function () {
2902
+ this.element.addEventListener('mousedown', this.onStart.bind(this));
2903
+ this.element.addEventListener('touchstart', this.onStart.bind(this));
2904
+ };
2905
+ DraggableButton.prototype.onStart = function (e) {
2906
+ e.preventDefault();
2907
+ this.initialX = e.clientX || e.touches[0].clientX;
2908
+ this.initialY = e.clientY || e.touches[0].clientY;
2909
+ var clientX = e.touches ? e.touches[0].clientX : e.clientX;
2910
+ var clientY = e.touches ? e.touches[0].clientY : e.clientY;
2911
+ // 获取元素当前实际位置(包含transform)
2912
+ var rect = this.element.getBoundingClientRect();
2913
+ this.initialX = rect.left;
2914
+ this.initialY = rect.top;
2915
+ // 计算点击位置偏移量
2916
+ this.offsetX = clientX - this.initialX;
2917
+ this.offsetY = clientY - this.initialY;
2918
+ this.clickAllowed = true;
2919
+ this.isDragging = true;
2920
+ document.addEventListener('mousemove', this.onMove);
2921
+ document.addEventListener('mouseup', this.onEnd);
2922
+ document.addEventListener('touchmove', this.onMove);
2923
+ document.addEventListener('touchend', this.onEnd);
2924
+ };
2925
+ // 修改后的点击事件绑定方式
2926
+ DraggableButton.prototype.bindClickHandler = function () {
2927
+ var _this = this;
2928
+ this.element.addEventListener('click', function (e) {
2929
+ if (!_this.enableClick) return;
2930
+ if (!_this.clickAllowed) {
2931
+ e.stopImmediatePropagation();
2932
+ e.preventDefault();
2933
+ return;
2934
+ }
2935
+ // 原有的点击处理逻辑
2936
+ window && window.postMessage({
2937
+ type: 'devtool:web:open-draw'
2938
+ }, location.origin);
2939
+ });
2940
+ };
2941
+ DraggableButton.prototype.enable = function () {
2942
+ this.enableClick = true;
2943
+ this.element.style.cursor = 'pointer';
2944
+ this.element.style.opacity = '1';
2945
+ };
2946
+ return DraggableButton;
2947
+ }();
2948
+
2949
+ // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
2950
+ var Debugger = /** @class */function () {
2951
+ function Debugger(collect, config) {
2952
+ this.devToolReady = false;
2953
+ this.devToolOrigin = '*';
2954
+ this.sendAlready = false;
2955
+ this.trackEnabled = true;
2956
+ if (config.disable_debug) return;
2957
+ if (collect.configManager.get('browser') === 'Microsoft Internet Explorer') return;
2958
+ this.collect = collect;
2959
+ this.config = config;
2960
+ this.app_id = config.app_id;
2961
+ this.trackEnabled = config.track_enabled ? true : false;
2962
+ this.cacheStorgae = new StorageManager();
2963
+ this.currentAppKey = "__applog_load_devtool_web_" + this.app_id;
2964
+ this.loadUrl = config.devtool_url || 'https://lf-static.applogcdn.com/obj/applog-sdk-static/log-sdk/collect/devtool/debug-web.v2.0.1.js';
2965
+ this.filterEvent = new Set(['__bav_page', '__bav_beat', '__bav_page_statistics', '__bav_click', '__bav_page_exposure', 'bav2b_page', 'bav2b_beat', 'bav2b_page_statistics', 'bav2b_click', 'bav2b_page_exposure', '_be_active', 'predefine_pageview', '__profile_set', '__profile_set_once', '__profile_increment', '__profile_unset', '__profile_append', 'predefine_page_alive', 'predefine_page_close', 'abtest_exposure']);
2966
+ this.load();
2967
+ }
2968
+ Debugger.prototype.loadScript = function (src) {
2969
+ var _this = this;
2970
+ try {
2971
+ var script = document.createElement('script');
2972
+ script.src = src;
2973
+ script.onerror = function () {
2974
+ console.log('load DevTool render fail');
2975
+ };
2976
+ script.onload = function () {
2977
+ _this.enableDebugButton();
2978
+ console.log('load DevTool render success');
2979
+ };
2980
+ document.getElementsByTagName('body')[0].appendChild(script);
2981
+ } catch (e) {
2982
+ console.log("devTool load fail, " + e.message);
2983
+ }
2984
+ };
2985
+ Debugger.prototype.parseUrl = function () {
2986
+ var params = {};
2987
+ try {
2988
+ var url = window.location.href;
2989
+ var hash = url.split('?')[1].split('&');
2990
+ if (hash.length) {
2991
+ hash.forEach(function (h) {
2992
+ var parts = h.split('=');
2993
+ params[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
2994
+ });
2995
+ }
2996
+ } catch (e) {}
2997
+ return params;
2998
+ };
2999
+ Debugger.prototype.load = function () {
3000
+ try {
3001
+ var queryObj = this.parseUrl();
3002
+ if (queryObj['open_devtool_web'] == false) {
3003
+ this.cacheStorgae.removeLocalItem("__applog_open_devtool_web");
3004
+ return;
3005
+ }
3006
+ if (queryObj['open_devtool_web'] && queryObj['app_id']) {
3007
+ if (parseInt(queryObj['app_id']) !== this.app_id) return;
3008
+ } else {
3009
+ if (!this.getStorage()) return;
3010
+ }
3011
+ this.loadBaseInfo();
3012
+ this.loadHook();
3013
+ this.setStorage();
3014
+ this.addLintener();
3015
+ this.loadDevTool();
3016
+ } catch (e) {
3017
+ console.log("debug fail, " + e.message);
3018
+ }
3019
+ };
3020
+ Debugger.prototype.getStorage = function () {
3021
+ var storage_appid = this.cacheStorgae.getLocalItem("__applog_open_devtool_web");
3022
+ return storage_appid && parseInt(storage_appid) === this.app_id;
3023
+ };
3024
+ Debugger.prototype.setStorage = function () {
3025
+ this.cacheStorgae.setLocalItem('__applog_open_devtool_web', this.app_id);
3026
+ this.cacheStorgae.setLocalItem('__applog_devtool_web_track_enable', this.trackEnabled);
3027
+ };
3028
+ Debugger.prototype.loadDevTool = function () {
3029
+ var currentAppHasLoad = this.cacheStorgae.getLocalItem(this.currentAppKey) == 1;
3030
+ if (currentAppHasLoad) {
3031
+ console.warn("your appid: " + this.app_id + " has load web devtools already, maybe your page has more than two applogsdk and use one appid");
3032
+ return;
3033
+ }
3034
+ this.loadDebuggerModule();
3035
+ this.loadScript(this.loadUrl);
3036
+ };
3037
+ Debugger.prototype.loadBaseInfo = function () {
3038
+ this.log = [];
3039
+ this.event = [];
3040
+ this.info = [{
3041
+ title: '基本信息',
3042
+ key: 'base',
3043
+ type: 1,
3044
+ content: [{
3045
+ name: 'app_id',
3046
+ desc: 'APP_ID',
3047
+ value: this.config.app_id
3048
+ }, {
3049
+ name: 'channel',
3050
+ desc: 'CHANNEL',
3051
+ value: this.config.channel
3052
+ }, {
3053
+ name: 'domain',
3054
+ desc: '上报域名',
3055
+ value: this.collect.configManager.getDomain()
3056
+ }, {
3057
+ name: 'sdk_version',
3058
+ desc: 'SDK版本',
3059
+ value: SDK_VERSION
3060
+ }, {
3061
+ name: 'sdk_type',
3062
+ desc: 'SDK引入方式',
3063
+ value: SDK_TYPE
3064
+ }]
3065
+ }, {
3066
+ title: '用户信息',
3067
+ key: 'user',
3068
+ type: 2,
3069
+ content: [{
3070
+ name: 'uuid',
3071
+ desc: 'UUID',
3072
+ value: this.collect.configManager.get('user').user_unique_id || ''
3073
+ }, {
3074
+ name: 'web_id',
3075
+ desc: 'WEB_ID',
3076
+ value: this.collect.configManager.get('user').web_id || ''
3077
+ }]
3078
+ }, {
3079
+ title: '公共参数信息',
3080
+ type: 2,
3081
+ key: 'common',
3082
+ content: [{
3083
+ name: 'browser',
3084
+ desc: '浏览器',
3085
+ value: this.collect.configManager.get('browser')
3086
+ }, {
3087
+ name: 'browser_version',
3088
+ desc: '浏览器版本',
3089
+ value: this.collect.configManager.get('browser_version')
3090
+ }, {
3091
+ name: 'platform',
3092
+ desc: '平台',
3093
+ value: this.collect.configManager.get('platform')
3094
+ }, {
3095
+ name: 'device_model',
3096
+ desc: '设备型号',
3097
+ value: this.collect.configManager.get('device_model')
3098
+ }, {
3099
+ name: 'os_name',
3100
+ desc: '操作系统',
3101
+ value: this.collect.configManager.get('os_name')
3102
+ }, {
3103
+ name: 'os_version',
3104
+ desc: '操作系统版本',
3105
+ value: this.collect.configManager.get('os_version')
3106
+ }, {
3107
+ name: 'resolution',
3108
+ desc: '屏幕分辨率',
3109
+ value: this.collect.configManager.get('resolution')
3110
+ }, {
3111
+ name: 'referrer',
3112
+ desc: '来源',
3113
+ value: this.collect.configManager.get('referrer')
3114
+ }, {
3115
+ name: 'custom',
3116
+ desc: '自定义信息',
3117
+ value: JSON.stringify(this.collect.configManager.get('custom'))
3118
+ }]
3119
+ }, {
3120
+ title: '配置信息',
3121
+ key: 'config',
3122
+ type: 3,
3123
+ content: [{
3124
+ name: 'autotrack',
3125
+ desc: '全埋点',
3126
+ value: this.config.autotrack ? true : false
3127
+ }, {
3128
+ name: 'stay',
3129
+ desc: '停留时长',
3130
+ value: this.config.enable_stay_duration ? true : false
3131
+ }]
3132
+ }, {
3133
+ title: 'A/B配置信息',
3134
+ key: 'ab',
3135
+ type: 4,
3136
+ content: [{
3137
+ name: 'ab',
3138
+ desc: 'A/B实验',
3139
+ value: this.config.enable_ab_test ? true : false
3140
+ }]
3141
+ }];
3142
+ if (this.config.enable_ab_test) {
3143
+ var ab = this.getInfo('ab');
3144
+ var content = [{
3145
+ name: 'ab',
3146
+ desc: 'A/B实验',
3147
+ value: this.config.enable_ab_test ? true : false
3148
+ }, {
3149
+ name: 'vid',
3150
+ desc: '已曝光VID',
3151
+ value: this.collect.configManager.getAbVersion()
3152
+ }, {
3153
+ name: 'ab_domain',
3154
+ desc: 'A/B域名',
3155
+ value: this.config.ab_channel_domain || decodeUrl(AB_DOMAINS[this.config.channel])
3156
+ }, {
3157
+ name: 'all_values',
3158
+ desc: '全部配置',
3159
+ value: this.collect.configManager.getAbCache()
3160
+ }];
3161
+ ab.content = content;
3162
+ this.setInfo('ab', ab);
3163
+ }
3164
+ if (this.config.enable_native || this.config.Native) {
3165
+ var _native = {
3166
+ title: '客户端信息',
3167
+ type: 3,
3168
+ content: [{
3169
+ name: 'native',
3170
+ desc: '是否打通',
3171
+ value: this.collect.bridgeReport ? true : false
3172
+ }]
3173
+ };
3174
+ this.setInfo('native', _native);
3175
+ }
3176
+ if (SDK_VERSION.includes('tob')) {
3177
+ var user = this.getInfo('user');
3178
+ user.content.push({
3179
+ name: 'sid',
3180
+ desc: 'DISS'.split('').reverse().join(''),
3181
+ value: '点击获取'
3182
+ });
3183
+ this.setInfo('user', user);
3184
+ }
3185
+ };
3186
+ Debugger.prototype.getInfo = function (key) {
3187
+ var current = null;
3188
+ this.info.forEach(function (item) {
3189
+ if (item.key === key) {
3190
+ current = item;
3191
+ }
3192
+ });
3193
+ return current;
3194
+ };
3195
+ Debugger.prototype.setInfo = function (key, data) {
3196
+ var hasKey = false;
3197
+ this.info.forEach(function (item) {
3198
+ if (item.key === key) {
3199
+ hasKey = true;
3200
+ item = data;
3201
+ }
3202
+ });
3203
+ if (!hasKey) {
3204
+ this.info.push(data);
3205
+ }
3206
+ };
3207
+ Debugger.prototype.getSecondInfo = function (key, valueKey) {
3208
+ var data = this.getInfo(key);
3209
+ var current = null;
3210
+ data.content.forEach(function (item) {
3211
+ if (item.name === valueKey) {
3212
+ current = item;
3213
+ }
3214
+ });
3215
+ return current;
3216
+ };
3217
+ Debugger.prototype.setSecondInfo = function (key, valueKey, value) {
3218
+ var data = this.getInfo(key);
3219
+ var contentHasKey = false;
3220
+ data.content.forEach(function (item) {
3221
+ if (item.name === valueKey) {
3222
+ item.value = value;
3223
+ contentHasKey = true;
3224
+ }
3225
+ });
3226
+ if (!contentHasKey) {
3227
+ var newContent = {
3228
+ name: valueKey,
3229
+ value: value,
3230
+ desc: valueKey.toLocaleUpperCase()
3231
+ };
3232
+ data.content.push(newContent);
3233
+ }
3234
+ this.setInfo(key, data);
3235
+ };
3236
+ Debugger.prototype.loadHook = function () {
3237
+ var _this = this;
3238
+ this.collect.on(DebuggerMesssge.DEBUGGER_MESSAGE, function (data) {
3239
+ switch (data.type) {
3240
+ case DebuggerMesssge.DEBUGGER_MESSAGE_SDK:
3241
+ var logObj = {
3242
+ time: data.time,
3243
+ type: data.logType || 'sdk',
3244
+ infoType: data.infoType || 'sdk',
3245
+ level: data.level,
3246
+ name: data.info,
3247
+ show: true,
3248
+ levelShow: true,
3249
+ needDesc: data.data ? true : false
3250
+ };
3251
+ if (data.data) {
3252
+ logObj['desc'] = {
3253
+ content: JSON.stringify(data.data)
3254
+ };
3255
+ }
3256
+ _this.updateLog(logObj);
3257
+ if (data.secType && data.secType === 'AB') {
3258
+ _this.setSecondInfo('ab', 'vid', _this.collect.configManager.getAbVersion());
3259
+ _this.setSecondInfo('ab', 'all_values', _this.collect.configManager.getAbCache());
3260
+ } else if (data.secType === 'USER') {
3261
+ // this.setSecondInfo('user', 'uuid', this.collect.configManager.get('user_unique_id'))
3262
+ // this.setSecondInfo('user', 'web_id', this.collect.configManager.get('web_id'))
3263
+ _this.setSecondInfo('user', data.common === 'user_unique_id' ? 'uuid' : data.common, _this.collect.configManager.get(data.common));
3264
+ } else if (data.secType === 'HEADER') {
3265
+ var value = _this.collect.configManager.get(data.common);
3266
+ _this.setSecondInfo('common', data.common, data.common === 'custom' ? JSON.stringify(value) : value);
3267
+ }
3268
+ _this.updateInfo();
3269
+ return;
3270
+ case DebuggerMesssge.DEBUGGER_MESSAGE_EVENT:
3271
+ if (data.data && data.data.length) {
3272
+ var events = data.data[0];
3273
+ var event_1 = events.events;
3274
+ if (!event_1.length) return;
3275
+ event_1.forEach(function (item) {
3276
+ item['checkShow'] = true;
3277
+ item['searchShow'] = true;
3278
+ item['focusShow'] = true;
3279
+ item['status'] = data.status;
3280
+ item['type'] = _this.filterEvent.has(item.event) ? 'sdk' : 'cus';
3281
+ item['verifyType'] = data.verifyType ? 'verify' : 'no';
3282
+ item['info'] = '';
3283
+ if (data.status === 'fail') {
3284
+ item['info'] = {
3285
+ message: "code: " + data.code + "\uFF0C msg: " + (data.msg || data.failType)
3286
+ };
3287
+ }
3288
+ });
3289
+ _this.updateEvent(events);
3290
+ }
3291
+ return;
3292
+ }
3293
+ });
3294
+ };
3295
+ Debugger.prototype.addLintener = function () {
3296
+ var _this = this;
3297
+ window.addEventListener('message', function (messgae) {
3298
+ if (messgae && messgae.data && messgae.data.type === 'devtool:web:ready') {
3299
+ _this.devToolOrigin = messgae.origin;
3300
+ _this.devToolReady = true;
3301
+ if (_this.sendAlready) return;
3302
+ _this.sendData('devtool:web:init', {
3303
+ info: _this.info,
3304
+ log: _this.log,
3305
+ event: _this.event,
3306
+ sdk_type: SDK_VERSION.includes('tob') ? 'tob' : 'inner',
3307
+ appId: _this.app_id
3308
+ });
3309
+ _this.sendAlready = true;
3310
+ }
3311
+ if (messgae && messgae.data && messgae.data.type === 'devtool:web:ssid') {
3312
+ _this.collect.getToken(function (res) {
3313
+ _this.setSecondInfo('user', 'sid', res.tobid);
3314
+ _this.updateInfo();
3315
+ });
3316
+ }
3317
+ });
3318
+ };
3319
+ Debugger.prototype.sendData = function (type, data) {
3320
+ try {
3321
+ var postData = {
3322
+ type: type,
3323
+ payload: data
3324
+ };
3325
+ // (window.opener || window.parent).postMessage(postData, this.devToolOrigin);
3326
+ window && window.postMessage(postData, this.devToolOrigin);
3327
+ } catch (e) {}
3328
+ };
3329
+ Debugger.prototype.updateInfo = function () {
3330
+ if (!this.devToolReady) {
3331
+ return;
3332
+ }
3333
+ this.sendData('devtool:web:info', this.info);
3334
+ };
3335
+ Debugger.prototype.updateLog = function (logObj) {
3336
+ if (!this.devToolReady) {
3337
+ this.log.push(logObj);
3338
+ return;
3339
+ }
3340
+ this.sendData('devtool:web:log', logObj);
3341
+ };
3342
+ Debugger.prototype.updateEvent = function (events) {
3343
+ if (!this.devToolReady) {
3344
+ this.event.push(events);
3345
+ return;
3346
+ }
3347
+ this.sendData('devtool:web:event', events);
3348
+ };
3349
+ Debugger.prototype.loadDebuggerModule = function () {
3350
+ var debugCss = "#debugger-applog-web {\n position: fixed;\n width: 90px;\n height: 30px;\n background: #23c243;\n border-radius: 6px;\n color: #fff;\n font-size: 12px;\n bottom: 5%;\n right: 10%;\n text-align: center;\n line-height: 30px;\n cursor: not-allowed;\n z-index:1000;\n font-weight:bold;\n opacity: 0.6;\n }";
3351
+ var head = document.head || document.getElementsByTagName('head')[0];
3352
+ var style = document.createElement('style');
3353
+ style.appendChild(document.createTextNode(debugCss));
3354
+ head.appendChild(style);
3355
+ var debuggerHtml = "<div id=\"debugger-applog-web\" class=\"debugger-applog-web\">AppLog\u8C03\u8BD5</div>";
3356
+ var debugDiv = document.createElement('div');
3357
+ debugDiv.innerHTML = debuggerHtml;
3358
+ var debuggerContainer = "<div id=\"debugger-container\" class=\"debugger-container\"></div>";
3359
+ var debugContainerDiv = document.createElement('div');
3360
+ debugContainerDiv.innerHTML = debuggerContainer;
3361
+ document.getElementsByTagName('body')[0].appendChild(debugDiv);
3362
+ document.getElementsByTagName('body')[0].appendChild(debugContainerDiv);
3363
+ var debugTool = document.getElementById('debugger-applog-web');
3364
+ this.debugButton = new DraggableButton(debugTool);
3365
+ };
3366
+ Debugger.prototype.enableDebugButton = function () {
3367
+ this.debugButton && this.debugButton.enable();
3368
+ };
3369
+ return Debugger;
3370
+ }();
3371
+
2966
3372
  var jsbn = createCommonjsModule(function (module, exports) {
2967
3373
  (function(){
2968
3374
  var dbits;
@@ -5123,7 +5529,7 @@ var Collector$1 = /** @class */function () {
5123
5529
  this.configManager = new ConfigManager(this, initConfig);
5124
5530
  this.appBridge = new AppBridge(initConfig, this.configManager);
5125
5531
  this.bridgeReport = this.appBridge.bridgeInject();
5126
- // this.debugger = new Debugger(this, initConfig)
5532
+ this["debugger"] = new Debugger(this, initConfig);
5127
5533
  this.requestManager = new RequestManager(this, initConfig);
5128
5534
  this.initConfig = initConfig;
5129
5535
  this.env = initConfig.channel_domain ? 'self' : 'public';
@@ -8942,8 +9348,7 @@ var Store = /** @class */function () {
8942
9348
  this.config = config;
8943
9349
  if (this.collect.destroy) return;
8944
9350
  var Types = collect.Types;
8945
- var storage = collect.adapters.storage;
8946
- this.storage = new storage(false);
9351
+ this.storage = new StorageManager();
8947
9352
  this.eventUrl = this.collect.configManager.getUrl('event');
8948
9353
  this.eventKey = "__tea_cache_events_" + config.app_id;
8949
9354
  this.storageNum = config.storage_num || 50; // 默认最大存储50条数据
@@ -8992,19 +9397,19 @@ var Store = /** @class */function () {
8992
9397
  }, this.retryInterval);
8993
9398
  };
8994
9399
  Store.prototype.storeData = function (errorInfo) {
8995
- var data = this.storage.getItem(this.eventKey);
9400
+ var data = this.storage.getLocalItem(this.eventKey);
8996
9401
  var eventData = errorInfo.eventData;
8997
9402
  // 数据错误不进行存储
8998
9403
  if (Object.keys(data).length === this.storageNum) return;
8999
9404
  // 数据满了,就不再添加数据
9000
9405
  data[Date.now()] = eventData;
9001
- this.storage.setItem(this.eventKey, data);
9406
+ this.storage.setLocalItem(this.eventKey, data);
9002
9407
  };
9003
9408
  Store.prototype.checkStorage = function () {
9004
9409
  var _this = this;
9005
9410
  try {
9006
9411
  if (!window.navigator.onLine) return; // 设备未联网
9007
- var data_1 = this.storage.getItem(this.eventKey);
9412
+ var data_1 = this.storage.getLocalItem(this.eventKey);
9008
9413
  if (!data_1 || !Object.keys(data_1).length) return;
9009
9414
  var loadData = {
9010
9415
  events: [{
@@ -9024,7 +9429,7 @@ var Store = /** @class */function () {
9024
9429
  var _loop_1 = function _loop_1(key) {
9025
9430
  _this.fetchData(data_1[key], function () {
9026
9431
  delete copyData[key];
9027
- _this.storage.setItem(_this.eventKey, copyData);
9432
+ _this.storage.setLocalItem(_this.eventKey, copyData);
9028
9433
  }, function () {}, false);
9029
9434
  };
9030
9435
  for (var key in data_1) {