pb-sxp-ui 1.16.14 → 1.16.16
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 +145 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +145 -33
- package/dist/index.js.map +1 -1
- package/dist/index.min.cjs +4 -4
- package/dist/index.min.cjs.map +1 -1
- package/dist/index.min.js +4 -4
- package/dist/index.min.js.map +1 -1
- package/dist/pb-ui.js +145 -33
- package/dist/pb-ui.js.map +1 -1
- package/dist/pb-ui.min.js +4 -4
- package/dist/pb-ui.min.js.map +1 -1
- package/es/core/context/SxpDataSourceProvider.js +127 -31
- package/lib/core/context/SxpDataSourceProvider.js +127 -31
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -763,8 +763,8 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
763
763
|
var _a;
|
764
764
|
const body = {
|
765
765
|
eventName: params === null || params === void 0 ? void 0 : params.eventName,
|
766
|
-
eventSource: params === null || params === void 0 ? void 0 : params.eventSource
|
767
|
-
eventInfo:
|
766
|
+
eventSource: params === null || params === void 0 ? void 0 : params.eventSource
|
767
|
+
// eventInfo: params?.eventInfo ? JSON.stringify(params?.eventInfo) : ''
|
768
768
|
};
|
769
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
770
|
method: 'POST',
|
@@ -783,19 +783,18 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
783
783
|
set(value) {
|
784
784
|
// 继续正常设置 src
|
785
785
|
originalSrcDescriptor.set.call(this, value);
|
786
|
-
img.onload = function () {
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
};
|
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
|
+
});
|
796
|
+
// }
|
797
|
+
}
|
799
798
|
},
|
800
799
|
get() {
|
801
800
|
return originalSrcDescriptor.get.call(this);
|
@@ -805,6 +804,137 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
805
804
|
};
|
806
805
|
}
|
807
806
|
}, [bffCollectEvent]);
|
807
|
+
React.useEffect(() => {
|
808
|
+
// 类型安全声明
|
809
|
+
const navigatorWithBeacon = navigator;
|
810
|
+
if (!navigatorWithBeacon.sendBeacon) {
|
811
|
+
console.warn('navigator.sendBeacon is not supported');
|
812
|
+
return;
|
813
|
+
}
|
814
|
+
// 保存原始方法
|
815
|
+
const originalSendBeacon = navigatorWithBeacon.sendBeacon.bind(navigatorWithBeacon);
|
816
|
+
// 覆盖方法
|
817
|
+
navigatorWithBeacon.sendBeacon = function (url, data) {
|
818
|
+
const urlString = url instanceof URL ? url.href : url.toString();
|
819
|
+
const success = originalSendBeacon(url, data);
|
820
|
+
function parseBeaconData(data) {
|
821
|
+
return __awaiter(this, void 0, void 0, function* () {
|
822
|
+
if (typeof data === 'string')
|
823
|
+
return JSON.parse(data);
|
824
|
+
if (data instanceof Blob)
|
825
|
+
return JSON.parse(yield data.text());
|
826
|
+
if (data instanceof ArrayBuffer)
|
827
|
+
return JSON.parse(new TextDecoder().decode(data));
|
828
|
+
return null;
|
829
|
+
});
|
830
|
+
}
|
831
|
+
if (success) {
|
832
|
+
// 异步处理监控逻辑(不阻塞原始行为)
|
833
|
+
Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () {
|
834
|
+
var _a, _b;
|
835
|
+
try {
|
836
|
+
const parsedData = yield parseBeaconData(data);
|
837
|
+
// 使用你的自定义上报方法
|
838
|
+
if (urlString.includes('https://tr.snapchat.com/p')) {
|
839
|
+
(_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) => {
|
840
|
+
var _a, _b;
|
841
|
+
if ((_a = item === null || item === void 0 ? void 0 : item.t) === null || _a === void 0 ? void 0 : _a.ev) {
|
842
|
+
bffCollectEvent({
|
843
|
+
eventName: (_b = item === null || item === void 0 ? void 0 : item.t) === null || _b === void 0 ? void 0 : _b.ev,
|
844
|
+
eventSource: 'Snapchat Pixel'
|
845
|
+
});
|
846
|
+
}
|
847
|
+
});
|
848
|
+
}
|
849
|
+
else if (urlString.includes('https://analytics.tiktok.com/api/v2/pixel') && (parsedData === null || parsedData === void 0 ? void 0 : parsedData.event)) {
|
850
|
+
bffCollectEvent({
|
851
|
+
eventName: parsedData.event,
|
852
|
+
eventSource: 'TikTok Pixel'
|
853
|
+
});
|
854
|
+
}
|
855
|
+
}
|
856
|
+
catch (error) {
|
857
|
+
console.error('监控失败:', error);
|
858
|
+
}
|
859
|
+
}));
|
860
|
+
}
|
861
|
+
// 非TikTok请求直接放行
|
862
|
+
return success;
|
863
|
+
};
|
864
|
+
// 清理函数:恢复原始方法
|
865
|
+
return () => {
|
866
|
+
navigatorWithBeacon.sendBeacon = originalSendBeacon;
|
867
|
+
};
|
868
|
+
}, [bffCollectEvent]);
|
869
|
+
React.useEffect(() => {
|
870
|
+
const _originalFetch = window.fetch;
|
871
|
+
// 覆盖 fetch 方法
|
872
|
+
window.fetch = function (input, init) {
|
873
|
+
var arguments_1 = arguments;
|
874
|
+
return __awaiter(this, void 0, void 0, function* () {
|
875
|
+
var _a;
|
876
|
+
// 安全获取 URL 字符串
|
877
|
+
let url;
|
878
|
+
try {
|
879
|
+
url = typeof input === 'string'
|
880
|
+
? input
|
881
|
+
: input instanceof URL
|
882
|
+
? input.href
|
883
|
+
: input.url;
|
884
|
+
}
|
885
|
+
catch (error) {
|
886
|
+
console.error('解析请求URL失败:', error);
|
887
|
+
return _originalFetch.apply(this, arguments_1);
|
888
|
+
}
|
889
|
+
// 非GA4请求直接放行
|
890
|
+
if (!url.includes('https://www.google-analytics.com/g/collect')) {
|
891
|
+
return _originalFetch.apply(this, arguments_1);
|
892
|
+
}
|
893
|
+
// 检查是否是 GA4 收集端点
|
894
|
+
try {
|
895
|
+
// 1. 先执行原始请求
|
896
|
+
const response = _originalFetch.apply(this, arguments_1);
|
897
|
+
// 2. 检查请求是否成功 (HTTP 200-299)
|
898
|
+
// 安全解析 URL
|
899
|
+
const urlObj = new URL(url);
|
900
|
+
const params = Object.fromEntries(urlObj.searchParams.entries());
|
901
|
+
const body = (_a = arguments_1[1]) === null || _a === void 0 ? void 0 : _a.body;
|
902
|
+
if (params === null || params === void 0 ? void 0 : params.en) {
|
903
|
+
bffCollectEvent({
|
904
|
+
eventName: params === null || params === void 0 ? void 0 : params.en,
|
905
|
+
eventSource: 'Google Analytics'
|
906
|
+
});
|
907
|
+
}
|
908
|
+
else if (body) {
|
909
|
+
function extractAllEnValuesSplit(queryString) {
|
910
|
+
if (typeof queryString !== 'string') {
|
911
|
+
return [];
|
912
|
+
}
|
913
|
+
const matches = [];
|
914
|
+
const regex = /en=([^&\r\n]*)/g;
|
915
|
+
let match;
|
916
|
+
while ((match = regex.exec(queryString)) !== null) {
|
917
|
+
matches.push(decodeURIComponent(match[1]));
|
918
|
+
}
|
919
|
+
return matches;
|
920
|
+
}
|
921
|
+
const enValues = extractAllEnValuesSplit(body);
|
922
|
+
enValues === null || enValues === void 0 ? void 0 : enValues.forEach((en) => {
|
923
|
+
bffCollectEvent({
|
924
|
+
eventName: en,
|
925
|
+
eventSource: 'Google Analytics'
|
926
|
+
});
|
927
|
+
});
|
928
|
+
}
|
929
|
+
return response;
|
930
|
+
}
|
931
|
+
catch (error) {
|
932
|
+
console.error('处理 GA4 请求时出错:', error);
|
933
|
+
throw error;
|
934
|
+
}
|
935
|
+
});
|
936
|
+
};
|
937
|
+
}, [bffCollectEvent]);
|
808
938
|
React.useEffect(() => {
|
809
939
|
if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
|
810
940
|
window === null || window === void 0 ? void 0 : window.fbq('track', 'PageView');
|
@@ -1065,10 +1195,6 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
1065
1195
|
const newUrl = updateQueryStringParameter(currentUrl, 'timestamp', Date.now());
|
1066
1196
|
history.pushState({ path: newUrl }, '', newUrl);
|
1067
1197
|
isPushState = true;
|
1068
|
-
bffCollectEvent({
|
1069
|
-
eventName: 'page_view',
|
1070
|
-
eventSource: 'Google Analytics'
|
1071
|
-
});
|
1072
1198
|
}
|
1073
1199
|
}
|
1074
1200
|
else {
|
@@ -1078,31 +1204,17 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
1078
1204
|
if (!isPushState) {
|
1079
1205
|
if (eventName === 'PageView' && typeof (window === null || window === void 0 ? void 0 : window.gtag) === 'function') {
|
1080
1206
|
window === null || window === void 0 ? void 0 : window.gtag('event', 'page_view');
|
1081
|
-
bffCollectEvent({
|
1082
|
-
eventName: 'page_view',
|
1083
|
-
eventSource: 'Google Analytics'
|
1084
|
-
});
|
1085
1207
|
}
|
1086
1208
|
const tiktokPixelEventParamsJson = (_b = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.tiktokPixel) === null || _b === void 0 ? void 0 : _b[eventName];
|
1087
1209
|
if ((tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name) &&
|
1088
1210
|
typeof (window === null || window === void 0 ? void 0 : window.ttq) === 'object' &&
|
1089
1211
|
typeof ((_c = window === null || window === void 0 ? void 0 : window.ttq) === null || _c === void 0 ? void 0 : _c.track) === 'function') {
|
1090
1212
|
(_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
|
-
});
|
1096
1213
|
}
|
1097
1214
|
}
|
1098
1215
|
const snapchatPixelEventParamsJson = (_e = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.snapchatPixel) === null || _e === void 0 ? void 0 : _e[eventName];
|
1099
1216
|
if ((snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name) && typeof (window === null || window === void 0 ? void 0 : window.snaptr) === 'function') {
|
1100
1217
|
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
|
-
});
|
1106
1218
|
}
|
1107
1219
|
const converApiEventParamsJson = (_f = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.converApi) === null || _f === void 0 ? void 0 : _f[eventName];
|
1108
1220
|
if (enabledMetaConversionApi && converApiEventParamsJson) {
|