@anker-in/shopify-react 1.2.2-beta.3 → 1.2.2-beta.5
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/hooks/index.d.mts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +42 -31
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +42 -31
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -31
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +1 -1
- package/dist/provider/index.d.ts +1 -1
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-C4qc-wG4.d.mts → types-DnDvCDW-.d.mts} +12 -4
- package/dist/{types-C4qc-wG4.d.ts → types-DnDvCDW-.d.ts} +12 -4
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -858,17 +858,11 @@ var trackAddToCartGA = ({
|
|
|
858
858
|
lineItems = [],
|
|
859
859
|
gtmParams = {}
|
|
860
860
|
}) => {
|
|
861
|
-
if (!lineItems.length
|
|
861
|
+
if (!lineItems.length) {
|
|
862
862
|
return;
|
|
863
863
|
}
|
|
864
|
-
const
|
|
865
|
-
const
|
|
866
|
-
const totalPrice = lineItems?.reduce(
|
|
867
|
-
(prev, { variant: variant2 }) => prev.plus(
|
|
868
|
-
variant2?.finalPrice?.amount === void 0 ? Number(variant2?.price?.amount) || 0 : Number(variant2?.finalPrice?.amount) || 0
|
|
869
|
-
),
|
|
870
|
-
new Decimal2(0)
|
|
871
|
-
).toNumber();
|
|
864
|
+
const currencyCode = lineItems[0].product?.price?.currencyCode;
|
|
865
|
+
const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.variant.price || 0), new Decimal2(0)).toNumber();
|
|
872
866
|
gaTrack({
|
|
873
867
|
event: "ga4Event",
|
|
874
868
|
event_name: "add_to_cart",
|
|
@@ -878,19 +872,19 @@ var trackAddToCartGA = ({
|
|
|
878
872
|
value: totalPrice,
|
|
879
873
|
position: gtmParams?.position || "",
|
|
880
874
|
items: lineItems.map((item) => {
|
|
881
|
-
const imageUrl = item.variant
|
|
875
|
+
const imageUrl = item.variant.image?.url || item.product?.images?.[0]?.url;
|
|
882
876
|
const itemCategoryId = item.gtmParams?.item_category_id;
|
|
883
|
-
const itemVariantId = item.variant
|
|
877
|
+
const itemVariantId = item.variant.id ? atobID(item.variant.id) : void 0;
|
|
884
878
|
return {
|
|
885
|
-
item_id: item.variant
|
|
886
|
-
item_name: item.
|
|
879
|
+
item_id: item.variant.sku,
|
|
880
|
+
item_name: item.product?.title,
|
|
887
881
|
item_brand: gtmParams?.brand || "",
|
|
888
|
-
item_category: item.
|
|
889
|
-
item_variant: item.variant
|
|
890
|
-
price: item.variant
|
|
882
|
+
item_category: item.product?.productType || "",
|
|
883
|
+
item_variant: item.variant.name,
|
|
884
|
+
price: item.variant.listPrice ?? item.variant.price,
|
|
891
885
|
quantity: item.quantity || 1,
|
|
892
886
|
...imageUrl && { image_url: imageUrl },
|
|
893
|
-
...itemCategoryId && { item_category_id: itemCategoryId },
|
|
887
|
+
...itemCategoryId !== void 0 && { item_category_id: itemCategoryId },
|
|
894
888
|
...itemVariantId && { item_variant_id: itemVariantId }
|
|
895
889
|
};
|
|
896
890
|
}),
|
|
@@ -1071,21 +1065,24 @@ var getGA4Data = async (measurementId = "G-R0BRMRK4CY") => {
|
|
|
1071
1065
|
};
|
|
1072
1066
|
|
|
1073
1067
|
// src/tracking/fbq.ts
|
|
1074
|
-
var trackAddToCartFBQ = ({
|
|
1068
|
+
var trackAddToCartFBQ = ({
|
|
1069
|
+
lineItems = []
|
|
1070
|
+
}) => {
|
|
1075
1071
|
if (typeof window === "undefined" || !window.fbq) {
|
|
1076
1072
|
return;
|
|
1077
1073
|
}
|
|
1078
|
-
if (lineItems.length
|
|
1079
|
-
const
|
|
1074
|
+
if (lineItems.length) {
|
|
1075
|
+
const item = lineItems[0];
|
|
1076
|
+
const { variant, quantity, product } = item;
|
|
1080
1077
|
try {
|
|
1081
1078
|
window.fbq("track", "AddToCart", {
|
|
1082
|
-
value: variant
|
|
1079
|
+
value: variant.listPrice || variant.price,
|
|
1083
1080
|
num_items: quantity,
|
|
1084
|
-
currency:
|
|
1085
|
-
content_name:
|
|
1081
|
+
currency: product?.price?.currencyCode,
|
|
1082
|
+
content_name: product?.title,
|
|
1086
1083
|
content_type: "product_group",
|
|
1087
|
-
content_ids: String(variant
|
|
1088
|
-
content_category:
|
|
1084
|
+
content_ids: String(variant.id),
|
|
1085
|
+
content_category: product?.metafields?.global?.trafficType || "public"
|
|
1089
1086
|
});
|
|
1090
1087
|
} catch (error) {
|
|
1091
1088
|
console.error("FBQ tracking error:", error);
|
|
@@ -1170,7 +1167,7 @@ var initSameLinesAttributes = ({
|
|
|
1170
1167
|
line
|
|
1171
1168
|
}) => {
|
|
1172
1169
|
const sameLineInCart = cart?.lineItems.find(
|
|
1173
|
-
(lineInCart) => lineInCart.variant.
|
|
1170
|
+
(lineInCart) => lineInCart.variant.id === line.variant?.id
|
|
1174
1171
|
);
|
|
1175
1172
|
const codeAmountAttribute = sameLineInCart?.customAttributes?.find(
|
|
1176
1173
|
(attr) => attr.key === CODE_AMOUNT_KEY
|
|
@@ -1201,13 +1198,14 @@ var initSameLinesAttributes = ({
|
|
|
1201
1198
|
var initDiscountAttributes = ({ line }) => {
|
|
1202
1199
|
let itemAttributes = line.attributes || [];
|
|
1203
1200
|
const functionEnvAttribute = itemAttributes.find((attr) => attr.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
1204
|
-
|
|
1201
|
+
const priceAmount = line.variant?.finalPrice?.amount ?? line.variant?.price?.amount;
|
|
1202
|
+
if (!functionEnvAttribute && priceAmount !== void 0 && priceAmount !== null) {
|
|
1205
1203
|
itemAttributes = itemAttributes.concat([
|
|
1206
1204
|
{
|
|
1207
1205
|
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
1208
1206
|
value: JSON.stringify({
|
|
1209
1207
|
is_gift: false,
|
|
1210
|
-
discounted_amount:
|
|
1208
|
+
discounted_amount: new Decimal2(priceAmount).times(line.quantity || 1).toNumber()
|
|
1211
1209
|
})
|
|
1212
1210
|
}
|
|
1213
1211
|
]);
|
|
@@ -2546,12 +2544,25 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
2546
2544
|
addCustomAttributes(customAttributes);
|
|
2547
2545
|
}
|
|
2548
2546
|
}
|
|
2549
|
-
if (withTrack) {
|
|
2547
|
+
if (withTrack && resultCart) {
|
|
2548
|
+
const trackingLineItems = lineItems.map((inputLine) => {
|
|
2549
|
+
const cartLine = resultCart.lineItems.find(
|
|
2550
|
+
(line) => line.variant.id === inputLine.variant?.id
|
|
2551
|
+
);
|
|
2552
|
+
if (!cartLine) {
|
|
2553
|
+
return null;
|
|
2554
|
+
}
|
|
2555
|
+
return {
|
|
2556
|
+
...cartLine,
|
|
2557
|
+
quantity: inputLine.quantity,
|
|
2558
|
+
gtmParams: inputLine.gtmParams
|
|
2559
|
+
};
|
|
2560
|
+
}).filter(Boolean);
|
|
2550
2561
|
trackAddToCartGA({
|
|
2551
|
-
lineItems,
|
|
2562
|
+
lineItems: trackingLineItems,
|
|
2552
2563
|
gtmParams: { ...gtmParams, brand: config.getBrand() }
|
|
2553
2564
|
});
|
|
2554
|
-
trackAddToCartFBQ({ lineItems });
|
|
2565
|
+
trackAddToCartFBQ({ lineItems: trackingLineItems });
|
|
2555
2566
|
}
|
|
2556
2567
|
performanceAdapter?.addToCartEnd();
|
|
2557
2568
|
return resultCart;
|