@artisan-commerce/analytics-web 0.2.0-canary.149 → 0.2.0-canary.150

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/bundle.cjs CHANGED
@@ -50,7 +50,7 @@ const _State = class {
50
50
  let State$1 = _State;
51
51
  State$1._instance = null;
52
52
 
53
- var version = "0.14.0-canary.80";
53
+ var version = "0.2.0-canary.149";
54
54
  var packageJSON = {
55
55
  version: version};
56
56
 
@@ -905,29 +905,44 @@ const sendFacebookConversionEvent = (eventParams) => {
905
905
  customData
906
906
  }));
907
907
  };
908
- const toItemProduct = (product) => {
909
- var _a, _b;
910
- const { categories, addedFrom } = product;
908
+ const getModifiersNames = (product) => {
909
+ const { questionsAndAnswers } = product;
910
+ const modifiers = questionsAndAnswers == null ? void 0 : questionsAndAnswers.filter((question) => question.answers.some((answer) => answer.amount > 0));
911
+ const variants = modifiers == null ? void 0 : modifiers.flatMap((question) => question.answers.filter((answer) => answer.amount > 0).map((answer) => answer.name));
912
+ return variants;
913
+ };
914
+ const toItemProduct = (product, cart, item_category2) => {
915
+ var _a, _b, _c;
916
+ const { categories, addedFrom, additionalInfo } = product;
911
917
  const [category] = categories != null ? categories : [];
912
918
  const { categoryId, name: categoryName } = category != null ? category : {};
913
919
  const { netPrice } = products.getProductTotals(product);
920
+ const productModifiers = getModifiersNames(product);
921
+ const benefits = (_a = cart == null ? void 0 : cart.benefits) != null ? _a : [];
922
+ const source = addedFrom === "up_sell_modal" ? "upsell_recommendation" : addedFrom;
923
+ const benefit = benefits == null ? void 0 : benefits.find((benefit2) => {
924
+ var _a2, _b2, _c2, _d;
925
+ return ((_b2 = (_a2 = benefit2 == null ? void 0 : benefit2.reward) == null ? void 0 : _a2.attributes) == null ? void 0 : _b2.new_product_id) || ((_d = (_c2 = benefit2 == null ? void 0 : benefit2.reward) == null ? void 0 : _c2.attributes) == null ? void 0 : _d.item_id) === (additionalInfo == null ? void 0 : additionalInfo.externalId);
926
+ });
927
+ const couponCode = (_c = (_b = benefit == null ? void 0 : benefit.reward) == null ? void 0 : _b.metadata) == null ? void 0 : _c.coupon_code;
914
928
  const item = {
915
929
  item_name: product.name,
916
930
  item_id: product.productId,
917
- item_category: (_b = (_a = product.categories) == null ? void 0 : _a[0]) == null ? void 0 : _b.name,
918
- item_category2: product.addedFrom,
931
+ item_category: categoryName,
932
+ item_category2: item_category2 != null ? item_category2 : source,
919
933
  price_in_usd: netPrice,
920
934
  price: netPrice,
921
935
  quantity: product.amount,
922
936
  item_revenue_in_usd: netPrice,
923
- item_revenue: netPrice
937
+ item_revenue: netPrice,
938
+ item_list_name: (categoryName == null ? void 0 : categoryName.includes("COUPON")) ? "coupon_menu" : "product_menu"
924
939
  };
925
940
  if (categoryId)
926
941
  item.item_list_id = categoryId;
927
- if (categoryName)
928
- item.item_category = categoryName;
929
- if (addedFrom)
930
- item.item_category2 = addedFrom;
942
+ if (productModifiers == null ? void 0 : productModifiers.length)
943
+ item.item_variant = productModifiers.join(", ");
944
+ if (couponCode)
945
+ item.coupon = couponCode;
931
946
  return [item];
932
947
  };
933
948
  const toItems = (type, params) => {
@@ -944,13 +959,13 @@ const toItems = (type, params) => {
944
959
  ];
945
960
  }
946
961
  case "viewProductDetails": {
947
- const { product } = params;
948
- return toItemProduct(product);
962
+ const { product, cart } = params;
963
+ return toItemProduct(product, cart);
949
964
  }
950
965
  case "purchaseSuccess": {
951
966
  const { shoppingCart } = params;
952
967
  const products = shoppingCartCore.getShoppingCartProducts(shoppingCart);
953
- return products.flatMap(toItemProduct);
968
+ return products.flatMap((product) => toItemProduct(product, shoppingCart));
954
969
  }
955
970
  case "setPaymentInfo": {
956
971
  const { orderTotal, paymentType, cardType } = params;
@@ -970,19 +985,19 @@ const toItems = (type, params) => {
970
985
  return toItemProduct(product);
971
986
  }
972
987
  case "viewCart": {
973
- const { shoppingCart, products } = params;
988
+ const { shoppingCart, products, item_category2 } = params;
974
989
  const shoppingCartProducts = shoppingCart ? shoppingCartCore.getShoppingCartProducts(shoppingCart) : [];
975
990
  let productsToMap = [];
976
991
  if (shoppingCartProducts.length)
977
992
  productsToMap = shoppingCartProducts;
978
993
  else if (products == null ? void 0 : products.length)
979
994
  productsToMap = products;
980
- return productsToMap.flatMap(toItemProduct);
995
+ return productsToMap.flatMap((product) => toItemProduct(product, shoppingCart, item_category2));
981
996
  }
982
997
  case "initiateCheckout": {
983
- const { shoppingCart } = params;
998
+ const { shoppingCart, item_category2 } = params;
984
999
  const products = shoppingCartCore.getShoppingCartProducts(shoppingCart);
985
- return products.flatMap(toItemProduct);
1000
+ return products.flatMap((product) => toItemProduct(product, shoppingCart, item_category2));
986
1001
  }
987
1002
  case "selectPromotion": {
988
1003
  const { item, promotionId, promotionName, creativeName } = params;
@@ -1009,8 +1024,8 @@ const toItems = (type, params) => {
1009
1024
  return [_item];
1010
1025
  }
1011
1026
  case "addProductToCart": {
1012
- const { product } = params;
1013
- return toItemProduct(product);
1027
+ const { product, cart, item_category2 } = params;
1028
+ return toItemProduct(product, cart, item_category2);
1014
1029
  }
1015
1030
  default:
1016
1031
  return;
@@ -5875,7 +5890,7 @@ var __objRest$2A = (source, exclude) => {
5875
5890
  };
5876
5891
  const viewItemList$2 = (provider, params) => {
5877
5892
  const { trackingId, userId: providerUserId } = provider;
5878
- const _a = params, { callback, userId, item, list } = _a, rest = __objRest$2A(_a, ["callback", "userId", "item", "list"]);
5893
+ const _a = params, { callback, userId, item, items, list } = _a, rest = __objRest$2A(_a, ["callback", "userId", "item", "items", "list"]);
5879
5894
  const selectedUserId = userId != null ? userId : providerUserId;
5880
5895
  const enhancedParams = __spreadProps$1C(__spreadValues$2B({}, rest), { userId: selectedUserId });
5881
5896
  const transformedParams = eventParamsToSnakeCase(enhancedParams);
@@ -5886,7 +5901,7 @@ const viewItemList$2 = (provider, params) => {
5886
5901
  event_callback: callback,
5887
5902
  item_list_name: list
5888
5903
  }, transformedParams), transformedMeta), {
5889
- items: [item]
5904
+ items: items != null ? items : [item]
5890
5905
  }));
5891
5906
  };
5892
5907
 
@@ -11770,14 +11785,17 @@ const addProductToCart$2 = (provider, params) => {
11770
11785
  var _c;
11771
11786
  const { trackingId, userId: providerUserId } = provider;
11772
11787
  const { currency: providerCurrency } = provider;
11773
- const _a = params, { callback, userId, currency, product, cartName } = _a, params2 = __objRest$O(_a, ["callback", "userId", "currency", "product", "cartName"]);
11774
- const _b = params2, { priceCategory, items: paramsItems, cartId, list } = _b, rest = __objRest$O(_b, ["priceCategory", "items", "cartId", "list"]);
11788
+ const _a = params, { callback, userId, currency, product, cart } = _a, params2 = __objRest$O(_a, ["callback", "userId", "currency", "product", "cart"]);
11789
+ const _b = params2, { priceCategory, items: paramsItems, list } = _b, rest = __objRest$O(_b, ["priceCategory", "items", "list"]);
11790
+ const { id: cartId, name: cartName } = cart;
11775
11791
  const selectedUserId = userId != null ? userId : providerUserId;
11776
11792
  const selectedCurrency = currency != null ? currency : providerCurrency;
11777
11793
  const items = toItems("addProductToCart", params);
11778
11794
  const enhancedParams = __spreadProps$z(__spreadValues$P({}, rest), {
11779
11795
  userId: selectedUserId,
11780
- currency: selectedCurrency
11796
+ currency: selectedCurrency,
11797
+ cartId,
11798
+ cartName
11781
11799
  });
11782
11800
  const { netPrice } = products.getProductTotals(product);
11783
11801
  const { priceCategory: productPriceCategory } = product;