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