@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.
@@ -807,36 +807,30 @@ var trackBuyNowGA = ({
807
807
  lineItems = [],
808
808
  gtmParams = {}
809
809
  }) => {
810
- if (!lineItems.length || !lineItems[0]?.variant) {
810
+ if (!lineItems.length) {
811
811
  return;
812
812
  }
813
- const { variant } = lineItems[0];
814
- const currencyCode = variant.product?.price?.currencyCode || variant.price?.currencyCode;
815
- const totalPrice = lineItems?.reduce(
816
- (prev, { variant: variant2 }) => prev.plus(
817
- variant2?.finalPrice?.amount === void 0 ? Number(variant2?.price?.amount) || 0 : Number(variant2?.finalPrice?.amount) || 0
818
- ),
819
- new Decimal2(0)
820
- ).toNumber();
813
+ const currencyCode = lineItems[0].product?.price?.currencyCode;
814
+ const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.variant.price || 0), new Decimal2(0)).toNumber();
821
815
  gaTrack({
822
816
  event: "ga4Event",
823
817
  event_name: "begin_checkout",
824
818
  event_parameters: {
825
819
  page_group: gtmParams?.pageGroup,
826
- position: gtmParams?.position,
820
+ position: gtmParams?.position || "",
827
821
  currency: currencyCode,
828
822
  value: totalPrice,
829
823
  items: lineItems.map((item) => {
830
- const imageUrl = item.variant?.image?.url || item.variant?.product?.images?.[0]?.url;
824
+ const imageUrl = item.variant.image?.url || item.product?.images?.[0]?.url;
831
825
  const itemCategoryId = item.gtmParams?.item_category_id;
832
- const itemVariantId = item.variant?.id ? atobID(item.variant.id) : void 0;
826
+ const itemVariantId = item.variant.id ? atobID(item.variant.id) : void 0;
833
827
  return {
834
- item_id: item.variant?.sku,
835
- item_name: item.variant?.product?.title || item.variant?.title,
828
+ item_id: item.variant.sku,
829
+ item_name: item.product?.title,
836
830
  item_brand: gtmParams?.brand || "",
837
- item_category: item.variant?.product?.productType || "",
838
- item_variant: item.variant?.title,
839
- price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
831
+ item_category: item.product?.productType || "",
832
+ item_variant: item.variant.name,
833
+ price: item.variant.listPrice ?? item.variant.price,
840
834
  quantity: item.quantity || 1,
841
835
  ...imageUrl && { image_url: imageUrl },
842
836
  ...itemCategoryId !== void 0 && { item_category_id: itemCategoryId },
@@ -997,7 +991,7 @@ var initSameLinesAttributes = ({
997
991
  line
998
992
  }) => {
999
993
  const sameLineInCart = cart?.lineItems.find(
1000
- (lineInCart) => lineInCart.variant.sku === line.variant?.sku && lineInCart.product?.handle === line.variant?.product?.handle
994
+ (lineInCart) => lineInCart.variant.id === line.variant?.id
1001
995
  );
1002
996
  const codeAmountAttribute = sameLineInCart?.customAttributes?.find(
1003
997
  (attr) => attr.key === CODE_AMOUNT_KEY
@@ -2547,7 +2541,16 @@ function useBuyNow({ withTrack = true } = {}, swrOptions) {
2547
2541
  }
2548
2542
  if (withTrack && resultCart.lineItems) {
2549
2543
  trackBuyNowGA({
2550
- lineItems,
2544
+ lineItems: lineItems.map((item) => {
2545
+ const cartLine = resultCart.lineItems.find((line) => line.variant.id === item.variant?.id);
2546
+ if (!cartLine) {
2547
+ return null;
2548
+ }
2549
+ return {
2550
+ ...cartLine,
2551
+ quantity: item.quantity
2552
+ };
2553
+ }).filter(Boolean),
2551
2554
  gtmParams: { ...gtmParams, brand: config.getBrand() }
2552
2555
  });
2553
2556
  if (fbqTrackConfig) {