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

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.
@@ -35,7 +35,7 @@ const getState$1 = () => {
35
35
 
36
36
  var name = "@artisan-commerce/analytics-web";
37
37
  var description = "Artisn commerce analytics web library";
38
- var version = "0.2.0-canary.54";
38
+ var version = "0.2.0-canary.55";
39
39
  var main = "./dist/bundle.cjs.js";
40
40
  var module = "./dist/bundle.esm.js";
41
41
  var types = "./dist/bundle.d.ts";
@@ -76,9 +76,9 @@ var dependencies = {
76
76
  "snake-case": "^3.0.4"
77
77
  };
78
78
  var devDependencies = {
79
- "@artisan-commerce/products": "0.9.0-canary.35",
80
- "@artisan-commerce/shopping-cart": "0.12.0-canary.52",
81
- "@artisan-commerce/types": "0.14.0-canary.27"
79
+ "@artisan-commerce/products": "0.9.0-canary.36",
80
+ "@artisan-commerce/shopping-cart": "0.12.0-canary.53",
81
+ "@artisan-commerce/types": "0.14.0-canary.28"
82
82
  };
83
83
  var peerDependencies = {
84
84
  "@artisan-commerce/products": "*",
@@ -1463,6 +1463,9 @@ const getProductTotalTaxes$1 = (product, setAmount) => {
1463
1463
  const { taxes, grossPrice } = prices[priceCategory];
1464
1464
  const taxTotal = getTaxTotal$1(taxes, grossPrice);
1465
1465
  const questionsSum = getModifiersTotalTaxes$1(cartProduct, setAmount);
1466
+ if (taxTotal === null || questionsSum === null) {
1467
+ return null;
1468
+ }
1466
1469
  return questionsSum + taxTotal * amount;
1467
1470
  };
1468
1471
  const getModifiersTotalTaxes$1 = (product, setAmount) => {
@@ -1473,7 +1476,7 @@ const getModifiersTotalTaxes$1 = (product, setAmount) => {
1473
1476
  const { taxes, grossPrice } = prices[priceCategory];
1474
1477
  const taxTotal = getTaxTotal$1(taxes, grossPrice);
1475
1478
  const childrenTotal = getModifiersTotalTaxes$1(answer, setAmount);
1476
- return acc2 + amount * (taxTotal + childrenTotal);
1479
+ return acc2 + amount * (Number(taxTotal) + childrenTotal);
1477
1480
  }, 0);
1478
1481
  return acc + answersSum * setAmount;
1479
1482
  }, 0)) != null ? _b : 0;
@@ -1482,7 +1485,7 @@ const getProductGrossPrice$1 = (product, setAmount) => {
1482
1485
  return getProductFieldPrice$1(product, "grossPrice", setAmount);
1483
1486
  };
1484
1487
  const getProductTotalDiscounts$1 = (product, setAmount) => {
1485
- return 0;
1488
+ return null;
1486
1489
  };
1487
1490
  const getProductNetPrice$1 = (product, setAmount) => {
1488
1491
  return getProductFieldPrice$1(product, "netPrice", setAmount);
@@ -1507,6 +1510,9 @@ const getModifiersFieldTotal$1 = (product, field) => {
1507
1510
  }, 0)) != null ? _b : 0;
1508
1511
  };
1509
1512
  const getTaxTotal$1 = (taxes, grossPrice) => {
1513
+ if (!taxes.length) {
1514
+ return null;
1515
+ }
1510
1516
  return taxes.reduce((acc, tax) => {
1511
1517
  return acc + tax.percentage / 100 * grossPrice;
1512
1518
  }, 0);
@@ -1534,12 +1540,15 @@ const { toCartProduct: toCartProduct$4 } = transformers_utils;
1534
1540
  const getShoppingCartTotal = (shoppingCart, config = {}) => {
1535
1541
  const initialValue = {
1536
1542
  subtotal: 0,
1537
- totalDiscounts: 0,
1538
- totalTaxes: 0,
1539
- totalPoints: 0,
1543
+ totalDiscounts: null,
1544
+ shippingCost: null,
1545
+ totalTaxes: null,
1546
+ totalPoints: null,
1540
1547
  total: 0
1541
1548
  };
1542
1549
  const products = getShoppingCartProducts(shoppingCart);
1550
+ if (!products.length)
1551
+ return initialValue;
1543
1552
  const totals = products.reduce((acc, product) => {
1544
1553
  const cartProduct = toCartProduct$4(product);
1545
1554
  const { priceCategory } = cartProduct;
@@ -1550,9 +1559,10 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
1550
1559
  const subtotalNormal = !isPoints ? productTotal.grossPrice : 0;
1551
1560
  return {
1552
1561
  subtotal: acc.subtotal + subtotalNormal,
1553
- totalDiscounts: acc.totalDiscounts + productTotal.totalDiscounts,
1554
- totalTaxes: acc.totalTaxes + productTotal.totalTaxes,
1555
- totalPoints: acc.totalPoints + points,
1562
+ totalDiscounts: productTotal.totalDiscounts !== null ? Number(acc.totalDiscounts) + productTotal.totalDiscounts : null,
1563
+ totalTaxes: productTotal.totalTaxes !== null ? Number(acc.totalTaxes) + productTotal.totalTaxes : null,
1564
+ shippingCost: null,
1565
+ totalPoints: points !== null ? Number(acc.totalPoints) + points : null,
1556
1566
  total: acc.total + normal
1557
1567
  };
1558
1568
  }, initialValue);
@@ -1564,8 +1574,8 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
1564
1574
  const { grossPrice, netPrice, taxTotal, discountTotal } = shippingCost;
1565
1575
  const totalsWithShippingCost = {
1566
1576
  subtotal: totalsWithBenefits.subtotal + grossPrice,
1567
- totalDiscounts: totalsWithBenefits.totalDiscounts + discountTotal,
1568
- totalTaxes: totalsWithBenefits.totalTaxes + taxTotal,
1577
+ totalDiscounts: totalsWithBenefits.totalDiscounts !== null ? totalsWithBenefits.totalDiscounts + discountTotal : discountTotal,
1578
+ totalTaxes: totalsWithBenefits.totalTaxes !== null ? totalsWithBenefits.totalTaxes + taxTotal : taxTotal,
1569
1579
  shippingCost: netPrice,
1570
1580
  totalPoints: totalsWithBenefits.totalPoints,
1571
1581
  total: totalsWithBenefits.total + netPrice
@@ -1605,7 +1615,7 @@ const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) =>
1605
1615
  if (typeof (additionalInfo == null ? void 0 : additionalInfo.copayment) !== "undefined") {
1606
1616
  const copayment = additionalInfo == null ? void 0 : additionalInfo.copayment;
1607
1617
  const totalDiscount2 = copayment * discountPercentage;
1608
- const newTotalDiscounts2 = prevTotalDiscounts + totalDiscount2;
1618
+ const newTotalDiscounts2 = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount2 : totalDiscount2;
1609
1619
  const newTotal2 = (copayment - totalDiscount2).toFixed(4);
1610
1620
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1611
1621
  totalDiscounts: newTotalDiscounts2,
@@ -1614,7 +1624,7 @@ const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) =>
1614
1624
  }
1615
1625
  const newSubtotal = subtotal * discountPercentage;
1616
1626
  const totalDiscount = newSubtotal;
1617
- const newTotalDiscounts = prevTotalDiscounts + totalDiscount;
1627
+ const newTotalDiscounts = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount : totalDiscount;
1618
1628
  const newTotal = prevTotal - totalDiscount;
1619
1629
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1620
1630
  totalDiscounts: newTotalDiscounts,
@@ -1804,6 +1814,9 @@ const getProductTotalTaxes = (product, setAmount) => {
1804
1814
  const { taxes, grossPrice } = prices[priceCategory];
1805
1815
  const taxTotal = getTaxTotal(taxes, grossPrice);
1806
1816
  const questionsSum = getModifiersTotalTaxes(cartProduct, setAmount);
1817
+ if (taxTotal === null || questionsSum === null) {
1818
+ return null;
1819
+ }
1807
1820
  return questionsSum + taxTotal * amount;
1808
1821
  };
1809
1822
  const getModifiersTotalTaxes = (product, setAmount) => {
@@ -1814,7 +1827,7 @@ const getModifiersTotalTaxes = (product, setAmount) => {
1814
1827
  const { taxes, grossPrice } = prices[priceCategory];
1815
1828
  const taxTotal = getTaxTotal(taxes, grossPrice);
1816
1829
  const childrenTotal = getModifiersTotalTaxes(answer, setAmount);
1817
- return acc2 + amount * (taxTotal + childrenTotal);
1830
+ return acc2 + amount * (Number(taxTotal) + childrenTotal);
1818
1831
  }, 0);
1819
1832
  return acc + answersSum * setAmount;
1820
1833
  }, 0)) != null ? _b : 0;
@@ -1823,7 +1836,7 @@ const getProductGrossPrice = (product, setAmount) => {
1823
1836
  return getProductFieldPrice(product, "grossPrice", setAmount);
1824
1837
  };
1825
1838
  const getProductTotalDiscounts = (product, setAmount) => {
1826
- return 0;
1839
+ return null;
1827
1840
  };
1828
1841
  const getProductNetPrice = (product, setAmount) => {
1829
1842
  return getProductFieldPrice(product, "netPrice", setAmount);
@@ -1848,6 +1861,9 @@ const getModifiersFieldTotal = (product, field) => {
1848
1861
  }, 0)) != null ? _b : 0;
1849
1862
  };
1850
1863
  const getTaxTotal = (taxes, grossPrice) => {
1864
+ if (!taxes.length) {
1865
+ return null;
1866
+ }
1851
1867
  return taxes.reduce((acc, tax) => {
1852
1868
  return acc + tax.percentage / 100 * grossPrice;
1853
1869
  }, 0);
@@ -4386,7 +4402,7 @@ const initiateCheckout$2 = (provider, params) => {
4386
4402
  event_callback: callback,
4387
4403
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
4388
4404
  value: total,
4389
- points: totalPoints
4405
+ points: totalPoints != null ? totalPoints : 0
4390
4406
  }, transformedParams), transformedMeta));
4391
4407
  };
4392
4408
 
@@ -4440,7 +4456,7 @@ const initiateCheckout$1 = (provider, params) => {
4440
4456
  contents: getProductContentFromShoppingCart(shoppingCart),
4441
4457
  num_items: productsIds.length,
4442
4458
  value: total,
4443
- points: totalPoints
4459
+ points: totalPoints != null ? totalPoints : 0
4444
4460
  }, transformedParams), transformedMeta));
4445
4461
  };
4446
4462
 
@@ -4490,11 +4506,11 @@ const initiateCheckout = (provider, params) => {
4490
4506
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
4491
4507
  analytics.track("Initiate Checkout", __spreadValues$31(__spreadValues$31({
4492
4508
  total,
4493
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
4494
- shipping: shippingCost,
4495
- tax: totalTaxes,
4509
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
4510
+ shipping: shippingCost != null ? shippingCost : 0,
4511
+ tax: totalTaxes != null ? totalTaxes : 0,
4496
4512
  products: mapProductsToSegmentProducts(products),
4497
- points: totalPoints
4513
+ points: totalPoints != null ? totalPoints : 0
4498
4514
  }, transformedParams), transformedMeta));
4499
4515
  };
4500
4516
 
@@ -10205,7 +10221,7 @@ const purchaseAttempt$2 = (provider, params) => {
10205
10221
  event_callback: callback,
10206
10222
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
10207
10223
  value: total,
10208
- points: totalPoints
10224
+ points: totalPoints != null ? totalPoints : 0
10209
10225
  }, transformedParams), transformedMeta));
10210
10226
  };
10211
10227
 
@@ -10259,7 +10275,7 @@ const purchaseAttempt$1 = (provider, params) => {
10259
10275
  contents: getProductContentFromShoppingCart(shoppingCart),
10260
10276
  num_items: productsIds.length,
10261
10277
  value: total,
10262
- points: totalPoints
10278
+ points: totalPoints != null ? totalPoints : 0
10263
10279
  }, transformedParams), transformedMeta));
10264
10280
  };
10265
10281
 
@@ -10309,11 +10325,11 @@ const purchaseAttempt = (provider, params) => {
10309
10325
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
10310
10326
  analytics.track("Purchase Attempt", __spreadValues$16(__spreadValues$16({
10311
10327
  total,
10312
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
10313
- shipping: shippingCost,
10314
- tax: totalTaxes,
10328
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
10329
+ shipping: shippingCost != null ? shippingCost : 0,
10330
+ tax: totalTaxes != null ? totalTaxes : 0,
10315
10331
  products: mapProductsToSegmentProducts(products),
10316
- points: totalPoints
10332
+ points: totalPoints != null ? totalPoints : 0
10317
10333
  }, transformedParams), transformedMeta));
10318
10334
  };
10319
10335
 
@@ -10375,7 +10391,7 @@ const purchaseFail$2 = (provider, params) => {
10375
10391
  event_callback: callback,
10376
10392
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
10377
10393
  value: total,
10378
- points: totalPoints
10394
+ points: totalPoints != null ? totalPoints : 0
10379
10395
  }, transformedParams), transformedMeta));
10380
10396
  };
10381
10397
 
@@ -10429,7 +10445,7 @@ const purchaseFail$1 = (provider, params) => {
10429
10445
  contents: getProductContentFromShoppingCart(shoppingCart),
10430
10446
  num_items: productsIds.length,
10431
10447
  value: total,
10432
- points: totalPoints
10448
+ points: totalPoints != null ? totalPoints : 0
10433
10449
  }, transformedParams), transformedMeta));
10434
10450
  };
10435
10451
 
@@ -10479,11 +10495,11 @@ const purchaseFail = (provider, params) => {
10479
10495
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
10480
10496
  analytics.track("Purchase Fail", __spreadValues$13(__spreadValues$13({
10481
10497
  total,
10482
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
10483
- shipping: shippingCost,
10484
- tax: totalTaxes,
10498
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
10499
+ shipping: shippingCost != null ? shippingCost : 0,
10500
+ tax: totalTaxes != null ? totalTaxes : 0,
10485
10501
  products: mapProductsToSegmentProducts(products),
10486
- points: totalPoints
10502
+ points: totalPoints != null ? totalPoints : 0
10487
10503
  }, transformedParams), transformedMeta));
10488
10504
  };
10489
10505
 
@@ -10545,10 +10561,10 @@ const purchaseSuccess$2 = (provider, params) => {
10545
10561
  event_callback: callback,
10546
10562
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
10547
10563
  value: total,
10548
- points: totalPoints,
10564
+ points: totalPoints != null ? totalPoints : 0,
10549
10565
  transaction_id: orderId,
10550
- shipping: shippingCost,
10551
- tax: totalTaxes
10566
+ shipping: shippingCost != null ? shippingCost : 0,
10567
+ tax: totalTaxes != null ? totalTaxes : 0
10552
10568
  }, transformedParams), transformedMeta));
10553
10569
  };
10554
10570
 
@@ -10602,7 +10618,7 @@ const purchaseSuccess$1 = (provider, params) => {
10602
10618
  contents: getProductContentFromShoppingCart(shoppingCart),
10603
10619
  num_items: productsIds.length,
10604
10620
  value: total,
10605
- points: totalPoints
10621
+ points: totalPoints != null ? totalPoints : 0
10606
10622
  }, transformedParams), transformedMeta));
10607
10623
  };
10608
10624
 
@@ -10652,11 +10668,11 @@ const purchaseSuccess = (provider, params) => {
10652
10668
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
10653
10669
  analytics.track("Order Completed", __spreadValues$10(__spreadValues$10({
10654
10670
  total,
10655
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
10656
- shipping: shippingCost,
10657
- tax: totalTaxes,
10671
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
10672
+ shipping: shippingCost != null ? shippingCost : 0,
10673
+ tax: totalTaxes != null ? totalTaxes : 0,
10658
10674
  products: mapProductsToSegmentProducts(products),
10659
- points: totalPoints
10675
+ points: totalPoints != null ? totalPoints : 0
10660
10676
  }, transformedParams), transformedMeta));
10661
10677
  };
10662
10678