@artisan-commerce/analytics-rn 0.3.0-canary.156 → 0.3.0-canary.159

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
@@ -1531,10 +1531,8 @@ interface AddProductToCartParams$1 extends SegmentCommonEventParams, SegmentCust
1531
1531
  interface AddProductToCartCommonParams {
1532
1532
  /** The product that was added to the cart */
1533
1533
  product: CartProduct;
1534
- /** Shopping cart identifier */
1535
- cartId: ShoppingCart["id"];
1536
- /** Shopping cart name */
1537
- cartName?: ShoppingCart["name"];
1534
+ /** Shopping cart */
1535
+ cart: ShoppingCart;
1538
1536
  /** The store ID where the user is buying the product */
1539
1537
  storeId: Store["storeId"];
1540
1538
  /** The store name where the user is buying the product */
@@ -2041,6 +2039,8 @@ interface ViewProductDetailsParams$1 extends SegmentCommonEventParams, SegmentCu
2041
2039
  interface ViewProductDetailsCommonParams {
2042
2040
  /** The details of the product that the user is viewing */
2043
2041
  product: Product;
2042
+ /** The shopping cart that the product belongs to */
2043
+ cart: ShoppingCart;
2044
2044
  /** The list that the product belongs to, this is used to add `item_list_name` to the items array */
2045
2045
  list?: string;
2046
2046
  }
@@ -5730,7 +5730,7 @@ declare const events: {
5730
5730
  */
5731
5731
  declare const updateActiveVendor: (vendor: Vendor | Vendor["id"] | -1 | undefined) => void;
5732
5732
 
5733
- declare const toItemProduct: (product: CartProduct) => Gtag.Item[];
5733
+ declare const toItemProduct: (product: CartProduct, cart?: ShoppingCart, item_category2?: string) => Gtag.Item[];
5734
5734
 
5735
5735
  export { Gtag, Providers, events, initAnalytics, toItemProduct, updateActiveVendor };
5736
5736
  export type { AnalyticsMeta, AuthProviderMethods, FacebookConversionsApiConfig, FacebookPixelCommonEventParams, FacebookPixelCustomEventParams, FacebookPixelProvider, FacebookPixelProviderConfig, GoogleAnalyticsCommonEventParams, GoogleAnalyticsCustomEventParams, GoogleAnalyticsProvider, GoogleAnalyticsProviderConfig, InitAnalyticsConfig, InitAnalyticsConfigMeta, SupportedProviders, UserProperties };
package/dist/bundle.mjs CHANGED
@@ -51,7 +51,7 @@ const _State = class {
51
51
  let State$1 = _State;
52
52
  State$1._instance = null;
53
53
 
54
- var version = "0.3.0-canary.156";
54
+ var version = "0.3.0-canary.159";
55
55
  var packageJSON = {
56
56
  version: version};
57
57
 
@@ -785,29 +785,45 @@ const sendFacebookConversionEvent = (eventParams) => {
785
785
  customData
786
786
  }));
787
787
  };
788
- const toItemProduct = (product) => {
789
- var _a, _b;
790
- const { categories, addedFrom } = product;
788
+ const getModifiersNames = (product) => {
789
+ const { questionsAndAnswers } = product;
790
+ const modifiers = questionsAndAnswers == null ? void 0 : questionsAndAnswers.filter((question) => question.answers.some((answer) => answer.amount > 0));
791
+ const variants = modifiers == null ? void 0 : modifiers.flatMap((question) => question.answers.filter((answer) => answer.amount > 0).map((answer) => answer.name));
792
+ return variants;
793
+ };
794
+ const toItemProduct = (product, cart, item_category2) => {
795
+ var _a, _b, _c;
796
+ const { categories, addedFrom, additionalInfo } = product;
791
797
  const [category] = categories != null ? categories : [];
792
798
  const { categoryId, name: categoryName } = category != null ? category : {};
793
799
  const { netPrice } = getProductTotals(product);
800
+ const productModifiers = getModifiersNames(product);
801
+ const benefits = (_a = cart == null ? void 0 : cart.benefits) != null ? _a : [];
802
+ const source = addedFrom === "up_sell_modal" ? "upsell_recommendation" : addedFrom;
803
+ const benefit = benefits == null ? void 0 : benefits.find((benefit2) => {
804
+ var _a2, _b2, _c2, _d;
805
+ 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);
806
+ });
807
+ const couponCode = (_c = (_b = benefit == null ? void 0 : benefit.reward) == null ? void 0 : _b.metadata) == null ? void 0 : _c.coupon_code;
794
808
  const item = {
795
809
  item_name: product.name,
796
810
  item_id: product.productId,
797
- item_category: (_b = (_a = product.categories) == null ? void 0 : _a[0]) == null ? void 0 : _b.name,
798
- item_category2: product.addedFrom,
811
+ item_category: categoryName,
812
+ item_category2: item_category2 != null ? item_category2 : source,
799
813
  price_in_usd: netPrice,
800
814
  price: netPrice,
801
815
  quantity: product.amount,
802
816
  item_revenue_in_usd: netPrice,
803
- item_revenue: netPrice
817
+ item_revenue: netPrice,
818
+ item_list_name: (categoryName == null ? void 0 : categoryName.includes("COUPON")) ? "coupon_menu" : "product_menu",
819
+ item_category3: (categoryName == null ? void 0 : categoryName.includes("PRODUCT PROMOTION")) ? "push_in_app" : ""
804
820
  };
805
821
  if (categoryId)
806
822
  item.item_list_id = categoryId;
807
- if (categoryName)
808
- item.item_category = categoryName;
809
- if (addedFrom)
810
- item.item_category2 = addedFrom;
823
+ if (productModifiers == null ? void 0 : productModifiers.length)
824
+ item.item_variant = productModifiers.join(", ");
825
+ if (couponCode)
826
+ item.coupon = couponCode;
811
827
  return [item];
812
828
  };
813
829
  const toItems = (type, params) => {
@@ -824,17 +840,17 @@ const toItems = (type, params) => {
824
840
  ];
825
841
  }
826
842
  case "addProductToCart": {
827
- const { product } = params;
828
- return toItemProduct(product);
843
+ const { product, cart, item_category2 } = params;
844
+ return toItemProduct(product, cart, item_category2);
829
845
  }
830
846
  case "viewProductDetails": {
831
- const { product } = params;
832
- return toItemProduct(product);
847
+ const { product, cart } = params;
848
+ return toItemProduct(product, cart);
833
849
  }
834
850
  case "purchaseSuccess": {
835
851
  const { shoppingCart } = params;
836
852
  const products = getShoppingCartProducts(shoppingCart);
837
- return products.flatMap(toItemProduct);
853
+ return products.flatMap((product) => toItemProduct(product, shoppingCart));
838
854
  }
839
855
  case "setPaymentInfo": {
840
856
  const { orderTotal, paymentType, cardType } = params;
@@ -854,14 +870,14 @@ const toItems = (type, params) => {
854
870
  return toItemProduct(product);
855
871
  }
856
872
  case "viewCart": {
857
- const { shoppingCart } = params;
873
+ const { shoppingCart, item_category2 } = params;
858
874
  const products = getShoppingCartProducts(shoppingCart);
859
- return products.flatMap(toItemProduct);
875
+ return products.flatMap((product) => toItemProduct(product, shoppingCart, item_category2));
860
876
  }
861
877
  case "initiateCheckout": {
862
- const { shoppingCart } = params;
878
+ const { shoppingCart, item_category2 } = params;
863
879
  const products = getShoppingCartProducts(shoppingCart);
864
- return products.flatMap(toItemProduct);
880
+ return products.flatMap((product) => toItemProduct(product, shoppingCart, item_category2));
865
881
  }
866
882
  case "selectPromotion": {
867
883
  const { item, promotionId, promotionName, creativeName } = params;
@@ -6640,7 +6656,7 @@ var __objRest$2l = (source, exclude) => {
6640
6656
  };
6641
6657
  const viewItemList$2 = (provider, params) => {
6642
6658
  const { userId: providerUserId, currency: providerCurrency } = provider;
6643
- const _a = params, { userId, currency, item, list } = _a, rest = __objRest$2l(_a, ["userId", "currency", "item", "list"]);
6659
+ const _a = params, { userId, currency, item, items, list } = _a, rest = __objRest$2l(_a, ["userId", "currency", "item", "items", "list"]);
6644
6660
  const selectedUserId = userId != null ? userId : providerUserId;
6645
6661
  const selectedCurrency = currency != null ? currency : providerCurrency;
6646
6662
  const enhancedParams = __spreadProps$1A(__spreadValues$2m({}, rest), {
@@ -6651,7 +6667,7 @@ const viewItemList$2 = (provider, params) => {
6651
6667
  const { meta } = State().state;
6652
6668
  const transformedMeta = eventParamsToSnakeCase(meta);
6653
6669
  analytics().logEvent("view_item_list", __spreadProps$1A(__spreadValues$2m(__spreadValues$2m({}, transformedParams), transformedMeta), {
6654
- items: [item],
6670
+ items: items != null ? items : [item],
6655
6671
  item_list_name: list
6656
6672
  }));
6657
6673
  };
@@ -10618,7 +10634,7 @@ var __objRest$19 = (source, exclude) => {
10618
10634
  };
10619
10635
  const viewProductDetails$1 = (provider, params) => {
10620
10636
  const { track, currency: providerCurrency } = provider;
10621
- const _a = params, { product, currency } = _a, rest = __objRest$19(_a, ["product", "currency"]);
10637
+ const _a = params, { product, cart, currency } = _a, rest = __objRest$19(_a, ["product", "cart", "currency"]);
10622
10638
  delete rest.userId;
10623
10639
  const selectedCurrency = currency != null ? currency : providerCurrency;
10624
10640
  const { productId, name } = product;
@@ -11954,13 +11970,16 @@ const addProductToCart$2 = (provider, params) => {
11954
11970
  var _c;
11955
11971
  const { userId: providerUserId, currency: providerCurrency } = provider;
11956
11972
  const _a = params, { userId, currency, priceCategory } = _a, params2 = __objRest$O(_a, ["userId", "currency", "priceCategory"]);
11957
- const _b = params2, { product, items: paramsItems, cartId, cartName } = _b, rest = __objRest$O(_b, ["product", "items", "cartId", "cartName"]);
11973
+ const _b = params2, { product, items: paramsItems, cart } = _b, rest = __objRest$O(_b, ["product", "items", "cart"]);
11974
+ const { id: cartId, name: cartName } = cart;
11958
11975
  const selectedUserId = userId != null ? userId : providerUserId;
11959
11976
  const selectedCurrency = currency != null ? currency : providerCurrency;
11960
11977
  const items = toItems("addProductToCart", params);
11961
11978
  const enhancedParams = __spreadProps$A(__spreadValues$P({}, rest), {
11962
11979
  userId: selectedUserId,
11963
- currency: selectedCurrency
11980
+ currency: selectedCurrency,
11981
+ cartId,
11982
+ cartName
11964
11983
  });
11965
11984
  const { netPrice } = getProductTotals(product);
11966
11985
  const { priceCategory: productPriceCategory } = product;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@artisan-commerce/analytics-rn",
3
3
  "description": "Artisn commerce analytics react native library",
4
- "version": "0.3.0-canary.156",
4
+ "version": "0.3.0-canary.159",
5
5
  "type": "module",
6
6
  "main": "./dist/bundle.mjs",
7
7
  "module": "./dist/bundle.mjs",
@@ -36,10 +36,10 @@
36
36
  "snake-case": "^3.0.4"
37
37
  },
38
38
  "devDependencies": {
39
- "@artisan-commerce/products": "0.9.0-canary.102",
40
- "@artisan-commerce/shopping-cart-core": "0.12.0-canary.140",
41
- "@artisan-commerce/state": "0.3.0-canary.51",
42
- "@artisan-commerce/types": "0.14.0-canary.79",
39
+ "@artisan-commerce/products": "0.9.0-canary.105",
40
+ "@artisan-commerce/shopping-cart-core": "0.12.0-canary.143",
41
+ "@artisan-commerce/state": "0.3.0-canary.54",
42
+ "@artisan-commerce/types": "0.14.0-canary.82",
43
43
  "@babel/core": "^7.13.15",
44
44
  "@babel/preset-env": "^7.10.4",
45
45
  "@babel/preset-react": "^7.10.4",
@@ -84,5 +84,5 @@
84
84
  }
85
85
  }
86
86
  },
87
- "gitHead": "f12af97364f52fc5767594d709abd3cee2069514"
87
+ "gitHead": "f5cfc83824eb2d1fbacf697518335cfcff7545eb"
88
88
  }