pb-sxp-ui 1.16.12 → 1.16.14
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 +71 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +71 -2
- 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 +71 -2
- 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 +67 -2
- package/lib/core/context/SxpDataSourceProvider.js +67 -2
- package/package.json +1 -1
package/dist/pb-ui.js
CHANGED
@@ -729,7 +729,7 @@
|
|
729
729
|
return ((_a = bffDataSource === null || bffDataSource === void 0 ? void 0 : bffDataSource.headers) === null || _a === void 0 ? void 0 : _a['x-app-id']) + storeAndLoadFeUserId();
|
730
730
|
}, [bffDataSource]);
|
731
731
|
// bff API 请求方法
|
732
|
-
const bffFetch = React.useCallback((path, options) => {
|
732
|
+
const bffFetch = React.useCallback((path, options, isBota = true) => {
|
733
733
|
var _a;
|
734
734
|
if (!bffDataSource)
|
735
735
|
return;
|
@@ -744,7 +744,7 @@
|
|
744
744
|
val.split('=')[1];
|
745
745
|
});
|
746
746
|
return window
|
747
|
-
.fetch(`${url}/api/${path}`, Object.assign({ headers: Object.assign({ 'Content-Type': 'application/json', 'x-user-id': fakeUserId }, bffDataSource.headers), method: options.method, body: options.type === 'beacon'
|
747
|
+
.fetch(`${url}/api/${path}`, Object.assign({ headers: Object.assign({ 'Content-Type': 'application/json', 'x-user-id': fakeUserId }, bffDataSource.headers), method: options.method, body: options.type === 'beacon' && isBota
|
748
748
|
? JSON.stringify({
|
749
749
|
body: btoa(encodeURIComponent(JSON.stringify(Object.assign(Object.assign(Object.assign({}, options.body), bffDataSource.headers), { 'x-user-id': fakeUserId }))))
|
750
750
|
})
|
@@ -752,6 +752,57 @@
|
|
752
752
|
.then((res) => res.json())
|
753
753
|
.catch((err) => Promise.reject(err));
|
754
754
|
}, [bffDataSource, fakeUserId]);
|
755
|
+
const bffCollectEvent = React.useCallback((params) => {
|
756
|
+
var _a;
|
757
|
+
const body = {
|
758
|
+
eventName: params === null || params === void 0 ? void 0 : params.eventName,
|
759
|
+
eventSource: params === null || params === void 0 ? void 0 : params.eventSource,
|
760
|
+
eventInfo: (params === null || params === void 0 ? void 0 : params.eventInfo) ? JSON.stringify(params === null || params === void 0 ? void 0 : params.eventInfo) : ''
|
761
|
+
};
|
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
|
+
method: 'POST',
|
764
|
+
body,
|
765
|
+
type: 'beacon'
|
766
|
+
}, false);
|
767
|
+
}, [bffFetch, bffDataSource]);
|
768
|
+
React.useEffect(() => {
|
769
|
+
if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
|
770
|
+
const OriginalImage = window.Image;
|
771
|
+
window.Image = function () {
|
772
|
+
const img = new OriginalImage();
|
773
|
+
// 劫持 src 的 setter
|
774
|
+
const originalSrcDescriptor = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, 'src');
|
775
|
+
Object.defineProperty(img, 'src', {
|
776
|
+
set(value) {
|
777
|
+
// 继续正常设置 src
|
778
|
+
originalSrcDescriptor.set.call(this, value);
|
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
|
+
eventInfo: params
|
789
|
+
});
|
790
|
+
}
|
791
|
+
};
|
792
|
+
},
|
793
|
+
get() {
|
794
|
+
return originalSrcDescriptor.get.call(this);
|
795
|
+
}
|
796
|
+
});
|
797
|
+
return img;
|
798
|
+
};
|
799
|
+
}
|
800
|
+
}, [bffCollectEvent]);
|
801
|
+
React.useEffect(() => {
|
802
|
+
if (typeof (window === null || window === void 0 ? void 0 : window.fbq) === 'function') {
|
803
|
+
window === null || window === void 0 ? void 0 : window.fbq('track', 'PageView');
|
804
|
+
}
|
805
|
+
}, []);
|
755
806
|
// bff API admin 请求方法
|
756
807
|
const bffFetchAdmin = React.useCallback((path, options) => {
|
757
808
|
if (!bffDataSource)
|
@@ -1007,6 +1058,10 @@
|
|
1007
1058
|
const newUrl = updateQueryStringParameter(currentUrl, 'timestamp', Date.now());
|
1008
1059
|
history.pushState({ path: newUrl }, '', newUrl);
|
1009
1060
|
isPushState = true;
|
1061
|
+
bffCollectEvent({
|
1062
|
+
eventName: 'page_view',
|
1063
|
+
eventSource: 'Google Analytics'
|
1064
|
+
});
|
1010
1065
|
}
|
1011
1066
|
}
|
1012
1067
|
else {
|
@@ -1016,17 +1071,31 @@
|
|
1016
1071
|
if (!isPushState) {
|
1017
1072
|
if (eventName === 'PageView' && typeof (window === null || window === void 0 ? void 0 : window.gtag) === 'function') {
|
1018
1073
|
window === null || window === void 0 ? void 0 : window.gtag('event', 'page_view');
|
1074
|
+
bffCollectEvent({
|
1075
|
+
eventName: 'page_view',
|
1076
|
+
eventSource: 'Google Analytics'
|
1077
|
+
});
|
1019
1078
|
}
|
1020
1079
|
const tiktokPixelEventParamsJson = (_b = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.tiktokPixel) === null || _b === void 0 ? void 0 : _b[eventName];
|
1021
1080
|
if ((tiktokPixelEventParamsJson === null || tiktokPixelEventParamsJson === void 0 ? void 0 : tiktokPixelEventParamsJson.event_name) &&
|
1022
1081
|
typeof (window === null || window === void 0 ? void 0 : window.ttq) === 'object' &&
|
1023
1082
|
typeof ((_c = window === null || window === void 0 ? void 0 : window.ttq) === null || _c === void 0 ? void 0 : _c.track) === 'function') {
|
1024
1083
|
(_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
|
+
});
|
1025
1089
|
}
|
1026
1090
|
}
|
1027
1091
|
const snapchatPixelEventParamsJson = (_e = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.snapchatPixel) === null || _e === void 0 ? void 0 : _e[eventName];
|
1028
1092
|
if ((snapchatPixelEventParamsJson === null || snapchatPixelEventParamsJson === void 0 ? void 0 : snapchatPixelEventParamsJson.event_name) && typeof (window === null || window === void 0 ? void 0 : window.snaptr) === 'function') {
|
1029
1093
|
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
|
+
});
|
1030
1099
|
}
|
1031
1100
|
const converApiEventParamsJson = (_f = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.converApi) === null || _f === void 0 ? void 0 : _f[eventName];
|
1032
1101
|
if (enabledMetaConversionApi && converApiEventParamsJson) {
|