@artisan-commerce/analytics-web 0.2.0-canary.55 → 0.2.0-canary.57

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/CHANGELOG.md CHANGED
@@ -3,6 +3,24 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.2.0-canary.57](https://bitbucket.org/tradesystem/artisn_sdk/compare/@artisan-commerce/analytics-web@0.2.0-canary.56...@artisan-commerce/analytics-web@0.2.0-canary.57) (2021-12-21)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **analytics-web:** fix platform on initial analytics config ([05aa89e](https://bitbucket.org/tradesystem/artisn_sdk/commit/05aa89ebf3a06f490f10ac8f09c0cbc26d8b12e4))
12
+
13
+
14
+
15
+ ## [0.2.0-canary.56](https://bitbucket.org/tradesystem/artisn_sdk/compare/@artisan-commerce/analytics-web@0.2.0-canary.55...@artisan-commerce/analytics-web@0.2.0-canary.56) (2021-12-16)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **artisn:** fix ShoppingCartTotals ([412b147](https://bitbucket.org/tradesystem/artisn_sdk/commit/412b147e7e402aef26eb24c4ca7d987e7be9473b))
21
+
22
+
23
+
6
24
  ## [0.2.0-canary.55](https://bitbucket.org/tradesystem/artisn_sdk/compare/@artisan-commerce/analytics-web@0.2.0-canary.54...@artisan-commerce/analytics-web@0.2.0-canary.55) (2021-12-15)
7
25
 
8
26
  **Note:** Version bump only for package @artisan-commerce/analytics-web
@@ -39,7 +39,7 @@ const getState$1 = () => {
39
39
 
40
40
  var name = "@artisan-commerce/analytics-web";
41
41
  var description = "Artisn commerce analytics web library";
42
- var version = "0.2.0-canary.54";
42
+ var version = "0.2.0-canary.56";
43
43
  var main = "./dist/bundle.cjs.js";
44
44
  var module$1 = "./dist/bundle.esm.js";
45
45
  var types = "./dist/bundle.d.ts";
@@ -80,9 +80,9 @@ var dependencies = {
80
80
  "snake-case": "^3.0.4"
81
81
  };
82
82
  var devDependencies = {
83
- "@artisan-commerce/products": "0.9.0-canary.35",
84
- "@artisan-commerce/shopping-cart": "0.12.0-canary.52",
85
- "@artisan-commerce/types": "0.14.0-canary.27"
83
+ "@artisan-commerce/products": "0.9.0-canary.37",
84
+ "@artisan-commerce/shopping-cart": "0.12.0-canary.54",
85
+ "@artisan-commerce/types": "0.14.0-canary.28"
86
86
  };
87
87
  var peerDependencies = {
88
88
  "@artisan-commerce/products": "*",
@@ -600,12 +600,13 @@ const initAnalytics = (config) => {
600
600
  return logMessage("Providers trackerId must be unique, check that no provider trackerId are repeated", "severe");
601
601
  }
602
602
  const _a = config, { meta } = _a, rest = __objRest$3V(_a, ["meta"]);
603
+ const { platform = "web" } = meta;
603
604
  const enhancedProviders = shareArtisnAnalytics ? [GlobalProvider.instance, ...providers] : providers;
604
605
  const enhancedConfig = __spreadProps$2t(__spreadValues$3Y({}, rest), {
605
606
  providers: enhancedProviders,
606
607
  meta: __spreadProps$2t(__spreadValues$3Y({}, meta), {
607
608
  vendorId: rest.activeVendor,
608
- platform: "web",
609
+ platform,
609
610
  versionSDK: packageJSON.version
610
611
  })
611
612
  });
@@ -1467,6 +1468,9 @@ const getProductTotalTaxes$1 = (product, setAmount) => {
1467
1468
  const { taxes, grossPrice } = prices[priceCategory];
1468
1469
  const taxTotal = getTaxTotal$1(taxes, grossPrice);
1469
1470
  const questionsSum = getModifiersTotalTaxes$1(cartProduct, setAmount);
1471
+ if (taxTotal === null || questionsSum === null) {
1472
+ return null;
1473
+ }
1470
1474
  return questionsSum + taxTotal * amount;
1471
1475
  };
1472
1476
  const getModifiersTotalTaxes$1 = (product, setAmount) => {
@@ -1477,7 +1481,7 @@ const getModifiersTotalTaxes$1 = (product, setAmount) => {
1477
1481
  const { taxes, grossPrice } = prices[priceCategory];
1478
1482
  const taxTotal = getTaxTotal$1(taxes, grossPrice);
1479
1483
  const childrenTotal = getModifiersTotalTaxes$1(answer, setAmount);
1480
- return acc2 + amount * (taxTotal + childrenTotal);
1484
+ return acc2 + amount * (Number(taxTotal) + childrenTotal);
1481
1485
  }, 0);
1482
1486
  return acc + answersSum * setAmount;
1483
1487
  }, 0)) != null ? _b : 0;
@@ -1486,7 +1490,7 @@ const getProductGrossPrice$1 = (product, setAmount) => {
1486
1490
  return getProductFieldPrice$1(product, "grossPrice", setAmount);
1487
1491
  };
1488
1492
  const getProductTotalDiscounts$1 = (product, setAmount) => {
1489
- return 0;
1493
+ return null;
1490
1494
  };
1491
1495
  const getProductNetPrice$1 = (product, setAmount) => {
1492
1496
  return getProductFieldPrice$1(product, "netPrice", setAmount);
@@ -1511,6 +1515,9 @@ const getModifiersFieldTotal$1 = (product, field) => {
1511
1515
  }, 0)) != null ? _b : 0;
1512
1516
  };
1513
1517
  const getTaxTotal$1 = (taxes, grossPrice) => {
1518
+ if (!taxes.length) {
1519
+ return null;
1520
+ }
1514
1521
  return taxes.reduce((acc, tax) => {
1515
1522
  return acc + tax.percentage / 100 * grossPrice;
1516
1523
  }, 0);
@@ -1538,12 +1545,15 @@ const { toCartProduct: toCartProduct$4 } = transformers_utils;
1538
1545
  const getShoppingCartTotal = (shoppingCart, config = {}) => {
1539
1546
  const initialValue = {
1540
1547
  subtotal: 0,
1541
- totalDiscounts: 0,
1542
- totalTaxes: 0,
1543
- totalPoints: 0,
1548
+ totalDiscounts: null,
1549
+ shippingCost: null,
1550
+ totalTaxes: null,
1551
+ totalPoints: null,
1544
1552
  total: 0
1545
1553
  };
1546
1554
  const products = getShoppingCartProducts(shoppingCart);
1555
+ if (!products.length)
1556
+ return initialValue;
1547
1557
  const totals = products.reduce((acc, product) => {
1548
1558
  const cartProduct = toCartProduct$4(product);
1549
1559
  const { priceCategory } = cartProduct;
@@ -1554,9 +1564,10 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
1554
1564
  const subtotalNormal = !isPoints ? productTotal.grossPrice : 0;
1555
1565
  return {
1556
1566
  subtotal: acc.subtotal + subtotalNormal,
1557
- totalDiscounts: acc.totalDiscounts + productTotal.totalDiscounts,
1558
- totalTaxes: acc.totalTaxes + productTotal.totalTaxes,
1559
- totalPoints: acc.totalPoints + points,
1567
+ totalDiscounts: productTotal.totalDiscounts !== null ? Number(acc.totalDiscounts) + productTotal.totalDiscounts : null,
1568
+ totalTaxes: productTotal.totalTaxes !== null ? Number(acc.totalTaxes) + productTotal.totalTaxes : null,
1569
+ shippingCost: null,
1570
+ totalPoints: points !== null ? Number(acc.totalPoints) + points : null,
1560
1571
  total: acc.total + normal
1561
1572
  };
1562
1573
  }, initialValue);
@@ -1568,8 +1579,8 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
1568
1579
  const { grossPrice, netPrice, taxTotal, discountTotal } = shippingCost;
1569
1580
  const totalsWithShippingCost = {
1570
1581
  subtotal: totalsWithBenefits.subtotal + grossPrice,
1571
- totalDiscounts: totalsWithBenefits.totalDiscounts + discountTotal,
1572
- totalTaxes: totalsWithBenefits.totalTaxes + taxTotal,
1582
+ totalDiscounts: totalsWithBenefits.totalDiscounts !== null ? totalsWithBenefits.totalDiscounts + discountTotal : discountTotal,
1583
+ totalTaxes: totalsWithBenefits.totalTaxes !== null ? totalsWithBenefits.totalTaxes + taxTotal : taxTotal,
1573
1584
  shippingCost: netPrice,
1574
1585
  totalPoints: totalsWithBenefits.totalPoints,
1575
1586
  total: totalsWithBenefits.total + netPrice
@@ -1609,7 +1620,7 @@ const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) =>
1609
1620
  if (typeof (additionalInfo == null ? void 0 : additionalInfo.copayment) !== "undefined") {
1610
1621
  const copayment = additionalInfo == null ? void 0 : additionalInfo.copayment;
1611
1622
  const totalDiscount2 = copayment * discountPercentage;
1612
- const newTotalDiscounts2 = prevTotalDiscounts + totalDiscount2;
1623
+ const newTotalDiscounts2 = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount2 : totalDiscount2;
1613
1624
  const newTotal2 = (copayment - totalDiscount2).toFixed(4);
1614
1625
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1615
1626
  totalDiscounts: newTotalDiscounts2,
@@ -1618,7 +1629,7 @@ const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) =>
1618
1629
  }
1619
1630
  const newSubtotal = subtotal * discountPercentage;
1620
1631
  const totalDiscount = newSubtotal;
1621
- const newTotalDiscounts = prevTotalDiscounts + totalDiscount;
1632
+ const newTotalDiscounts = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount : totalDiscount;
1622
1633
  const newTotal = prevTotal - totalDiscount;
1623
1634
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1624
1635
  totalDiscounts: newTotalDiscounts,
@@ -1808,6 +1819,9 @@ const getProductTotalTaxes = (product, setAmount) => {
1808
1819
  const { taxes, grossPrice } = prices[priceCategory];
1809
1820
  const taxTotal = getTaxTotal(taxes, grossPrice);
1810
1821
  const questionsSum = getModifiersTotalTaxes(cartProduct, setAmount);
1822
+ if (taxTotal === null || questionsSum === null) {
1823
+ return null;
1824
+ }
1811
1825
  return questionsSum + taxTotal * amount;
1812
1826
  };
1813
1827
  const getModifiersTotalTaxes = (product, setAmount) => {
@@ -1818,7 +1832,7 @@ const getModifiersTotalTaxes = (product, setAmount) => {
1818
1832
  const { taxes, grossPrice } = prices[priceCategory];
1819
1833
  const taxTotal = getTaxTotal(taxes, grossPrice);
1820
1834
  const childrenTotal = getModifiersTotalTaxes(answer, setAmount);
1821
- return acc2 + amount * (taxTotal + childrenTotal);
1835
+ return acc2 + amount * (Number(taxTotal) + childrenTotal);
1822
1836
  }, 0);
1823
1837
  return acc + answersSum * setAmount;
1824
1838
  }, 0)) != null ? _b : 0;
@@ -1827,7 +1841,7 @@ const getProductGrossPrice = (product, setAmount) => {
1827
1841
  return getProductFieldPrice(product, "grossPrice", setAmount);
1828
1842
  };
1829
1843
  const getProductTotalDiscounts = (product, setAmount) => {
1830
- return 0;
1844
+ return null;
1831
1845
  };
1832
1846
  const getProductNetPrice = (product, setAmount) => {
1833
1847
  return getProductFieldPrice(product, "netPrice", setAmount);
@@ -1852,6 +1866,9 @@ const getModifiersFieldTotal = (product, field) => {
1852
1866
  }, 0)) != null ? _b : 0;
1853
1867
  };
1854
1868
  const getTaxTotal = (taxes, grossPrice) => {
1869
+ if (!taxes.length) {
1870
+ return null;
1871
+ }
1855
1872
  return taxes.reduce((acc, tax) => {
1856
1873
  return acc + tax.percentage / 100 * grossPrice;
1857
1874
  }, 0);
@@ -4390,7 +4407,7 @@ const initiateCheckout$2 = (provider, params) => {
4390
4407
  event_callback: callback,
4391
4408
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
4392
4409
  value: total,
4393
- points: totalPoints
4410
+ points: totalPoints != null ? totalPoints : 0
4394
4411
  }, transformedParams), transformedMeta));
4395
4412
  };
4396
4413
 
@@ -4444,7 +4461,7 @@ const initiateCheckout$1 = (provider, params) => {
4444
4461
  contents: getProductContentFromShoppingCart(shoppingCart),
4445
4462
  num_items: productsIds.length,
4446
4463
  value: total,
4447
- points: totalPoints
4464
+ points: totalPoints != null ? totalPoints : 0
4448
4465
  }, transformedParams), transformedMeta));
4449
4466
  };
4450
4467
 
@@ -4494,11 +4511,11 @@ const initiateCheckout = (provider, params) => {
4494
4511
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
4495
4512
  analytics.track("Initiate Checkout", __spreadValues$31(__spreadValues$31({
4496
4513
  total,
4497
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
4498
- shipping: shippingCost,
4499
- tax: totalTaxes,
4514
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
4515
+ shipping: shippingCost != null ? shippingCost : 0,
4516
+ tax: totalTaxes != null ? totalTaxes : 0,
4500
4517
  products: mapProductsToSegmentProducts(products),
4501
- points: totalPoints
4518
+ points: totalPoints != null ? totalPoints : 0
4502
4519
  }, transformedParams), transformedMeta));
4503
4520
  };
4504
4521
 
@@ -10209,7 +10226,7 @@ const purchaseAttempt$2 = (provider, params) => {
10209
10226
  event_callback: callback,
10210
10227
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
10211
10228
  value: total,
10212
- points: totalPoints
10229
+ points: totalPoints != null ? totalPoints : 0
10213
10230
  }, transformedParams), transformedMeta));
10214
10231
  };
10215
10232
 
@@ -10263,7 +10280,7 @@ const purchaseAttempt$1 = (provider, params) => {
10263
10280
  contents: getProductContentFromShoppingCart(shoppingCart),
10264
10281
  num_items: productsIds.length,
10265
10282
  value: total,
10266
- points: totalPoints
10283
+ points: totalPoints != null ? totalPoints : 0
10267
10284
  }, transformedParams), transformedMeta));
10268
10285
  };
10269
10286
 
@@ -10313,11 +10330,11 @@ const purchaseAttempt = (provider, params) => {
10313
10330
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
10314
10331
  analytics.track("Purchase Attempt", __spreadValues$16(__spreadValues$16({
10315
10332
  total,
10316
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
10317
- shipping: shippingCost,
10318
- tax: totalTaxes,
10333
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
10334
+ shipping: shippingCost != null ? shippingCost : 0,
10335
+ tax: totalTaxes != null ? totalTaxes : 0,
10319
10336
  products: mapProductsToSegmentProducts(products),
10320
- points: totalPoints
10337
+ points: totalPoints != null ? totalPoints : 0
10321
10338
  }, transformedParams), transformedMeta));
10322
10339
  };
10323
10340
 
@@ -10379,7 +10396,7 @@ const purchaseFail$2 = (provider, params) => {
10379
10396
  event_callback: callback,
10380
10397
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
10381
10398
  value: total,
10382
- points: totalPoints
10399
+ points: totalPoints != null ? totalPoints : 0
10383
10400
  }, transformedParams), transformedMeta));
10384
10401
  };
10385
10402
 
@@ -10433,7 +10450,7 @@ const purchaseFail$1 = (provider, params) => {
10433
10450
  contents: getProductContentFromShoppingCart(shoppingCart),
10434
10451
  num_items: productsIds.length,
10435
10452
  value: total,
10436
- points: totalPoints
10453
+ points: totalPoints != null ? totalPoints : 0
10437
10454
  }, transformedParams), transformedMeta));
10438
10455
  };
10439
10456
 
@@ -10483,11 +10500,11 @@ const purchaseFail = (provider, params) => {
10483
10500
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
10484
10501
  analytics.track("Purchase Fail", __spreadValues$13(__spreadValues$13({
10485
10502
  total,
10486
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
10487
- shipping: shippingCost,
10488
- tax: totalTaxes,
10503
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
10504
+ shipping: shippingCost != null ? shippingCost : 0,
10505
+ tax: totalTaxes != null ? totalTaxes : 0,
10489
10506
  products: mapProductsToSegmentProducts(products),
10490
- points: totalPoints
10507
+ points: totalPoints != null ? totalPoints : 0
10491
10508
  }, transformedParams), transformedMeta));
10492
10509
  };
10493
10510
 
@@ -10549,10 +10566,10 @@ const purchaseSuccess$2 = (provider, params) => {
10549
10566
  event_callback: callback,
10550
10567
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
10551
10568
  value: total,
10552
- points: totalPoints,
10569
+ points: totalPoints != null ? totalPoints : 0,
10553
10570
  transaction_id: orderId,
10554
- shipping: shippingCost,
10555
- tax: totalTaxes
10571
+ shipping: shippingCost != null ? shippingCost : 0,
10572
+ tax: totalTaxes != null ? totalTaxes : 0
10556
10573
  }, transformedParams), transformedMeta));
10557
10574
  };
10558
10575
 
@@ -10606,7 +10623,7 @@ const purchaseSuccess$1 = (provider, params) => {
10606
10623
  contents: getProductContentFromShoppingCart(shoppingCart),
10607
10624
  num_items: productsIds.length,
10608
10625
  value: total,
10609
- points: totalPoints
10626
+ points: totalPoints != null ? totalPoints : 0
10610
10627
  }, transformedParams), transformedMeta));
10611
10628
  };
10612
10629
 
@@ -10656,11 +10673,11 @@ const purchaseSuccess = (provider, params) => {
10656
10673
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
10657
10674
  analytics.track("Order Completed", __spreadValues$10(__spreadValues$10({
10658
10675
  total,
10659
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
10660
- shipping: shippingCost,
10661
- tax: totalTaxes,
10676
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
10677
+ shipping: shippingCost != null ? shippingCost : 0,
10678
+ tax: totalTaxes != null ? totalTaxes : 0,
10662
10679
  products: mapProductsToSegmentProducts(products),
10663
- points: totalPoints
10680
+ points: totalPoints != null ? totalPoints : 0
10664
10681
  }, transformedParams), transformedMeta));
10665
10682
  };
10666
10683