pb-sxp-ui 1.16.12 → 1.16.14

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/index.cjs CHANGED
@@ -736,7 +736,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
736
736
  return ((_a = bffDataSource === null || bffDataSource === void 0 ? void 0 : bffDataSource.headers) === null || _a === void 0 ? void 0 : _a['x-app-id']) + storeAndLoadFeUserId();
737
737
  }, [bffDataSource]);
738
738
  // bff API 请求方法
739
- const bffFetch = React.useCallback((path, options) => {
739
+ const bffFetch = React.useCallback((path, options, isBota = true) => {
740
740
  var _a;
741
741
  if (!bffDataSource)
742
742
  return;
@@ -751,7 +751,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
751
751
  val.split('=')[1];
752
752
  });
753
753
  return window
754
- .fetch(`${url}/api/${path}`, Object.assign({ headers: Object.assign({ 'Content-Type': 'application/json', 'x-user-id': fakeUserId }, bffDataSource.headers), method: options.method, body: options.type === 'beacon'
754
+ .fetch(`${url}/api/${path}`, Object.assign({ headers: Object.assign({ 'Content-Type': 'application/json', 'x-user-id': fakeUserId }, bffDataSource.headers), method: options.method, body: options.type === 'beacon' && isBota
755
755
  ? JSON.stringify({
756
756
  body: btoa(encodeURIComponent(JSON.stringify(Object.assign(Object.assign(Object.assign({}, options.body), bffDataSource.headers), { 'x-user-id': fakeUserId }))))
757
757
  })
@@ -759,6 +759,57 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
759
759
  .then((res) => res.json())
760
760
  .catch((err) => Promise.reject(err));
761
761
  }, [bffDataSource, fakeUserId]);
762
+ const bffCollectEvent = React.useCallback((params) => {
763
+ var _a;
764
+ const body = {
765
+ eventName: params === null || params === void 0 ? void 0 : params.eventName,
766
+ eventSource: params === null || params === void 0 ? void 0 : params.eventSource,
767
+ eventInfo: (params === null || params === void 0 ? void 0 : params.eventInfo) ? JSON.stringify(params === null || params === void 0 ? void 0 : params.eventInfo) : ''
768
+ };
769
+ 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}`, {
770
+ method: 'POST',
771
+ body,
772
+ type: 'beacon'
773
+ }, false);
774
+ }, [bffFetch, bffDataSource]);
775
+ React.useEffect(() => {
776
+ if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
777
+ const OriginalImage = window.Image;
778
+ window.Image = function () {
779
+ const img = new OriginalImage();
780
+ // 劫持 src 的 setter
781
+ const originalSrcDescriptor = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, 'src');
782
+ Object.defineProperty(img, 'src', {
783
+ set(value) {
784
+ // 继续正常设置 src
785
+ originalSrcDescriptor.set.call(this, value);
786
+ img.onload = function () {
787
+ // 检查是否是目标 URL
788
+ if (value.includes('https://www.facebook.com/privacy_sandbox/pixel/register/trigger/')) {
789
+ // 解析 URL 参数
790
+ const url = new URL(value);
791
+ const params = Object.fromEntries(url.searchParams.entries());
792
+ bffCollectEvent({
793
+ eventName: params === null || params === void 0 ? void 0 : params.ev,
794
+ eventSource: 'Meta Pixel',
795
+ eventInfo: params
796
+ });
797
+ }
798
+ };
799
+ },
800
+ get() {
801
+ return originalSrcDescriptor.get.call(this);
802
+ }
803
+ });
804
+ return img;
805
+ };
806
+ }
807
+ }, [bffCollectEvent]);
808
+ React.useEffect(() => {
809
+ if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
810
+ window === null || window === void 0 ? void 0 : window.fbq('track', 'PageView');
811
+ }
812
+ }, []);
762
813
  // bff API admin 请求方法
763
814
  const bffFetchAdmin = React.useCallback((path, options) => {
764
815
  if (!bffDataSource)
@@ -1014,6 +1065,10 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
1014
1065
  const newUrl = updateQueryStringParameter(currentUrl, 'timestamp', Date.now());
1015
1066
  history.pushState({ path: newUrl }, '', newUrl);
1016
1067
  isPushState = true;
1068
+ bffCollectEvent({
1069
+ eventName: 'page_view',
1070
+ eventSource: 'Google Analytics'
1071
+ });
1017
1072
  }
1018
1073
  }
1019
1074
  else {
@@ -1023,17 +1078,31 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
1023
1078
  if (!isPushState) {
1024
1079
  if (eventName === 'PageView' && typeof (window === null || window === void 0 ? void 0 : window.gtag) === 'function') {
1025
1080
  window === null || window === void 0 ? void 0 : window.gtag('event', 'page_view');
1081
+ bffCollectEvent({
1082
+ eventName: 'page_view',
1083
+ eventSource: 'Google Analytics'
1084
+ });
1026
1085
  }
1027
1086
  const tiktokPixelEventParamsJson = (_b = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.tiktokPixel) === null || _b === void 0 ? void 0 : _b[eventName];
1028
1087
  if ((tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name) &&
1029
1088
  typeof (window === null || window === void 0 ? void 0 : window.ttq) === 'object' &&
1030
1089
  typeof ((_c = window === null || window === void 0 ? void 0 : window.ttq) === null || _c === void 0 ? void 0 : _c.track) === 'function') {
1031
1090
  (_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));
1091
+ bffCollectEvent({
1092
+ eventName: tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name,
1093
+ eventSource: 'TikTok Pixel',
1094
+ eventInfo: getEventParamsByJson(tiktokPixelEventParamsJson, product)
1095
+ });
1032
1096
  }
1033
1097
  }
1034
1098
  const snapchatPixelEventParamsJson = (_e = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.snapchatPixel) === null || _e === void 0 ? void 0 : _e[eventName];
1035
1099
  if ((snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name) && typeof (window === null || window === void 0 ? void 0 : window.snaptr) === 'function') {
1036
1100
  window === null || window === void 0 ? void 0 : window.snaptr('track', snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name, getEventParamsByJson(snapchatPixelEventParamsJson, product));
1101
+ bffCollectEvent({
1102
+ eventName: snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name,
1103
+ eventSource: 'Snapchat Pixel',
1104
+ eventInfo: getEventParamsByJson(snapchatPixelEventParamsJson, product)
1105
+ });
1037
1106
  }
1038
1107
  const converApiEventParamsJson = (_f = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.converApi) === null || _f === void 0 ? void 0 : _f[eventName];
1039
1108
  if (enabledMetaConversionApi && converApiEventParamsJson) {