@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/hooks/index.mjs
CHANGED
|
@@ -769,17 +769,11 @@ var trackAddToCartGA = ({
|
|
|
769
769
|
lineItems = [],
|
|
770
770
|
gtmParams = {}
|
|
771
771
|
}) => {
|
|
772
|
-
if (!lineItems.length
|
|
772
|
+
if (!lineItems.length) {
|
|
773
773
|
return;
|
|
774
774
|
}
|
|
775
|
-
const
|
|
776
|
-
const
|
|
777
|
-
const totalPrice = lineItems?.reduce(
|
|
778
|
-
(prev, { variant: variant2 }) => prev.plus(
|
|
779
|
-
variant2?.finalPrice?.amount === void 0 ? Number(variant2?.price?.amount) || 0 : Number(variant2?.finalPrice?.amount) || 0
|
|
780
|
-
),
|
|
781
|
-
new Decimal2(0)
|
|
782
|
-
).toNumber();
|
|
775
|
+
const currencyCode = lineItems[0].product?.price?.currencyCode;
|
|
776
|
+
const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.variant.price || 0), new Decimal2(0)).toNumber();
|
|
783
777
|
gaTrack({
|
|
784
778
|
event: "ga4Event",
|
|
785
779
|
event_name: "add_to_cart",
|
|
@@ -789,19 +783,19 @@ var trackAddToCartGA = ({
|
|
|
789
783
|
value: totalPrice,
|
|
790
784
|
position: gtmParams?.position || "",
|
|
791
785
|
items: lineItems.map((item) => {
|
|
792
|
-
const imageUrl = item.variant
|
|
786
|
+
const imageUrl = item.variant.image?.url || item.product?.images?.[0]?.url;
|
|
793
787
|
const itemCategoryId = item.gtmParams?.item_category_id;
|
|
794
|
-
const itemVariantId = item.variant
|
|
788
|
+
const itemVariantId = item.variant.id ? atobID(item.variant.id) : void 0;
|
|
795
789
|
return {
|
|
796
|
-
item_id: item.variant
|
|
797
|
-
item_name: item.
|
|
790
|
+
item_id: item.variant.sku,
|
|
791
|
+
item_name: item.product?.title,
|
|
798
792
|
item_brand: gtmParams?.brand || "",
|
|
799
|
-
item_category: item.
|
|
800
|
-
item_variant: item.variant
|
|
801
|
-
price: item.variant
|
|
793
|
+
item_category: item.product?.productType || "",
|
|
794
|
+
item_variant: item.variant.name,
|
|
795
|
+
price: item.variant.listPrice ?? item.variant.price,
|
|
802
796
|
quantity: item.quantity || 1,
|
|
803
797
|
...imageUrl && { image_url: imageUrl },
|
|
804
|
-
...itemCategoryId && { item_category_id: itemCategoryId },
|
|
798
|
+
...itemCategoryId !== void 0 && { item_category_id: itemCategoryId },
|
|
805
799
|
...itemVariantId && { item_variant_id: itemVariantId }
|
|
806
800
|
};
|
|
807
801
|
}),
|
|
@@ -901,21 +895,24 @@ var getGA4Data = async (measurementId = "G-R0BRMRK4CY") => {
|
|
|
901
895
|
};
|
|
902
896
|
|
|
903
897
|
// src/tracking/fbq.ts
|
|
904
|
-
var trackAddToCartFBQ = ({
|
|
898
|
+
var trackAddToCartFBQ = ({
|
|
899
|
+
lineItems = []
|
|
900
|
+
}) => {
|
|
905
901
|
if (typeof window === "undefined" || !window.fbq) {
|
|
906
902
|
return;
|
|
907
903
|
}
|
|
908
|
-
if (lineItems.length
|
|
909
|
-
const
|
|
904
|
+
if (lineItems.length) {
|
|
905
|
+
const item = lineItems[0];
|
|
906
|
+
const { variant, quantity, product } = item;
|
|
910
907
|
try {
|
|
911
908
|
window.fbq("track", "AddToCart", {
|
|
912
|
-
value: variant
|
|
909
|
+
value: variant.listPrice || variant.price,
|
|
913
910
|
num_items: quantity,
|
|
914
|
-
currency:
|
|
915
|
-
content_name:
|
|
911
|
+
currency: product?.price?.currencyCode,
|
|
912
|
+
content_name: product?.title,
|
|
916
913
|
content_type: "product_group",
|
|
917
|
-
content_ids: String(variant
|
|
918
|
-
content_category:
|
|
914
|
+
content_ids: String(variant.id),
|
|
915
|
+
content_category: product?.metafields?.global?.trafficType || "public"
|
|
919
916
|
});
|
|
920
917
|
} catch (error) {
|
|
921
918
|
console.error("FBQ tracking error:", error);
|
|
@@ -1000,7 +997,7 @@ var initSameLinesAttributes = ({
|
|
|
1000
997
|
line
|
|
1001
998
|
}) => {
|
|
1002
999
|
const sameLineInCart = cart?.lineItems.find(
|
|
1003
|
-
(lineInCart) => lineInCart.variant.
|
|
1000
|
+
(lineInCart) => lineInCart.variant.id === line.variant?.id
|
|
1004
1001
|
);
|
|
1005
1002
|
const codeAmountAttribute = sameLineInCart?.customAttributes?.find(
|
|
1006
1003
|
(attr) => attr.key === CODE_AMOUNT_KEY
|
|
@@ -1031,13 +1028,14 @@ var initSameLinesAttributes = ({
|
|
|
1031
1028
|
var initDiscountAttributes = ({ line }) => {
|
|
1032
1029
|
let itemAttributes = line.attributes || [];
|
|
1033
1030
|
const functionEnvAttribute = itemAttributes.find((attr) => attr.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
1034
|
-
|
|
1031
|
+
const priceAmount = line.variant?.finalPrice?.amount ?? line.variant?.price?.amount;
|
|
1032
|
+
if (!functionEnvAttribute && priceAmount !== void 0 && priceAmount !== null) {
|
|
1035
1033
|
itemAttributes = itemAttributes.concat([
|
|
1036
1034
|
{
|
|
1037
1035
|
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
1038
1036
|
value: JSON.stringify({
|
|
1039
1037
|
is_gift: false,
|
|
1040
|
-
discounted_amount:
|
|
1038
|
+
discounted_amount: new Decimal2(priceAmount).times(line.quantity || 1).toNumber()
|
|
1041
1039
|
})
|
|
1042
1040
|
}
|
|
1043
1041
|
]);
|
|
@@ -2376,12 +2374,25 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
2376
2374
|
addCustomAttributes(customAttributes);
|
|
2377
2375
|
}
|
|
2378
2376
|
}
|
|
2379
|
-
if (withTrack) {
|
|
2377
|
+
if (withTrack && resultCart) {
|
|
2378
|
+
const trackingLineItems = lineItems.map((inputLine) => {
|
|
2379
|
+
const cartLine = resultCart.lineItems.find(
|
|
2380
|
+
(line) => line.variant.id === inputLine.variant?.id
|
|
2381
|
+
);
|
|
2382
|
+
if (!cartLine) {
|
|
2383
|
+
return null;
|
|
2384
|
+
}
|
|
2385
|
+
return {
|
|
2386
|
+
...cartLine,
|
|
2387
|
+
quantity: inputLine.quantity,
|
|
2388
|
+
gtmParams: inputLine.gtmParams
|
|
2389
|
+
};
|
|
2390
|
+
}).filter(Boolean);
|
|
2380
2391
|
trackAddToCartGA({
|
|
2381
|
-
lineItems,
|
|
2392
|
+
lineItems: trackingLineItems,
|
|
2382
2393
|
gtmParams: { ...gtmParams, brand: config.getBrand() }
|
|
2383
2394
|
});
|
|
2384
|
-
trackAddToCartFBQ({ lineItems });
|
|
2395
|
+
trackAddToCartFBQ({ lineItems: trackingLineItems });
|
|
2385
2396
|
}
|
|
2386
2397
|
performanceAdapter?.addToCartEnd();
|
|
2387
2398
|
return resultCart;
|