@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.d.ts CHANGED
@@ -1837,10 +1837,8 @@ interface AddProductToCartParams$1 extends SegmentCommonEventParams, SegmentCust
1837
1837
  interface AddProductToCartCommonParams {
1838
1838
  /** The product ID that was added to the cart */
1839
1839
  product: CartProduct;
1840
- /** Shopping cart identifier */
1841
- cartId: ShoppingCart["id"];
1842
- /** Shopping cart name */
1843
- cartName?: ShoppingCart["name"];
1840
+ /** Shopping cart */
1841
+ cart: ShoppingCart;
1844
1842
  /** The store ID where the user is buying the product */
1845
1843
  storeId: Store["storeId"];
1846
1844
  /** The store name where the user is buying the product */
@@ -2347,6 +2345,8 @@ interface ViewProductDetailsParams$1 extends SegmentCommonEventParams, SegmentCu
2347
2345
  interface ViewProductDetailsCommonParams {
2348
2346
  /** The details of the product that the user is viewing */
2349
2347
  product: Product;
2348
+ /** The shopping cart that the product belongs to */
2349
+ cart: ShoppingCart;
2350
2350
  /** The list that the product belongs to, this is used to add `item_list_name` to the items array */
2351
2351
  list?: string;
2352
2352
  }
@@ -5973,7 +5973,7 @@ declare const identifyUser: (identify: Segment$1.Traits) => void;
5973
5973
  */
5974
5974
  declare const checkInit: () => boolean;
5975
5975
 
5976
- declare const toItemProduct: (product: CartProduct) => Gtag.Item[];
5976
+ declare const toItemProduct: (product: CartProduct, cart?: ShoppingCart, item_category2?: string) => Gtag.Item[];
5977
5977
 
5978
5978
  export { Fbq, Gtag, Providers, Segment$1 as Segment, checkInit, events, identifyUser, initAnalytics, toItemProduct, updateActiveVendor };
5979
5979
  export type { AnalyticsMeta, AnalyticsProvidersConfigs, AuthProviderMethods, CommonGoogleAnalyticsEventParams, FacebookConversionsApiConfig, FacebookPixelCommonEventParams, FacebookPixelCustomEventParams, FacebookPixelProvider, FacebookPixelProviderConfig, GoogleAnalyticsCommonEventParams, GoogleAnalyticsCustomEventParams, GoogleAnalyticsProvider, GoogleAnalyticsProviderConfig, InitAnalyticsConfig, InitAnalyticsConfigMeta, SegmentCommonEventParams, SegmentCustomEventParams, SegmentProvider, SegmentProviderConfig, SupportedProviders, UserProperties };
package/dist/bundle.mjs CHANGED
@@ -48,7 +48,7 @@ const _State = class {
48
48
  let State$1 = _State;
49
49
  State$1._instance = null;
50
50
 
51
- var version = "0.14.0-canary.80";
51
+ var version = "0.2.0-canary.149";
52
52
  var packageJSON = {
53
53
  version: version};
54
54
 
@@ -903,29 +903,44 @@ const sendFacebookConversionEvent = (eventParams) => {
903
903
  customData
904
904
  }));
905
905
  };
906
- const toItemProduct = (product) => {
907
- var _a, _b;
908
- const { categories, addedFrom } = product;
906
+ const getModifiersNames = (product) => {
907
+ const { questionsAndAnswers } = product;
908
+ const modifiers = questionsAndAnswers == null ? void 0 : questionsAndAnswers.filter((question) => question.answers.some((answer) => answer.amount > 0));
909
+ const variants = modifiers == null ? void 0 : modifiers.flatMap((question) => question.answers.filter((answer) => answer.amount > 0).map((answer) => answer.name));
910
+ return variants;
911
+ };
912
+ const toItemProduct = (product, cart, item_category2) => {
913
+ var _a, _b, _c;
914
+ const { categories, addedFrom, additionalInfo } = product;
909
915
  const [category] = categories != null ? categories : [];
910
916
  const { categoryId, name: categoryName } = category != null ? category : {};
911
917
  const { netPrice } = getProductTotals(product);
918
+ const productModifiers = getModifiersNames(product);
919
+ const benefits = (_a = cart == null ? void 0 : cart.benefits) != null ? _a : [];
920
+ const source = addedFrom === "up_sell_modal" ? "upsell_recommendation" : addedFrom;
921
+ const benefit = benefits == null ? void 0 : benefits.find((benefit2) => {
922
+ var _a2, _b2, _c2, _d;
923
+ 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);
924
+ });
925
+ const couponCode = (_c = (_b = benefit == null ? void 0 : benefit.reward) == null ? void 0 : _b.metadata) == null ? void 0 : _c.coupon_code;
912
926
  const item = {
913
927
  item_name: product.name,
914
928
  item_id: product.productId,
915
- item_category: (_b = (_a = product.categories) == null ? void 0 : _a[0]) == null ? void 0 : _b.name,
916
- item_category2: product.addedFrom,
929
+ item_category: categoryName,
930
+ item_category2: item_category2 != null ? item_category2 : source,
917
931
  price_in_usd: netPrice,
918
932
  price: netPrice,
919
933
  quantity: product.amount,
920
934
  item_revenue_in_usd: netPrice,
921
- item_revenue: netPrice
935
+ item_revenue: netPrice,
936
+ item_list_name: (categoryName == null ? void 0 : categoryName.includes("COUPON")) ? "coupon_menu" : "product_menu"
922
937
  };
923
938
  if (categoryId)
924
939
  item.item_list_id = categoryId;
925
- if (categoryName)
926
- item.item_category = categoryName;
927
- if (addedFrom)
928
- item.item_category2 = addedFrom;
940
+ if (productModifiers == null ? void 0 : productModifiers.length)
941
+ item.item_variant = productModifiers.join(", ");
942
+ if (couponCode)
943
+ item.coupon = couponCode;
929
944
  return [item];
930
945
  };
931
946
  const toItems = (type, params) => {
@@ -942,13 +957,13 @@ const toItems = (type, params) => {
942
957
  ];
943
958
  }
944
959
  case "viewProductDetails": {
945
- const { product } = params;
946
- return toItemProduct(product);
960
+ const { product, cart } = params;
961
+ return toItemProduct(product, cart);
947
962
  }
948
963
  case "purchaseSuccess": {
949
964
  const { shoppingCart } = params;
950
965
  const products = getShoppingCartProducts(shoppingCart);
951
- return products.flatMap(toItemProduct);
966
+ return products.flatMap((product) => toItemProduct(product, shoppingCart));
952
967
  }
953
968
  case "setPaymentInfo": {
954
969
  const { orderTotal, paymentType, cardType } = params;
@@ -968,19 +983,19 @@ const toItems = (type, params) => {
968
983
  return toItemProduct(product);
969
984
  }
970
985
  case "viewCart": {
971
- const { shoppingCart, products } = params;
986
+ const { shoppingCart, products, item_category2 } = params;
972
987
  const shoppingCartProducts = shoppingCart ? getShoppingCartProducts(shoppingCart) : [];
973
988
  let productsToMap = [];
974
989
  if (shoppingCartProducts.length)
975
990
  productsToMap = shoppingCartProducts;
976
991
  else if (products == null ? void 0 : products.length)
977
992
  productsToMap = products;
978
- return productsToMap.flatMap(toItemProduct);
993
+ return productsToMap.flatMap((product) => toItemProduct(product, shoppingCart, item_category2));
979
994
  }
980
995
  case "initiateCheckout": {
981
- const { shoppingCart } = params;
996
+ const { shoppingCart, item_category2 } = params;
982
997
  const products = getShoppingCartProducts(shoppingCart);
983
- return products.flatMap(toItemProduct);
998
+ return products.flatMap((product) => toItemProduct(product, shoppingCart, item_category2));
984
999
  }
985
1000
  case "selectPromotion": {
986
1001
  const { item, promotionId, promotionName, creativeName } = params;
@@ -1007,8 +1022,8 @@ const toItems = (type, params) => {
1007
1022
  return [_item];
1008
1023
  }
1009
1024
  case "addProductToCart": {
1010
- const { product } = params;
1011
- return toItemProduct(product);
1025
+ const { product, cart, item_category2 } = params;
1026
+ return toItemProduct(product, cart, item_category2);
1012
1027
  }
1013
1028
  default:
1014
1029
  return;
@@ -5873,7 +5888,7 @@ var __objRest$2A = (source, exclude) => {
5873
5888
  };
5874
5889
  const viewItemList$2 = (provider, params) => {
5875
5890
  const { trackingId, userId: providerUserId } = provider;
5876
- const _a = params, { callback, userId, item, list } = _a, rest = __objRest$2A(_a, ["callback", "userId", "item", "list"]);
5891
+ const _a = params, { callback, userId, item, items, list } = _a, rest = __objRest$2A(_a, ["callback", "userId", "item", "items", "list"]);
5877
5892
  const selectedUserId = userId != null ? userId : providerUserId;
5878
5893
  const enhancedParams = __spreadProps$1C(__spreadValues$2B({}, rest), { userId: selectedUserId });
5879
5894
  const transformedParams = eventParamsToSnakeCase(enhancedParams);
@@ -5884,7 +5899,7 @@ const viewItemList$2 = (provider, params) => {
5884
5899
  event_callback: callback,
5885
5900
  item_list_name: list
5886
5901
  }, transformedParams), transformedMeta), {
5887
- items: [item]
5902
+ items: items != null ? items : [item]
5888
5903
  }));
5889
5904
  };
5890
5905
 
@@ -11768,14 +11783,17 @@ const addProductToCart$2 = (provider, params) => {
11768
11783
  var _c;
11769
11784
  const { trackingId, userId: providerUserId } = provider;
11770
11785
  const { currency: providerCurrency } = provider;
11771
- const _a = params, { callback, userId, currency, product, cartName } = _a, params2 = __objRest$O(_a, ["callback", "userId", "currency", "product", "cartName"]);
11772
- const _b = params2, { priceCategory, items: paramsItems, cartId, list } = _b, rest = __objRest$O(_b, ["priceCategory", "items", "cartId", "list"]);
11786
+ const _a = params, { callback, userId, currency, product, cart } = _a, params2 = __objRest$O(_a, ["callback", "userId", "currency", "product", "cart"]);
11787
+ const _b = params2, { priceCategory, items: paramsItems, list } = _b, rest = __objRest$O(_b, ["priceCategory", "items", "list"]);
11788
+ const { id: cartId, name: cartName } = cart;
11773
11789
  const selectedUserId = userId != null ? userId : providerUserId;
11774
11790
  const selectedCurrency = currency != null ? currency : providerCurrency;
11775
11791
  const items = toItems("addProductToCart", params);
11776
11792
  const enhancedParams = __spreadProps$z(__spreadValues$P({}, rest), {
11777
11793
  userId: selectedUserId,
11778
- currency: selectedCurrency
11794
+ currency: selectedCurrency,
11795
+ cartId,
11796
+ cartName
11779
11797
  });
11780
11798
  const { netPrice } = getProductTotals(product);
11781
11799
  const { priceCategory: productPriceCategory } = product;