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

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.
@@ -53,6 +53,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
53
53
  const [chatlabsId, setChatlabsId] = (0, react_1.useState)();
54
54
  const finalPageData = (0, react_1.useMemo)(() => pageData !== null && pageData !== void 0 ? pageData : data, [pageData, data]);
55
55
  const pixelPvStatusRef = (0, react_1.useRef)(false);
56
+ const fbcRef = (0, react_1.useRef)('');
56
57
  const isShowConsent = (0, react_1.useMemo)(() => {
57
58
  var _a, _b, _c, _d;
58
59
  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) &&
@@ -108,6 +109,53 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
108
109
  var _a;
109
110
  return ((_a = bffDataSource === null || bffDataSource === void 0 ? void 0 : bffDataSource.headers) === null || _a === void 0 ? void 0 : _a['x-app-id']) + (0, localStore_1.storeAndLoadFeUserId)();
110
111
  }, [bffDataSource]);
112
+ (0, react_1.useEffect)(() => {
113
+ if (!(globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enableCookieSetting))
114
+ return;
115
+ fbcRef.current = (0, tool_1.getCookie)('_fbc');
116
+ window.OptanonWrapper = function () {
117
+ const activeGroups = window === null || window === void 0 ? void 0 : window.OnetrustActiveGroups;
118
+ if (!activeGroups)
119
+ return;
120
+ if (!(activeGroups === null || activeGroups === void 0 ? void 0 : activeGroups.includes('4'))) {
121
+ (0, tool_1.deleteCookie)('_fbc');
122
+ }
123
+ else if (fbcRef.current) {
124
+ (0, tool_1.setCookie)('_fbc', fbcRef.current, 90);
125
+ }
126
+ };
127
+ }, [globalConfig]);
128
+ const isActiveTargetingCookie = (0, react_1.useMemo)(() => {
129
+ var _a;
130
+ function isTargetingRejected(cookieValue) {
131
+ const groupsMatch = cookieValue.match(/groups=([^&]+)/);
132
+ if (!groupsMatch || !groupsMatch[1]) {
133
+ return false;
134
+ }
135
+ const groupsString = groupsMatch[1];
136
+ const groupsPairs = groupsString.split(',');
137
+ for (const pair of groupsPairs) {
138
+ const [category, status] = pair.split(':');
139
+ if (category === '4') {
140
+ return status === '0';
141
+ }
142
+ }
143
+ return false;
144
+ }
145
+ function getCookie(name) {
146
+ var _a;
147
+ const value = `; ${document.cookie}`;
148
+ const parts = value.split(`; ${name}=`);
149
+ if (parts.length === 2)
150
+ return (_a = parts.pop()) === null || _a === void 0 ? void 0 : _a.split(';').shift();
151
+ return '';
152
+ }
153
+ const OptanonConsent = decodeURIComponent((_a = getCookie('OptanonConsent')) !== null && _a !== void 0 ? _a : '');
154
+ 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')))) {
155
+ return true;
156
+ }
157
+ return false;
158
+ }, [globalConfig]);
111
159
  const bffFetch = (0, react_1.useCallback)((path, options, isBota = true) => {
112
160
  var _a;
113
161
  if (!bffDataSource)
@@ -135,6 +183,8 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
135
183
  }, [bffDataSource, fakeUserId]);
136
184
  const bffCollectEvent = (0, react_1.useCallback)((params) => {
137
185
  var _a;
186
+ if (isActiveTargetingCookie)
187
+ return Promise.resolve();
138
188
  const body = {
139
189
  eventName: params === null || params === void 0 ? void 0 : params.eventName,
140
190
  eventSource: params === null || params === void 0 ? void 0 : params.eventSource
@@ -144,34 +194,35 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
144
194
  body,
145
195
  type: 'beacon'
146
196
  }, false);
147
- }, [bffFetch, bffDataSource]);
197
+ }, [bffFetch, bffDataSource, isActiveTargetingCookie]);
148
198
  (0, react_1.useEffect)(() => {
149
- if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
150
- const OriginalImage = window.Image;
151
- window.Image = function () {
152
- const img = new OriginalImage();
153
- const originalSrcDescriptor = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, 'src');
154
- Object.defineProperty(img, 'src', {
155
- set(value) {
156
- originalSrcDescriptor.set.call(this, value);
157
- if (value.includes('https://www.facebook.com/privacy_sandbox/pixel/register/trigger/')) {
158
- const url = new URL(value);
159
- const params = Object.fromEntries(url.searchParams.entries());
160
- bffCollectEvent({
161
- eventName: params === null || params === void 0 ? void 0 : params.ev,
162
- eventSource: 'Meta Pixel'
163
- });
164
- }
165
- ;
166
- },
167
- get() {
168
- return originalSrcDescriptor.get.call(this);
199
+ const OriginalImage = window.Image;
200
+ window.Image = function () {
201
+ const img = new OriginalImage();
202
+ const originalSrcDescriptor = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, 'src');
203
+ Object.defineProperty(img, 'src', {
204
+ set(value) {
205
+ if (isActiveTargetingCookie && (value.includes('https://www.facebook.com/privacy_sandbox/pixel/register/trigger/') || value.includes('https://www.facebook.com/tr'))) {
206
+ return;
169
207
  }
170
- });
171
- return img;
172
- };
173
- }
174
- }, [bffCollectEvent]);
208
+ originalSrcDescriptor.set.call(this, value);
209
+ if (value.includes('https://www.facebook.com/privacy_sandbox/pixel/register/trigger/')) {
210
+ const url = new URL(value);
211
+ const params = Object.fromEntries(url.searchParams.entries());
212
+ bffCollectEvent({
213
+ eventName: params === null || params === void 0 ? void 0 : params.ev,
214
+ eventSource: 'Meta Pixel'
215
+ });
216
+ }
217
+ ;
218
+ },
219
+ get() {
220
+ return originalSrcDescriptor.get.call(this);
221
+ }
222
+ });
223
+ return img;
224
+ };
225
+ }, [bffCollectEvent, isActiveTargetingCookie]);
175
226
  (0, react_1.useEffect)(() => {
176
227
  const navigatorWithBeacon = navigator;
177
228
  if (!navigatorWithBeacon.sendBeacon) {
@@ -181,6 +232,9 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
181
232
  const originalSendBeacon = navigatorWithBeacon.sendBeacon.bind(navigatorWithBeacon);
182
233
  navigatorWithBeacon.sendBeacon = function (url, data) {
183
234
  const urlString = url instanceof URL ? url.href : url.toString();
235
+ if (isActiveTargetingCookie && (urlString.includes('https://tr.snapchat.com/p') || urlString.includes('https://analytics.tiktok.com/api/v2/pixel'))) {
236
+ return true;
237
+ }
184
238
  const success = originalSendBeacon(url, data);
185
239
  function parseBeaconData(data) {
186
240
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -226,7 +280,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
226
280
  return () => {
227
281
  navigatorWithBeacon.sendBeacon = originalSendBeacon;
228
282
  };
229
- }, [bffCollectEvent]);
283
+ }, [bffCollectEvent, isActiveTargetingCookie]);
230
284
  (0, react_1.useEffect)(() => {
231
285
  const _originalFetch = window.fetch;
232
286
  window.fetch = function (input, init) {
@@ -246,6 +300,9 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
246
300
  return _originalFetch.apply(this, arguments_1);
247
301
  }
248
302
  try {
303
+ if (isActiveTargetingCookie && (url.includes('https://www.google-analytics.com/g/collect') || url.includes('https://arms-retcode.aliyuncs.com/r.png'))) {
304
+ return Promise.resolve(new Response(''));
305
+ }
249
306
  const response = _originalFetch.apply(this, arguments_1);
250
307
  if (url.includes('https://www.google-analytics.com/g/collect')) {
251
308
  const urlObj = new URL(url);
@@ -287,7 +344,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
287
344
  }
288
345
  });
289
346
  };
290
- }, [bffCollectEvent]);
347
+ }, [bffCollectEvent, isActiveTargetingCookie]);
291
348
  (0, react_1.useEffect)(() => {
292
349
  const originalOpen = XMLHttpRequest.prototype.open;
293
350
  const originalSend = XMLHttpRequest.prototype.send;
@@ -297,6 +354,9 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
297
354
  };
298
355
  XMLHttpRequest.prototype.send = function (body) {
299
356
  var _a;
357
+ 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'))) {
358
+ return;
359
+ }
300
360
  if (this._url && typeof this._url === 'string' && this._url.includes('https://i.giesswein.com/nb-collector')) {
301
361
  if (body && typeof body === 'string') {
302
362
  try {
@@ -322,7 +382,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
322
382
  XMLHttpRequest.prototype.open = originalOpen;
323
383
  XMLHttpRequest.prototype.send = originalSend;
324
384
  };
325
- }, [bffCollectEvent]);
385
+ }, [bffCollectEvent, isActiveTargetingCookie]);
326
386
  (0, react_1.useEffect)(() => {
327
387
  if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
328
388
  window === null || window === void 0 ? void 0 : window.fbq('track', 'PageView');
@@ -449,7 +509,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
449
509
  }, [data]);
450
510
  const bffEventReport = (0, react_1.useCallback)(({ userInfo, eventInfo, reportLayId = true }) => {
451
511
  var _a, _b;
452
- if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview)) {
512
+ if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) || isActiveTargetingCookie) {
453
513
  return;
454
514
  }
455
515
  if (!userInfo) {
@@ -486,7 +546,8 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
486
546
  layoutVariantId,
487
547
  globalConfig,
488
548
  playbookType,
489
- bffDataSource
549
+ bffDataSource,
550
+ isActiveTargetingCookie
490
551
  ]);
491
552
  const getEventParamsByJson = (0, react_1.useCallback)((json, product) => {
492
553
  var _a, _b, _c;
@@ -551,7 +612,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
551
612
  }, [fakeUserId]);
552
613
  const bffFbReport = (0, react_1.useCallback)(({ eventName, product }) => {
553
614
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
554
- if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview)) {
615
+ if (!enableReportEvent || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.enablePreview) || isActiveTargetingCookie) {
555
616
  return;
556
617
  }
557
618
  let isPushState = false;
@@ -617,7 +678,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
617
678
  type: 'beacon'
618
679
  });
619
680
  }
620
- }, [bffFetch, enableReportEvent, enabledMetaConversionApi, globalConfig, bffDataSource, getEventParamsByJson]);
681
+ }, [bffFetch, enableReportEvent, enabledMetaConversionApi, globalConfig, bffDataSource, getEventParamsByJson, isActiveTargetingCookie]);
621
682
  const bffMutateLike = (0, react_1.useCallback)((body) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
622
683
  const res = yield (bffFetch === null || bffFetch === void 0 ? void 0 : bffFetch('v1/recommend/like', { method: 'POST', body }));
623
684
  return res === null || res === void 0 ? void 0 : res.success;
@@ -13,4 +13,6 @@ declare function getDevice(): string | null;
13
13
  declare function getCookie(val: string): string;
14
14
  declare function getScreenReader(): boolean;
15
15
  declare function splitUrlParams(urlParams: string): string[] | undefined;
16
- export { uuid, getIndexByblockType, getBrowserInfo, getDevice, getSystem, getCookie, getScreenReader, splitUrlParams };
16
+ declare function deleteCookie(name: string, path?: string, domain?: string): void;
17
+ declare function setCookie(name: string, value: string, days?: number, path?: string, domain?: string, secure?: boolean, sameSite?: string): void;
18
+ export { uuid, getIndexByblockType, getBrowserInfo, getDevice, getSystem, getCookie, getScreenReader, splitUrlParams, deleteCookie, setCookie };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.splitUrlParams = exports.getScreenReader = exports.getCookie = exports.getSystem = exports.getDevice = exports.getBrowserInfo = exports.getIndexByblockType = exports.uuid = exports.setFontForText = exports.getUid = exports.generateRandomString = void 0;
3
+ exports.setCookie = exports.deleteCookie = exports.splitUrlParams = exports.getScreenReader = exports.getCookie = exports.getSystem = exports.getDevice = exports.getBrowserInfo = exports.getIndexByblockType = exports.uuid = exports.setFontForText = exports.getUid = exports.generateRandomString = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  function uuid(len, radix) {
6
6
  const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
@@ -205,3 +205,33 @@ function splitUrlParams(urlParams) {
205
205
  return splitList !== null && splitList !== void 0 ? splitList : [];
206
206
  }
207
207
  exports.splitUrlParams = splitUrlParams;
208
+ function deleteCookie(name, path = '/', domain = '') {
209
+ const expiration = 'expires=Thu, 01 Jan 1970 00:00:00 GMT';
210
+ const pathPart = path ? `; path=${path}` : '';
211
+ const domainPart = domain ? `; domain=${domain}` : '';
212
+ document.cookie = `${name}=; ${expiration}${pathPart}${domainPart}`;
213
+ console.log(`已尝试删除Cookie: ${name}`);
214
+ }
215
+ exports.deleteCookie = deleteCookie;
216
+ function setCookie(name, value, days = 0, path = '/', domain = '', secure = false, sameSite = 'Lax') {
217
+ let cookieString = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
218
+ if (days) {
219
+ const date = new Date();
220
+ date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
221
+ cookieString += `; expires=${date.toUTCString()}`;
222
+ }
223
+ if (path) {
224
+ cookieString += `; path=${path}`;
225
+ }
226
+ if (domain) {
227
+ cookieString += `; domain=${domain}`;
228
+ }
229
+ if (secure) {
230
+ cookieString += '; secure';
231
+ }
232
+ if (sameSite) {
233
+ cookieString += `; samesite=${sameSite}`;
234
+ }
235
+ document.cookie = cookieString;
236
+ }
237
+ exports.setCookie = setCookie;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pb-sxp-ui",
3
- "version": "1.18.2",
3
+ "version": "1.19.0-alpha.1",
4
4
  "description": "React enterprise-class UI components",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",