pb-sxp-ui 1.16.14 → 1.16.15

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/dist/pb-ui.js CHANGED
@@ -756,8 +756,8 @@
756
756
  var _a;
757
757
  const body = {
758
758
  eventName: params === null || params === void 0 ? void 0 : params.eventName,
759
- eventSource: params === null || params === void 0 ? void 0 : params.eventSource,
760
- eventInfo: (params === null || params === void 0 ? void 0 : params.eventInfo) ? JSON.stringify(params === null || params === void 0 ? void 0 : params.eventInfo) : ''
759
+ eventSource: params === null || params === void 0 ? void 0 : params.eventSource
760
+ // eventInfo: params?.eventInfo ? JSON.stringify(params?.eventInfo) : ''
761
761
  };
762
762
  return bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch(`v1/data/collect/${(_a = bffDataSource === null || bffDataSource === void 0 ? void 0 : bffDataSource.headers) === null || _a === void 0 ? void 0 : _a['x-app-id']}/${params === null || params === void 0 ? void 0 : params.eventName}`, {
763
763
  method: 'POST',
@@ -784,8 +784,7 @@
784
784
  const params = Object.fromEntries(url.searchParams.entries());
785
785
  bffCollectEvent({
786
786
  eventName: params === null || params === void 0 ? void 0 : params.ev,
787
- eventSource: 'Meta Pixel',
788
- eventInfo: params
787
+ eventSource: 'Meta Pixel'
789
788
  });
790
789
  }
791
790
  };
@@ -798,6 +797,116 @@
798
797
  };
799
798
  }
800
799
  }, [bffCollectEvent]);
800
+ React.useEffect(() => {
801
+ // 类型安全声明
802
+ const navigatorWithBeacon = navigator;
803
+ if (!navigatorWithBeacon.sendBeacon) {
804
+ console.warn('navigator.sendBeacon is not supported');
805
+ return;
806
+ }
807
+ // 保存原始方法
808
+ const originalSendBeacon = navigatorWithBeacon.sendBeacon.bind(navigatorWithBeacon);
809
+ // 覆盖方法
810
+ navigatorWithBeacon.sendBeacon = function (url, data) {
811
+ const urlString = url instanceof URL ? url.href : url.toString();
812
+ const success = originalSendBeacon(url, data);
813
+ function parseBeaconData(data) {
814
+ return __awaiter(this, void 0, void 0, function* () {
815
+ if (typeof data === 'string')
816
+ return JSON.parse(data);
817
+ if (data instanceof Blob)
818
+ return JSON.parse(yield data.text());
819
+ if (data instanceof ArrayBuffer)
820
+ return JSON.parse(new TextDecoder().decode(data));
821
+ return null;
822
+ });
823
+ }
824
+ if (success) {
825
+ // 异步处理监控逻辑(不阻塞原始行为)
826
+ Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () {
827
+ var _a, _b;
828
+ try {
829
+ const parsedData = yield parseBeaconData(data);
830
+ if (success) {
831
+ // 使用你的自定义上报方法
832
+ if (urlString.includes('https://tr.snapchat.com/p')) {
833
+ (_b = (_a = parsedData === null || parsedData === void 0 ? void 0 : parsedData.req) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, (item) => {
834
+ var _a, _b;
835
+ if ((_a = item === null || item === void 0 ? void 0 : item.t) === null || _a === void 0 ? void 0 : _a.ev) {
836
+ bffCollectEvent({
837
+ eventName: (_b = item === null || item === void 0 ? void 0 : item.t) === null || _b === void 0 ? void 0 : _b.ev,
838
+ eventSource: 'Snapchat Pixel'
839
+ });
840
+ }
841
+ });
842
+ }
843
+ else if (urlString.includes('https://analytics.tiktok.com/api/v2/pixel') && (parsedData === null || parsedData === void 0 ? void 0 : parsedData.event)) {
844
+ bffCollectEvent({
845
+ eventName: parsedData.event,
846
+ eventSource: 'TikTok Pixel'
847
+ });
848
+ }
849
+ }
850
+ }
851
+ catch (error) {
852
+ console.error('监控失败:', error);
853
+ }
854
+ }));
855
+ }
856
+ // 非TikTok请求直接放行
857
+ return success;
858
+ };
859
+ // 清理函数:恢复原始方法
860
+ return () => {
861
+ navigatorWithBeacon.sendBeacon = originalSendBeacon;
862
+ };
863
+ }, [bffCollectEvent]);
864
+ React.useEffect(() => {
865
+ const _originalFetch = window.fetch;
866
+ // 覆盖 fetch 方法
867
+ window.fetch = function (input, init) {
868
+ var arguments_1 = arguments;
869
+ return __awaiter(this, void 0, void 0, function* () {
870
+ // 安全获取 URL 字符串
871
+ let url;
872
+ try {
873
+ url = typeof input === 'string'
874
+ ? input
875
+ : input instanceof URL
876
+ ? input.href
877
+ : input.url;
878
+ }
879
+ catch (error) {
880
+ console.error('解析请求URL失败:', error);
881
+ return _originalFetch.apply(this, arguments_1);
882
+ }
883
+ // 非GA4请求直接放行
884
+ if (!url.includes('https://www.google-analytics.com/g/collect')) {
885
+ return _originalFetch.apply(this, arguments_1);
886
+ }
887
+ // 检查是否是 GA4 收集端点
888
+ try {
889
+ // 1. 先执行原始请求
890
+ const response = yield _originalFetch.apply(this, arguments_1);
891
+ // 2. 检查请求是否成功 (HTTP 200-299)
892
+ // 安全解析 URL
893
+ const urlObj = new URL(url);
894
+ const params = Object.fromEntries(urlObj.searchParams.entries());
895
+ if (params === null || params === void 0 ? void 0 : params.en) {
896
+ bffCollectEvent({
897
+ eventName: params === null || params === void 0 ? void 0 : params.en,
898
+ eventSource: 'Google Analytics'
899
+ });
900
+ }
901
+ return response;
902
+ }
903
+ catch (error) {
904
+ console.error('处理 GA4 请求时出错:', error);
905
+ throw error;
906
+ }
907
+ });
908
+ };
909
+ }, [bffCollectEvent]);
801
910
  React.useEffect(() => {
802
911
  if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
803
912
  window === null || window === void 0 ? void 0 : window.fbq('track', 'PageView');
@@ -1058,10 +1167,6 @@
1058
1167
  const newUrl = updateQueryStringParameter(currentUrl, 'timestamp', Date.now());
1059
1168
  history.pushState({ path: newUrl }, '', newUrl);
1060
1169
  isPushState = true;
1061
- bffCollectEvent({
1062
- eventName: 'page_view',
1063
- eventSource: 'Google Analytics'
1064
- });
1065
1170
  }
1066
1171
  }
1067
1172
  else {
@@ -1071,31 +1176,17 @@
1071
1176
  if (!isPushState) {
1072
1177
  if (eventName === 'PageView' && typeof (window === null || window === void 0 ? void 0 : window.gtag) === 'function') {
1073
1178
  window === null || window === void 0 ? void 0 : window.gtag('event', 'page_view');
1074
- bffCollectEvent({
1075
- eventName: 'page_view',
1076
- eventSource: 'Google Analytics'
1077
- });
1078
1179
  }
1079
1180
  const tiktokPixelEventParamsJson = (_b = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.tiktokPixel) === null || _b === void 0 ? void 0 : _b[eventName];
1080
1181
  if ((tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name) &&
1081
1182
  typeof (window === null || window === void 0 ? void 0 : window.ttq) === 'object' &&
1082
1183
  typeof ((_c = window === null || window === void 0 ? void 0 : window.ttq) === null || _c === void 0 ? void 0 : _c.track) === 'function') {
1083
1184
  (_d = window === null || window === void 0 ? void 0 : window.ttq) === null || _d === void 0 ? void 0 : _d.track(tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name, getEventParamsByJson(tiktokPixelEventParamsJson, product));
1084
- bffCollectEvent({
1085
- eventName: tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name,
1086
- eventSource: 'TikTok Pixel',
1087
- eventInfo: getEventParamsByJson(tiktokPixelEventParamsJson, product)
1088
- });
1089
1185
  }
1090
1186
  }
1091
1187
  const snapchatPixelEventParamsJson = (_e = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.snapchatPixel) === null || _e === void 0 ? void 0 : _e[eventName];
1092
1188
  if ((snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name) && typeof (window === null || window === void 0 ? void 0 : window.snaptr) === 'function') {
1093
1189
  window === null || window === void 0 ? void 0 : window.snaptr('track', snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name, getEventParamsByJson(snapchatPixelEventParamsJson, product));
1094
- bffCollectEvent({
1095
- eventName: snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name,
1096
- eventSource: 'Snapchat Pixel',
1097
- eventInfo: getEventParamsByJson(snapchatPixelEventParamsJson, product)
1098
- });
1099
1190
  }
1100
1191
  const converApiEventParamsJson = (_f = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.converApi) === null || _f === void 0 ? void 0 : _f[eventName];
1101
1192
  if (enabledMetaConversionApi && converApiEventParamsJson) {