@anker-in/shopify-react 1.2.2-beta.4 → 1.2.2-beta.6

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.mjs CHANGED
@@ -939,36 +939,30 @@ var trackBuyNowGA = ({
939
939
  lineItems = [],
940
940
  gtmParams = {}
941
941
  }) => {
942
- if (!lineItems.length || !lineItems[0]?.variant) {
942
+ if (!lineItems.length) {
943
943
  return;
944
944
  }
945
- const { variant } = lineItems[0];
946
- const currencyCode = variant.product?.price?.currencyCode || variant.price?.currencyCode;
947
- const totalPrice = lineItems?.reduce(
948
- (prev, { variant: variant2 }) => prev.plus(
949
- variant2?.finalPrice?.amount === void 0 ? Number(variant2?.price?.amount) || 0 : Number(variant2?.finalPrice?.amount) || 0
950
- ),
951
- new Decimal2(0)
952
- ).toNumber();
945
+ const currencyCode = lineItems[0].product?.price?.currencyCode;
946
+ const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.variant.price || 0), new Decimal2(0)).toNumber();
953
947
  gaTrack({
954
948
  event: "ga4Event",
955
949
  event_name: "begin_checkout",
956
950
  event_parameters: {
957
951
  page_group: gtmParams?.pageGroup,
958
- position: gtmParams?.position,
952
+ position: gtmParams?.position || "",
959
953
  currency: currencyCode,
960
954
  value: totalPrice,
961
955
  items: lineItems.map((item) => {
962
- const imageUrl = item.variant?.image?.url || item.variant?.product?.images?.[0]?.url;
956
+ const imageUrl = item.variant.image?.url || item.product?.images?.[0]?.url;
963
957
  const itemCategoryId = item.gtmParams?.item_category_id;
964
- const itemVariantId = item.variant?.id ? atobID(item.variant.id) : void 0;
958
+ const itemVariantId = item.variant.id ? atobID(item.variant.id) : void 0;
965
959
  return {
966
- item_id: item.variant?.sku,
967
- item_name: item.variant?.product?.title || item.variant?.title,
960
+ item_id: item.variant.sku,
961
+ item_name: item.product?.title,
968
962
  item_brand: gtmParams?.brand || "",
969
- item_category: item.variant?.product?.productType || "",
970
- item_variant: item.variant?.title,
971
- price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
963
+ item_category: item.product?.productType || "",
964
+ item_variant: item.variant.name,
965
+ price: item.variant.listPrice ?? item.variant.price,
972
966
  quantity: item.quantity || 1,
973
967
  ...imageUrl && { image_url: imageUrl },
974
968
  ...itemCategoryId !== void 0 && { item_category_id: itemCategoryId },
@@ -1167,7 +1161,7 @@ var initSameLinesAttributes = ({
1167
1161
  line
1168
1162
  }) => {
1169
1163
  const sameLineInCart = cart?.lineItems.find(
1170
- (lineInCart) => lineInCart.variant.sku === line.variant?.sku && lineInCart.product?.handle === line.variant?.product?.handle
1164
+ (lineInCart) => lineInCart.variant.id === line.variant?.id
1171
1165
  );
1172
1166
  const codeAmountAttribute = sameLineInCart?.customAttributes?.find(
1173
1167
  (attr) => attr.key === CODE_AMOUNT_KEY
@@ -2717,7 +2711,16 @@ function useBuyNow({ withTrack = true } = {}, swrOptions) {
2717
2711
  }
2718
2712
  if (withTrack && resultCart.lineItems) {
2719
2713
  trackBuyNowGA({
2720
- lineItems,
2714
+ lineItems: lineItems.map((item) => {
2715
+ const cartLine = resultCart.lineItems.find((line) => line.variant.id === item.variant?.id);
2716
+ if (!cartLine) {
2717
+ return null;
2718
+ }
2719
+ return {
2720
+ ...cartLine,
2721
+ quantity: item.quantity
2722
+ };
2723
+ }).filter(Boolean),
2721
2724
  gtmParams: { ...gtmParams, brand: config.getBrand() }
2722
2725
  });
2723
2726
  if (fbqTrackConfig) {