pb-sxp-ui 1.19.0-alpha.1 → 1.19.0-alpha.3

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
@@ -689,7 +689,6 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
689
689
  const [chatlabsId, setChatlabsId] = useState();
690
690
  const finalPageData = useMemo(() => pageData !== null && pageData !== void 0 ? pageData : data, [pageData, data]);
691
691
  const pixelPvStatusRef = useRef(false);
692
- const fbcRef = useRef('');
693
692
  const isShowConsent = useMemo(() => {
694
693
  var _a, _b, _c, _d;
695
694
  return (((((_d = (_c = (_b = (_a = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.consent) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.item) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.privacy_necessity) && !isAgreePolicy && !isEditor) || isOpenConsent) &&
@@ -750,23 +749,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
750
749
  var _a;
751
750
  return ((_a = bffDataSource === null || bffDataSource === void 0 ? void 0 : bffDataSource.headers) === null || _a === void 0 ? void 0 : _a['x-app-id']) + storeAndLoadFeUserId();
752
751
  }, [bffDataSource]);
753
- useEffect(() => {
754
- if (!(globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enableCookieSetting))
755
- return;
756
- fbcRef.current = getCookie('_fbc');
757
- window.OptanonWrapper = function () {
758
- const activeGroups = window === null || window === void 0 ? void 0 : window.OnetrustActiveGroups;
759
- if (!activeGroups)
760
- return;
761
- if (!(activeGroups === null || activeGroups === void 0 ? void 0 : activeGroups.includes('4'))) {
762
- deleteCookie('_fbc');
763
- }
764
- else if (fbcRef.current) {
765
- setCookie('_fbc', fbcRef.current, 90);
766
- }
767
- };
768
- }, [globalConfig]);
769
- const isActiveTargetingCookie = useMemo(() => {
752
+ const getTargetingCookie = () => {
770
753
  var _a;
771
754
  function getCookie(name) {
772
755
  var _a;
@@ -777,11 +760,12 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
777
760
  return '';
778
761
  }
779
762
  decodeURIComponent((_a = getCookie('OptanonConsent')) !== null && _a !== void 0 ? _a : '');
780
- if (((globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enableCookieSetting) && (window === null || window === void 0 ? void 0 : window.OnetrustActiveGroups) && !(window === null || window === void 0 ? void 0 : window.OnetrustActiveGroups.includes('4')))) {
763
+ console.log('OptanonConsent:', window === null || window === void 0 ? void 0 : window.OnetrustActiveGroups);
764
+ if (((window === null || window === void 0 ? void 0 : window.OnetrustActiveGroups) && !(window === null || window === void 0 ? void 0 : window.OnetrustActiveGroups.includes('4')))) {
781
765
  return true;
782
766
  }
783
767
  return false;
784
- }, [globalConfig]);
768
+ };
785
769
  // bff API 请求方法
786
770
  const bffFetch = useCallback((path, options, isBota = true) => {
787
771
  var _a;
@@ -808,7 +792,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
808
792
  }, [bffDataSource, fakeUserId]);
809
793
  const bffCollectEvent = useCallback((params) => {
810
794
  var _a;
811
- if (isActiveTargetingCookie)
795
+ if (getTargetingCookie())
812
796
  return Promise.resolve();
813
797
  const body = {
814
798
  eventName: params === null || params === void 0 ? void 0 : params.eventName,
@@ -820,7 +804,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
820
804
  body,
821
805
  type: 'beacon'
822
806
  }, false);
823
- }, [bffFetch, bffDataSource, isActiveTargetingCookie]);
807
+ }, [bffFetch, bffDataSource]);
824
808
  useEffect(() => {
825
809
  // if (typeof (window as any)?.fbq === 'function') {
826
810
  const OriginalImage = window.Image;
@@ -830,7 +814,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
830
814
  const originalSrcDescriptor = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, 'src');
831
815
  Object.defineProperty(img, 'src', {
832
816
  set(value) {
833
- if (isActiveTargetingCookie && (value.includes('https://www.facebook.com/privacy_sandbox/pixel/register/trigger/') || value.includes('https://www.facebook.com/tr'))) {
817
+ if (getTargetingCookie() && (value.includes('https://www.facebook.com/privacy_sandbox/pixel/register/trigger/') || value.includes('https://www.facebook.com/tr'))) {
834
818
  return;
835
819
  }
836
820
  // 继续正常设置 src
@@ -855,7 +839,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
855
839
  return img;
856
840
  };
857
841
  // }
858
- }, [bffCollectEvent, isActiveTargetingCookie]);
842
+ }, [bffCollectEvent]);
859
843
  useEffect(() => {
860
844
  // 类型安全声明
861
845
  const navigatorWithBeacon = navigator;
@@ -868,7 +852,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
868
852
  // 覆盖方法
869
853
  navigatorWithBeacon.sendBeacon = function (url, data) {
870
854
  const urlString = url instanceof URL ? url.href : url.toString();
871
- if (isActiveTargetingCookie && (urlString.includes('https://tr.snapchat.com/p') || urlString.includes('https://analytics.tiktok.com/api/v2/pixel'))) {
855
+ if (getTargetingCookie() && (urlString.includes('https://tr.snapchat.com/p') || urlString.includes('https://analytics.tiktok.com/api/v2/pixel'))) {
872
856
  return true;
873
857
  }
874
858
  const success = originalSendBeacon(url, data);
@@ -920,7 +904,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
920
904
  return () => {
921
905
  navigatorWithBeacon.sendBeacon = originalSendBeacon;
922
906
  };
923
- }, [bffCollectEvent, isActiveTargetingCookie]);
907
+ }, [bffCollectEvent]);
924
908
  useEffect(() => {
925
909
  const _originalFetch = window.fetch;
926
910
  // 覆盖 fetch 方法
@@ -942,7 +926,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
942
926
  return _originalFetch.apply(this, arguments_1);
943
927
  }
944
928
  try {
945
- if (isActiveTargetingCookie && (url.includes('https://www.google-analytics.com/g/collect') || url.includes('https://arms-retcode.aliyuncs.com/r.png'))) {
929
+ if (getTargetingCookie() && (url.includes('https://www.google-analytics.com/g/collect') || url.includes('https://arms-retcode.aliyuncs.com/r.png'))) {
946
930
  return Promise.resolve(new Response(''));
947
931
  }
948
932
  // 1. 先执行原始请求
@@ -988,7 +972,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
988
972
  }
989
973
  });
990
974
  };
991
- }, [bffCollectEvent, isActiveTargetingCookie]);
975
+ }, [bffCollectEvent]);
992
976
  useEffect(() => {
993
977
  const originalOpen = XMLHttpRequest.prototype.open;
994
978
  const originalSend = XMLHttpRequest.prototype.send;
@@ -998,7 +982,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
998
982
  };
999
983
  XMLHttpRequest.prototype.send = function (body) {
1000
984
  var _a;
1001
- if (isActiveTargetingCookie && this._url && typeof this._url === 'string' && (this._url.includes('https://rumcollector.uptime.com') || this._url.includes('https://arms-retcode.aliyuncs.com/r.png') || this._url.includes('https://i.giesswein.com/nb-collector'))) {
985
+ if (getTargetingCookie() && this._url && typeof this._url === 'string' && (this._url.includes('https://rumcollector.uptime.com') || this._url.includes('https://arms-retcode.aliyuncs.com/r.png') || this._url.includes('https://i.giesswein.com/nb-collector'))) {
1002
986
  return;
1003
987
  }
1004
988
  if (this._url && typeof this._url === 'string' && this._url.includes('https://i.giesswein.com/nb-collector')) {
@@ -1026,7 +1010,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
1026
1010
  XMLHttpRequest.prototype.open = originalOpen;
1027
1011
  XMLHttpRequest.prototype.send = originalSend;
1028
1012
  };
1029
- }, [bffCollectEvent, isActiveTargetingCookie]);
1013
+ }, [bffCollectEvent]);
1030
1014
  useEffect(() => {
1031
1015
  if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
1032
1016
  window === null || window === void 0 ? void 0 : window.fbq('track', 'PageView');
@@ -1153,10 +1137,10 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
1153
1137
  }
1154
1138
  return expire;
1155
1139
  }, [data]);
1156
- const bffEventReport = useCallback(({ userInfo, eventInfo, reportLayId = true }) => {
1140
+ const bffEventReport = useCallback(({ userInfo, eventInfo, reportLayId = true, isActiveTargetingCookie = true }) => {
1157
1141
  var _a, _b;
1158
1142
  // 关闭 BFF 事件上报
1159
- if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) || isActiveTargetingCookie) {
1143
+ if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) || (isActiveTargetingCookie && getTargetingCookie())) {
1160
1144
  return;
1161
1145
  }
1162
1146
  // 用户信息都是公共的
@@ -1197,8 +1181,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
1197
1181
  layoutVariantId,
1198
1182
  globalConfig,
1199
1183
  playbookType,
1200
- bffDataSource,
1201
- isActiveTargetingCookie
1184
+ bffDataSource
1202
1185
  ]);
1203
1186
  const getEventParamsByJson = useCallback((json, product) => {
1204
1187
  var _a, _b, _c;
@@ -1263,7 +1246,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
1263
1246
  }, [fakeUserId]);
1264
1247
  const bffFbReport = useCallback(({ eventName, product }) => {
1265
1248
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1266
- if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) || isActiveTargetingCookie) {
1249
+ if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) || getTargetingCookie()) {
1267
1250
  return;
1268
1251
  }
1269
1252
  let isPushState = false;
@@ -1329,7 +1312,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
1329
1312
  type: 'beacon'
1330
1313
  });
1331
1314
  }
1332
- }, [bffFetch, enableReportEvent, enabledMetaConversionApi, globalConfig, bffDataSource, getEventParamsByJson, isActiveTargetingCookie]);
1315
+ }, [bffFetch, enableReportEvent, enabledMetaConversionApi, globalConfig, bffDataSource, getEventParamsByJson]);
1333
1316
  const bffMutateLike = useCallback((body) => __awaiter(void 0, void 0, void 0, function* () {
1334
1317
  const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/like', { method: 'POST', body }));
1335
1318
  return res === null || res === void 0 ? void 0 : res.success;
@@ -19020,6 +19003,7 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
19020
19003
  const skipLinkRef = useRef(false);
19021
19004
  const [pageNum, setPageNum] = useState(2);
19022
19005
  const videoWidgetRef = useRef(null);
19006
+ const fbcRef = useRef('');
19023
19007
  const { loadVideos, bffEventReport, loading, setPopupDetailData, ctaEvent, swiperRef, waterFallData, setOpenHashtag, appDomain, openHashtag, loadingImage, isFromHashtag, popupDetailData, bffFbReport, curTime, h5EnterLink, isShowConsent, selectTag, isPreview, isEditor, cacheRtcList, setRtcList, cacheActiveIndex, rtcList, isNoMoreData, channel, refreshFeSession, isDiyH5 } = useSxpDataSource();
19024
19008
  const { backMainFeed, productView, jumpToWeb } = useEventReport();
19025
19009
  const isShowFingerTip = useMemo(() => {
@@ -19463,6 +19447,35 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
19463
19447
  viewTime.current = new Date();
19464
19448
  }
19465
19449
  }, [openHashtag, data, activeIndex]);
19450
+ useEffect(() => {
19451
+ if (!(globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enableCookieSetting))
19452
+ return;
19453
+ window.OptanonWrapper = function () {
19454
+ var _a, _b;
19455
+ const activeGroups = window === null || window === void 0 ? void 0 : window.OnetrustActiveGroups;
19456
+ if (!activeGroups)
19457
+ return;
19458
+ if (activeGroups === null || activeGroups === void 0 ? void 0 : activeGroups.includes('4')) {
19459
+ if (fbcRef.current) {
19460
+ setCookie('_fbc', fbcRef.current, 90);
19461
+ }
19462
+ }
19463
+ else {
19464
+ fbcRef.current = getCookie('_fbc');
19465
+ deleteCookie('_fbc');
19466
+ const item = data[activeIndex];
19467
+ const traceInfo = ((_a = item === null || item === void 0 ? void 0 : item.video) === null || _a === void 0 ? void 0 : _a.traceInfo) || ((_b = item === null || item === void 0 ? void 0 : item.product) === null || _b === void 0 ? void 0 : _b.traceInfo) || '';
19468
+ bffEventReport === null || bffEventReport === void 0 ? void 0 : bffEventReport({
19469
+ eventInfo: {
19470
+ eventSubject: 'refuseCookie',
19471
+ eventDescription: 'refuseCookie',
19472
+ traceInfo
19473
+ },
19474
+ isActiveTargetingCookie: false
19475
+ });
19476
+ }
19477
+ };
19478
+ }, [globalConfig, bffEventReport, data, activeIndex]);
19466
19479
  const handleViewImageStartEvent = (activeIndex, imgInfo, enableCapi) => {
19467
19480
  var _a, _b, _c, _d, _e, _f, _g, _h;
19468
19481
  const item = data[activeIndex];