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.
- package/dist/index.cjs +113 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +113 -22
- 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 +113 -22
- 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 +98 -22
- package/lib/core/context/SxpDataSourceProvider.js +98 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -741,8 +741,8 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
741
741
|
var _a;
|
742
742
|
const body = {
|
743
743
|
eventName: params === null || params === void 0 ? void 0 : params.eventName,
|
744
|
-
eventSource: params === null || params === void 0 ? void 0 : params.eventSource
|
745
|
-
eventInfo:
|
744
|
+
eventSource: params === null || params === void 0 ? void 0 : params.eventSource
|
745
|
+
// eventInfo: params?.eventInfo ? JSON.stringify(params?.eventInfo) : ''
|
746
746
|
};
|
747
747
|
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}`, {
|
748
748
|
method: 'POST',
|
@@ -769,8 +769,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
769
769
|
const params = Object.fromEntries(url.searchParams.entries());
|
770
770
|
bffCollectEvent({
|
771
771
|
eventName: params === null || params === void 0 ? void 0 : params.ev,
|
772
|
-
eventSource: 'Meta Pixel'
|
773
|
-
eventInfo: params
|
772
|
+
eventSource: 'Meta Pixel'
|
774
773
|
});
|
775
774
|
}
|
776
775
|
};
|
@@ -783,6 +782,116 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
783
782
|
};
|
784
783
|
}
|
785
784
|
}, [bffCollectEvent]);
|
785
|
+
useEffect(() => {
|
786
|
+
// 类型安全声明
|
787
|
+
const navigatorWithBeacon = navigator;
|
788
|
+
if (!navigatorWithBeacon.sendBeacon) {
|
789
|
+
console.warn('navigator.sendBeacon is not supported');
|
790
|
+
return;
|
791
|
+
}
|
792
|
+
// 保存原始方法
|
793
|
+
const originalSendBeacon = navigatorWithBeacon.sendBeacon.bind(navigatorWithBeacon);
|
794
|
+
// 覆盖方法
|
795
|
+
navigatorWithBeacon.sendBeacon = function (url, data) {
|
796
|
+
const urlString = url instanceof URL ? url.href : url.toString();
|
797
|
+
const success = originalSendBeacon(url, data);
|
798
|
+
function parseBeaconData(data) {
|
799
|
+
return __awaiter(this, void 0, void 0, function* () {
|
800
|
+
if (typeof data === 'string')
|
801
|
+
return JSON.parse(data);
|
802
|
+
if (data instanceof Blob)
|
803
|
+
return JSON.parse(yield data.text());
|
804
|
+
if (data instanceof ArrayBuffer)
|
805
|
+
return JSON.parse(new TextDecoder().decode(data));
|
806
|
+
return null;
|
807
|
+
});
|
808
|
+
}
|
809
|
+
if (success) {
|
810
|
+
// 异步处理监控逻辑(不阻塞原始行为)
|
811
|
+
Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () {
|
812
|
+
var _a, _b;
|
813
|
+
try {
|
814
|
+
const parsedData = yield parseBeaconData(data);
|
815
|
+
if (success) {
|
816
|
+
// 使用你的自定义上报方法
|
817
|
+
if (urlString.includes('https://tr.snapchat.com/p')) {
|
818
|
+
(_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) => {
|
819
|
+
var _a, _b;
|
820
|
+
if ((_a = item === null || item === void 0 ? void 0 : item.t) === null || _a === void 0 ? void 0 : _a.ev) {
|
821
|
+
bffCollectEvent({
|
822
|
+
eventName: (_b = item === null || item === void 0 ? void 0 : item.t) === null || _b === void 0 ? void 0 : _b.ev,
|
823
|
+
eventSource: 'Snapchat Pixel'
|
824
|
+
});
|
825
|
+
}
|
826
|
+
});
|
827
|
+
}
|
828
|
+
else if (urlString.includes('https://analytics.tiktok.com/api/v2/pixel') && (parsedData === null || parsedData === void 0 ? void 0 : parsedData.event)) {
|
829
|
+
bffCollectEvent({
|
830
|
+
eventName: parsedData.event,
|
831
|
+
eventSource: 'TikTok Pixel'
|
832
|
+
});
|
833
|
+
}
|
834
|
+
}
|
835
|
+
}
|
836
|
+
catch (error) {
|
837
|
+
console.error('监控失败:', error);
|
838
|
+
}
|
839
|
+
}));
|
840
|
+
}
|
841
|
+
// 非TikTok请求直接放行
|
842
|
+
return success;
|
843
|
+
};
|
844
|
+
// 清理函数:恢复原始方法
|
845
|
+
return () => {
|
846
|
+
navigatorWithBeacon.sendBeacon = originalSendBeacon;
|
847
|
+
};
|
848
|
+
}, [bffCollectEvent]);
|
849
|
+
useEffect(() => {
|
850
|
+
const _originalFetch = window.fetch;
|
851
|
+
// 覆盖 fetch 方法
|
852
|
+
window.fetch = function (input, init) {
|
853
|
+
var arguments_1 = arguments;
|
854
|
+
return __awaiter(this, void 0, void 0, function* () {
|
855
|
+
// 安全获取 URL 字符串
|
856
|
+
let url;
|
857
|
+
try {
|
858
|
+
url = typeof input === 'string'
|
859
|
+
? input
|
860
|
+
: input instanceof URL
|
861
|
+
? input.href
|
862
|
+
: input.url;
|
863
|
+
}
|
864
|
+
catch (error) {
|
865
|
+
console.error('解析请求URL失败:', error);
|
866
|
+
return _originalFetch.apply(this, arguments_1);
|
867
|
+
}
|
868
|
+
// 非GA4请求直接放行
|
869
|
+
if (!url.includes('https://www.google-analytics.com/g/collect')) {
|
870
|
+
return _originalFetch.apply(this, arguments_1);
|
871
|
+
}
|
872
|
+
// 检查是否是 GA4 收集端点
|
873
|
+
try {
|
874
|
+
// 1. 先执行原始请求
|
875
|
+
const response = yield _originalFetch.apply(this, arguments_1);
|
876
|
+
// 2. 检查请求是否成功 (HTTP 200-299)
|
877
|
+
// 安全解析 URL
|
878
|
+
const urlObj = new URL(url);
|
879
|
+
const params = Object.fromEntries(urlObj.searchParams.entries());
|
880
|
+
if (params === null || params === void 0 ? void 0 : params.en) {
|
881
|
+
bffCollectEvent({
|
882
|
+
eventName: params === null || params === void 0 ? void 0 : params.en,
|
883
|
+
eventSource: 'Google Analytics'
|
884
|
+
});
|
885
|
+
}
|
886
|
+
return response;
|
887
|
+
}
|
888
|
+
catch (error) {
|
889
|
+
console.error('处理 GA4 请求时出错:', error);
|
890
|
+
throw error;
|
891
|
+
}
|
892
|
+
});
|
893
|
+
};
|
894
|
+
}, [bffCollectEvent]);
|
786
895
|
useEffect(() => {
|
787
896
|
if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
|
788
897
|
window === null || window === void 0 ? void 0 : window.fbq('track', 'PageView');
|
@@ -1043,10 +1152,6 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
1043
1152
|
const newUrl = updateQueryStringParameter(currentUrl, 'timestamp', Date.now());
|
1044
1153
|
history.pushState({ path: newUrl }, '', newUrl);
|
1045
1154
|
isPushState = true;
|
1046
|
-
bffCollectEvent({
|
1047
|
-
eventName: 'page_view',
|
1048
|
-
eventSource: 'Google Analytics'
|
1049
|
-
});
|
1050
1155
|
}
|
1051
1156
|
}
|
1052
1157
|
else {
|
@@ -1056,31 +1161,17 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
|
|
1056
1161
|
if (!isPushState) {
|
1057
1162
|
if (eventName === 'PageView' && typeof (window === null || window === void 0 ? void 0 : window.gtag) === 'function') {
|
1058
1163
|
window === null || window === void 0 ? void 0 : window.gtag('event', 'page_view');
|
1059
|
-
bffCollectEvent({
|
1060
|
-
eventName: 'page_view',
|
1061
|
-
eventSource: 'Google Analytics'
|
1062
|
-
});
|
1063
1164
|
}
|
1064
1165
|
const tiktokPixelEventParamsJson = (_b = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.tiktokPixel) === null || _b === void 0 ? void 0 : _b[eventName];
|
1065
1166
|
if ((tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name) &&
|
1066
1167
|
typeof (window === null || window === void 0 ? void 0 : window.ttq) === 'object' &&
|
1067
1168
|
typeof ((_c = window === null || window === void 0 ? void 0 : window.ttq) === null || _c === void 0 ? void 0 : _c.track) === 'function') {
|
1068
1169
|
(_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));
|
1069
|
-
bffCollectEvent({
|
1070
|
-
eventName: tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name,
|
1071
|
-
eventSource: 'TikTok Pixel',
|
1072
|
-
eventInfo: getEventParamsByJson(tiktokPixelEventParamsJson, product)
|
1073
|
-
});
|
1074
1170
|
}
|
1075
1171
|
}
|
1076
1172
|
const snapchatPixelEventParamsJson = (_e = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.snapchatPixel) === null || _e === void 0 ? void 0 : _e[eventName];
|
1077
1173
|
if ((snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name) && typeof (window === null || window === void 0 ? void 0 : window.snaptr) === 'function') {
|
1078
1174
|
window === null || window === void 0 ? void 0 : window.snaptr('track', snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name, getEventParamsByJson(snapchatPixelEventParamsJson, product));
|
1079
|
-
bffCollectEvent({
|
1080
|
-
eventName: snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name,
|
1081
|
-
eventSource: 'Snapchat Pixel',
|
1082
|
-
eventInfo: getEventParamsByJson(snapchatPixelEventParamsJson, product)
|
1083
|
-
});
|
1084
1175
|
}
|
1085
1176
|
const converApiEventParamsJson = (_f = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.converApi) === null || _f === void 0 ? void 0 : _f[eventName];
|
1086
1177
|
if (enabledMetaConversionApi && converApiEventParamsJson) {
|