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.js CHANGED
@@ -714,7 +714,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
714
714
  return ((_a = bffDataSource === null || bffDataSource === void 0 ? void 0 : bffDataSource.headers) === null || _a === void 0 ? void 0 : _a['x-app-id']) + storeAndLoadFeUserId();
715
715
  }, [bffDataSource]);
716
716
  // bff API 请求方法
717
- const bffFetch = useCallback((path, options) => {
717
+ const bffFetch = useCallback((path, options, isBota = true) => {
718
718
  var _a;
719
719
  if (!bffDataSource)
720
720
  return;
@@ -729,7 +729,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
729
729
  val.split('=')[1];
730
730
  });
731
731
  return window
732
- .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'
732
+ .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
733
733
  ? JSON.stringify({
734
734
  body: btoa(encodeURIComponent(JSON.stringify(Object.assign(Object.assign(Object.assign({}, options.body), bffDataSource.headers), { 'x-user-id': fakeUserId }))))
735
735
  })
@@ -737,6 +737,57 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
737
737
  .then((res) => res.json())
738
738
  .catch((err) => Promise.reject(err));
739
739
  }, [bffDataSource, fakeUserId]);
740
+ const bffCollectEvent = useCallback((params) => {
741
+ var _a;
742
+ const body = {
743
+ eventName: params === null || params === void 0 ? void 0 : params.eventName,
744
+ eventSource: params === null || params === void 0 ? void 0 : params.eventSource,
745
+ eventInfo: (params === null || params === void 0 ? void 0 : params.eventInfo) ? JSON.stringify(params === null || params === void 0 ? void 0 : params.eventInfo) : ''
746
+ };
747
+ 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}`, {
748
+ method: 'POST',
749
+ body,
750
+ type: 'beacon'
751
+ }, false);
752
+ }, [bffFetch, bffDataSource]);
753
+ useEffect(() => {
754
+ if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
755
+ const OriginalImage = window.Image;
756
+ window.Image = function () {
757
+ const img = new OriginalImage();
758
+ // 劫持 src 的 setter
759
+ const originalSrcDescriptor = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, 'src');
760
+ Object.defineProperty(img, 'src', {
761
+ set(value) {
762
+ // 继续正常设置 src
763
+ originalSrcDescriptor.set.call(this, value);
764
+ img.onload = function () {
765
+ // 检查是否是目标 URL
766
+ if (value.includes('https://www.facebook.com/privacy_sandbox/pixel/register/trigger/')) {
767
+ // 解析 URL 参数
768
+ const url = new URL(value);
769
+ const params = Object.fromEntries(url.searchParams.entries());
770
+ bffCollectEvent({
771
+ eventName: params === null || params === void 0 ? void 0 : params.ev,
772
+ eventSource: 'Meta Pixel',
773
+ eventInfo: params
774
+ });
775
+ }
776
+ };
777
+ },
778
+ get() {
779
+ return originalSrcDescriptor.get.call(this);
780
+ }
781
+ });
782
+ return img;
783
+ };
784
+ }
785
+ }, [bffCollectEvent]);
786
+ useEffect(() => {
787
+ if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
788
+ window === null || window === void 0 ? void 0 : window.fbq('track', 'PageView');
789
+ }
790
+ }, []);
740
791
  // bff API admin 请求方法
741
792
  const bffFetchAdmin = useCallback((path, options) => {
742
793
  if (!bffDataSource)
@@ -992,6 +1043,10 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
992
1043
  const newUrl = updateQueryStringParameter(currentUrl, 'timestamp', Date.now());
993
1044
  history.pushState({ path: newUrl }, '', newUrl);
994
1045
  isPushState = true;
1046
+ bffCollectEvent({
1047
+ eventName: 'page_view',
1048
+ eventSource: 'Google Analytics'
1049
+ });
995
1050
  }
996
1051
  }
997
1052
  else {
@@ -1001,17 +1056,31 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
1001
1056
  if (!isPushState) {
1002
1057
  if (eventName === 'PageView' && typeof (window === null || window === void 0 ? void 0 : window.gtag) === 'function') {
1003
1058
  window === null || window === void 0 ? void 0 : window.gtag('event', 'page_view');
1059
+ bffCollectEvent({
1060
+ eventName: 'page_view',
1061
+ eventSource: 'Google Analytics'
1062
+ });
1004
1063
  }
1005
1064
  const tiktokPixelEventParamsJson = (_b = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.tiktokPixel) === null || _b === void 0 ? void 0 : _b[eventName];
1006
1065
  if ((tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name) &&
1007
1066
  typeof (window === null || window === void 0 ? void 0 : window.ttq) === 'object' &&
1008
1067
  typeof ((_c = window === null || window === void 0 ? void 0 : window.ttq) === null || _c === void 0 ? void 0 : _c.track) === 'function') {
1009
1068
  (_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));
1069
+ bffCollectEvent({
1070
+ eventName: tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name,
1071
+ eventSource: 'TikTok Pixel',
1072
+ eventInfo: getEventParamsByJson(tiktokPixelEventParamsJson, product)
1073
+ });
1010
1074
  }
1011
1075
  }
1012
1076
  const snapchatPixelEventParamsJson = (_e = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.snapchatPixel) === null || _e === void 0 ? void 0 : _e[eventName];
1013
1077
  if ((snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name) && typeof (window === null || window === void 0 ? void 0 : window.snaptr) === 'function') {
1014
1078
  window === null || window === void 0 ? void 0 : window.snaptr('track', snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name, getEventParamsByJson(snapchatPixelEventParamsJson, product));
1079
+ bffCollectEvent({
1080
+ eventName: snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name,
1081
+ eventSource: 'Snapchat Pixel',
1082
+ eventInfo: getEventParamsByJson(snapchatPixelEventParamsJson, product)
1083
+ });
1015
1084
  }
1016
1085
  const converApiEventParamsJson = (_f = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.converApi) === null || _f === void 0 ? void 0 : _f[eventName];
1017
1086
  if (enabledMetaConversionApi && converApiEventParamsJson) {