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.
@@ -134,8 +134,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
134
134
  var _a;
135
135
  const body = {
136
136
  eventName: params === null || params === void 0 ? void 0 : params.eventName,
137
- eventSource: params === null || params === void 0 ? void 0 : params.eventSource,
138
- eventInfo: (params === null || params === void 0 ? void 0 : params.eventInfo) ? JSON.stringify(params === null || params === void 0 ? void 0 : params.eventInfo) : ''
137
+ eventSource: params === null || params === void 0 ? void 0 : params.eventSource
139
138
  };
140
139
  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}`, {
141
140
  method: 'POST',
@@ -158,8 +157,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
158
157
  const params = Object.fromEntries(url.searchParams.entries());
159
158
  bffCollectEvent({
160
159
  eventName: params === null || params === void 0 ? void 0 : params.ev,
161
- eventSource: 'Meta Pixel',
162
- eventInfo: params
160
+ eventSource: 'Meta Pixel'
163
161
  });
164
162
  }
165
163
  };
@@ -172,6 +170,102 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
172
170
  };
173
171
  }
174
172
  }, [bffCollectEvent]);
173
+ useEffect(() => {
174
+ const navigatorWithBeacon = navigator;
175
+ if (!navigatorWithBeacon.sendBeacon) {
176
+ console.warn('navigator.sendBeacon is not supported');
177
+ return;
178
+ }
179
+ const originalSendBeacon = navigatorWithBeacon.sendBeacon.bind(navigatorWithBeacon);
180
+ navigatorWithBeacon.sendBeacon = function (url, data) {
181
+ const urlString = url instanceof URL ? url.href : url.toString();
182
+ const success = originalSendBeacon(url, data);
183
+ function parseBeaconData(data) {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ if (typeof data === 'string')
186
+ return JSON.parse(data);
187
+ if (data instanceof Blob)
188
+ return JSON.parse(yield data.text());
189
+ if (data instanceof ArrayBuffer)
190
+ return JSON.parse(new TextDecoder().decode(data));
191
+ return null;
192
+ });
193
+ }
194
+ if (success) {
195
+ Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () {
196
+ var _a, _b;
197
+ try {
198
+ const parsedData = yield parseBeaconData(data);
199
+ if (success) {
200
+ if (urlString.includes('https://tr.snapchat.com/p')) {
201
+ (_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) => {
202
+ var _a, _b;
203
+ if ((_a = item === null || item === void 0 ? void 0 : item.t) === null || _a === void 0 ? void 0 : _a.ev) {
204
+ bffCollectEvent({
205
+ eventName: (_b = item === null || item === void 0 ? void 0 : item.t) === null || _b === void 0 ? void 0 : _b.ev,
206
+ eventSource: 'Snapchat Pixel'
207
+ });
208
+ }
209
+ });
210
+ }
211
+ else if (urlString.includes('https://analytics.tiktok.com/api/v2/pixel') && (parsedData === null || parsedData === void 0 ? void 0 : parsedData.event)) {
212
+ bffCollectEvent({
213
+ eventName: parsedData.event,
214
+ eventSource: 'TikTok Pixel'
215
+ });
216
+ }
217
+ }
218
+ }
219
+ catch (error) {
220
+ console.error('监控失败:', error);
221
+ }
222
+ }));
223
+ }
224
+ return success;
225
+ };
226
+ return () => {
227
+ navigatorWithBeacon.sendBeacon = originalSendBeacon;
228
+ };
229
+ }, [bffCollectEvent]);
230
+ useEffect(() => {
231
+ const _originalFetch = window.fetch;
232
+ window.fetch = function (input, init) {
233
+ var arguments_1 = arguments;
234
+ return __awaiter(this, void 0, void 0, function* () {
235
+ let url;
236
+ try {
237
+ url = typeof input === 'string'
238
+ ? input
239
+ : input instanceof URL
240
+ ? input.href
241
+ : input.url;
242
+ }
243
+ catch (error) {
244
+ console.error('解析请求URL失败:', error);
245
+ return _originalFetch.apply(this, arguments_1);
246
+ }
247
+ if (!url.includes('https://www.google-analytics.com/g/collect')) {
248
+ return _originalFetch.apply(this, arguments_1);
249
+ }
250
+ try {
251
+ const response = yield _originalFetch.apply(this, arguments_1);
252
+ const urlObj = new URL(url);
253
+ const params = Object.fromEntries(urlObj.searchParams.entries());
254
+ if (params === null || params === void 0 ? void 0 : params.en) {
255
+ bffCollectEvent({
256
+ eventName: params === null || params === void 0 ? void 0 : params.en,
257
+ eventSource: 'Google Analytics'
258
+ });
259
+ }
260
+ return response;
261
+ }
262
+ catch (error) {
263
+ console.error('处理 GA4 请求时出错:', error);
264
+ throw error;
265
+ }
266
+ });
267
+ };
268
+ }, [bffCollectEvent]);
175
269
  useEffect(() => {
176
270
  if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
177
271
  window === null || window === void 0 ? void 0 : window.fbq('track', 'PageView');
@@ -425,10 +519,6 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
425
519
  const newUrl = updateQueryStringParameter(currentUrl, 'timestamp', Date.now());
426
520
  history.pushState({ path: newUrl }, '', newUrl);
427
521
  isPushState = true;
428
- bffCollectEvent({
429
- eventName: 'page_view',
430
- eventSource: 'Google Analytics'
431
- });
432
522
  }
433
523
  }
434
524
  else {
@@ -438,31 +528,17 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
438
528
  if (!isPushState) {
439
529
  if (eventName === 'PageView' && typeof (window === null || window === void 0 ? void 0 : window.gtag) === 'function') {
440
530
  window === null || window === void 0 ? void 0 : window.gtag('event', 'page_view');
441
- bffCollectEvent({
442
- eventName: 'page_view',
443
- eventSource: 'Google Analytics'
444
- });
445
531
  }
446
532
  const tiktokPixelEventParamsJson = (_b = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.tiktokPixel) === null || _b === void 0 ? void 0 : _b[eventName];
447
533
  if ((tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name) &&
448
534
  typeof (window === null || window === void 0 ? void 0 : window.ttq) === 'object' &&
449
535
  typeof ((_c = window === null || window === void 0 ? void 0 : window.ttq) === null || _c === void 0 ? void 0 : _c.track) === 'function') {
450
536
  (_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));
451
- bffCollectEvent({
452
- eventName: tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name,
453
- eventSource: 'TikTok Pixel',
454
- eventInfo: getEventParamsByJson(tiktokPixelEventParamsJson, product)
455
- });
456
537
  }
457
538
  }
458
539
  const snapchatPixelEventParamsJson = (_e = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.snapchatPixel) === null || _e === void 0 ? void 0 : _e[eventName];
459
540
  if ((snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name) && typeof (window === null || window === void 0 ? void 0 : window.snaptr) === 'function') {
460
541
  window === null || window === void 0 ? void 0 : window.snaptr('track', snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name, getEventParamsByJson(snapchatPixelEventParamsJson, product));
461
- bffCollectEvent({
462
- eventName: snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name,
463
- eventSource: 'Snapchat Pixel',
464
- eventInfo: getEventParamsByJson(snapchatPixelEventParamsJson, product)
465
- });
466
542
  }
467
543
  const converApiEventParamsJson = (_f = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.converApi) === null || _f === void 0 ? void 0 : _f[eventName];
468
544
  if (enabledMetaConversionApi && converApiEventParamsJson) {
@@ -137,8 +137,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
137
137
  var _a;
138
138
  const body = {
139
139
  eventName: params === null || params === void 0 ? void 0 : params.eventName,
140
- eventSource: params === null || params === void 0 ? void 0 : params.eventSource,
141
- eventInfo: (params === null || params === void 0 ? void 0 : params.eventInfo) ? JSON.stringify(params === null || params === void 0 ? void 0 : params.eventInfo) : ''
140
+ eventSource: params === null || params === void 0 ? void 0 : params.eventSource
142
141
  };
143
142
  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}`, {
144
143
  method: 'POST',
@@ -161,8 +160,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
161
160
  const params = Object.fromEntries(url.searchParams.entries());
162
161
  bffCollectEvent({
163
162
  eventName: params === null || params === void 0 ? void 0 : params.ev,
164
- eventSource: 'Meta Pixel',
165
- eventInfo: params
163
+ eventSource: 'Meta Pixel'
166
164
  });
167
165
  }
168
166
  };
@@ -175,6 +173,102 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
175
173
  };
176
174
  }
177
175
  }, [bffCollectEvent]);
176
+ (0, react_1.useEffect)(() => {
177
+ const navigatorWithBeacon = navigator;
178
+ if (!navigatorWithBeacon.sendBeacon) {
179
+ console.warn('navigator.sendBeacon is not supported');
180
+ return;
181
+ }
182
+ const originalSendBeacon = navigatorWithBeacon.sendBeacon.bind(navigatorWithBeacon);
183
+ navigatorWithBeacon.sendBeacon = function (url, data) {
184
+ const urlString = url instanceof URL ? url.href : url.toString();
185
+ const success = originalSendBeacon(url, data);
186
+ function parseBeaconData(data) {
187
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
188
+ if (typeof data === 'string')
189
+ return JSON.parse(data);
190
+ if (data instanceof Blob)
191
+ return JSON.parse(yield data.text());
192
+ if (data instanceof ArrayBuffer)
193
+ return JSON.parse(new TextDecoder().decode(data));
194
+ return null;
195
+ });
196
+ }
197
+ if (success) {
198
+ Promise.resolve().then(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
199
+ var _a, _b;
200
+ try {
201
+ const parsedData = yield parseBeaconData(data);
202
+ if (success) {
203
+ if (urlString.includes('https://tr.snapchat.com/p')) {
204
+ (_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) => {
205
+ var _a, _b;
206
+ if ((_a = item === null || item === void 0 ? void 0 : item.t) === null || _a === void 0 ? void 0 : _a.ev) {
207
+ bffCollectEvent({
208
+ eventName: (_b = item === null || item === void 0 ? void 0 : item.t) === null || _b === void 0 ? void 0 : _b.ev,
209
+ eventSource: 'Snapchat Pixel'
210
+ });
211
+ }
212
+ });
213
+ }
214
+ else if (urlString.includes('https://analytics.tiktok.com/api/v2/pixel') && (parsedData === null || parsedData === void 0 ? void 0 : parsedData.event)) {
215
+ bffCollectEvent({
216
+ eventName: parsedData.event,
217
+ eventSource: 'TikTok Pixel'
218
+ });
219
+ }
220
+ }
221
+ }
222
+ catch (error) {
223
+ console.error('监控失败:', error);
224
+ }
225
+ }));
226
+ }
227
+ return success;
228
+ };
229
+ return () => {
230
+ navigatorWithBeacon.sendBeacon = originalSendBeacon;
231
+ };
232
+ }, [bffCollectEvent]);
233
+ (0, react_1.useEffect)(() => {
234
+ const _originalFetch = window.fetch;
235
+ window.fetch = function (input, init) {
236
+ var arguments_1 = arguments;
237
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
238
+ let url;
239
+ try {
240
+ url = typeof input === 'string'
241
+ ? input
242
+ : input instanceof URL
243
+ ? input.href
244
+ : input.url;
245
+ }
246
+ catch (error) {
247
+ console.error('解析请求URL失败:', error);
248
+ return _originalFetch.apply(this, arguments_1);
249
+ }
250
+ if (!url.includes('https://www.google-analytics.com/g/collect')) {
251
+ return _originalFetch.apply(this, arguments_1);
252
+ }
253
+ try {
254
+ const response = yield _originalFetch.apply(this, arguments_1);
255
+ const urlObj = new URL(url);
256
+ const params = Object.fromEntries(urlObj.searchParams.entries());
257
+ if (params === null || params === void 0 ? void 0 : params.en) {
258
+ bffCollectEvent({
259
+ eventName: params === null || params === void 0 ? void 0 : params.en,
260
+ eventSource: 'Google Analytics'
261
+ });
262
+ }
263
+ return response;
264
+ }
265
+ catch (error) {
266
+ console.error('处理 GA4 请求时出错:', error);
267
+ throw error;
268
+ }
269
+ });
270
+ };
271
+ }, [bffCollectEvent]);
178
272
  (0, react_1.useEffect)(() => {
179
273
  if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
180
274
  window === null || window === void 0 ? void 0 : window.fbq('track', 'PageView');
@@ -428,10 +522,6 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
428
522
  const newUrl = updateQueryStringParameter(currentUrl, 'timestamp', Date.now());
429
523
  history.pushState({ path: newUrl }, '', newUrl);
430
524
  isPushState = true;
431
- bffCollectEvent({
432
- eventName: 'page_view',
433
- eventSource: 'Google Analytics'
434
- });
435
525
  }
436
526
  }
437
527
  else {
@@ -441,31 +531,17 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
441
531
  if (!isPushState) {
442
532
  if (eventName === 'PageView' && typeof (window === null || window === void 0 ? void 0 : window.gtag) === 'function') {
443
533
  window === null || window === void 0 ? void 0 : window.gtag('event', 'page_view');
444
- bffCollectEvent({
445
- eventName: 'page_view',
446
- eventSource: 'Google Analytics'
447
- });
448
534
  }
449
535
  const tiktokPixelEventParamsJson = (_b = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.tiktokPixel) === null || _b === void 0 ? void 0 : _b[eventName];
450
536
  if ((tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name) &&
451
537
  typeof (window === null || window === void 0 ? void 0 : window.ttq) === 'object' &&
452
538
  typeof ((_c = window === null || window === void 0 ? void 0 : window.ttq) === null || _c === void 0 ? void 0 : _c.track) === 'function') {
453
539
  (_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));
454
- bffCollectEvent({
455
- eventName: tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name,
456
- eventSource: 'TikTok Pixel',
457
- eventInfo: getEventParamsByJson(tiktokPixelEventParamsJson, product)
458
- });
459
540
  }
460
541
  }
461
542
  const snapchatPixelEventParamsJson = (_e = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.snapchatPixel) === null || _e === void 0 ? void 0 : _e[eventName];
462
543
  if ((snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name) && typeof (window === null || window === void 0 ? void 0 : window.snaptr) === 'function') {
463
544
  window === null || window === void 0 ? void 0 : window.snaptr('track', snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name, getEventParamsByJson(snapchatPixelEventParamsJson, product));
464
- bffCollectEvent({
465
- eventName: snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name,
466
- eventSource: 'Snapchat Pixel',
467
- eventInfo: getEventParamsByJson(snapchatPixelEventParamsJson, product)
468
- });
469
545
  }
470
546
  const converApiEventParamsJson = (_f = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.converApi) === null || _f === void 0 ? void 0 : _f[eventName];
471
547
  if (enabledMetaConversionApi && converApiEventParamsJson) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pb-sxp-ui",
3
- "version": "1.16.14",
3
+ "version": "1.16.15",
4
4
  "description": "React enterprise-class UI components",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",