@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.
@@ -41,7 +41,7 @@
41
41
 
42
42
  var name = "@artisan-commerce/analytics-web";
43
43
  var description = "Artisn commerce analytics web library";
44
- var version = "0.2.0-canary.54";
44
+ var version = "0.2.0-canary.56";
45
45
  var main = "./dist/bundle.cjs.js";
46
46
  var module = "./dist/bundle.esm.js";
47
47
  var types = "./dist/bundle.d.ts";
@@ -82,9 +82,9 @@
82
82
  "snake-case": "^3.0.4"
83
83
  };
84
84
  var devDependencies = {
85
- "@artisan-commerce/products": "0.9.0-canary.35",
86
- "@artisan-commerce/shopping-cart": "0.12.0-canary.52",
87
- "@artisan-commerce/types": "0.14.0-canary.27"
85
+ "@artisan-commerce/products": "0.9.0-canary.37",
86
+ "@artisan-commerce/shopping-cart": "0.12.0-canary.54",
87
+ "@artisan-commerce/types": "0.14.0-canary.28"
88
88
  };
89
89
  var peerDependencies = {
90
90
  "@artisan-commerce/products": "*",
@@ -602,12 +602,13 @@ ${key}: ${value}`;
602
602
  return logMessage("Providers trackerId must be unique, check that no provider trackerId are repeated", "severe");
603
603
  }
604
604
  const _a = config, { meta } = _a, rest = __objRest$3V(_a, ["meta"]);
605
+ const { platform = "web" } = meta;
605
606
  const enhancedProviders = shareArtisnAnalytics ? [GlobalProvider.instance, ...providers] : providers;
606
607
  const enhancedConfig = __spreadProps$2t(__spreadValues$3Y({}, rest), {
607
608
  providers: enhancedProviders,
608
609
  meta: __spreadProps$2t(__spreadValues$3Y({}, meta), {
609
610
  vendorId: rest.activeVendor,
610
- platform: "web",
611
+ platform,
611
612
  versionSDK: packageJSON.version
612
613
  })
613
614
  });
@@ -1469,6 +1470,9 @@ ${key}: ${value}`;
1469
1470
  const { taxes, grossPrice } = prices[priceCategory];
1470
1471
  const taxTotal = getTaxTotal$1(taxes, grossPrice);
1471
1472
  const questionsSum = getModifiersTotalTaxes$1(cartProduct, setAmount);
1473
+ if (taxTotal === null || questionsSum === null) {
1474
+ return null;
1475
+ }
1472
1476
  return questionsSum + taxTotal * amount;
1473
1477
  };
1474
1478
  const getModifiersTotalTaxes$1 = (product, setAmount) => {
@@ -1479,7 +1483,7 @@ ${key}: ${value}`;
1479
1483
  const { taxes, grossPrice } = prices[priceCategory];
1480
1484
  const taxTotal = getTaxTotal$1(taxes, grossPrice);
1481
1485
  const childrenTotal = getModifiersTotalTaxes$1(answer, setAmount);
1482
- return acc2 + amount * (taxTotal + childrenTotal);
1486
+ return acc2 + amount * (Number(taxTotal) + childrenTotal);
1483
1487
  }, 0);
1484
1488
  return acc + answersSum * setAmount;
1485
1489
  }, 0)) != null ? _b : 0;
@@ -1488,7 +1492,7 @@ ${key}: ${value}`;
1488
1492
  return getProductFieldPrice$1(product, "grossPrice", setAmount);
1489
1493
  };
1490
1494
  const getProductTotalDiscounts$1 = (product, setAmount) => {
1491
- return 0;
1495
+ return null;
1492
1496
  };
1493
1497
  const getProductNetPrice$1 = (product, setAmount) => {
1494
1498
  return getProductFieldPrice$1(product, "netPrice", setAmount);
@@ -1513,6 +1517,9 @@ ${key}: ${value}`;
1513
1517
  }, 0)) != null ? _b : 0;
1514
1518
  };
1515
1519
  const getTaxTotal$1 = (taxes, grossPrice) => {
1520
+ if (!taxes.length) {
1521
+ return null;
1522
+ }
1516
1523
  return taxes.reduce((acc, tax) => {
1517
1524
  return acc + tax.percentage / 100 * grossPrice;
1518
1525
  }, 0);
@@ -1540,12 +1547,15 @@ ${key}: ${value}`;
1540
1547
  const getShoppingCartTotal = (shoppingCart, config = {}) => {
1541
1548
  const initialValue = {
1542
1549
  subtotal: 0,
1543
- totalDiscounts: 0,
1544
- totalTaxes: 0,
1545
- totalPoints: 0,
1550
+ totalDiscounts: null,
1551
+ shippingCost: null,
1552
+ totalTaxes: null,
1553
+ totalPoints: null,
1546
1554
  total: 0
1547
1555
  };
1548
1556
  const products = getShoppingCartProducts(shoppingCart);
1557
+ if (!products.length)
1558
+ return initialValue;
1549
1559
  const totals = products.reduce((acc, product) => {
1550
1560
  const cartProduct = toCartProduct$4(product);
1551
1561
  const { priceCategory } = cartProduct;
@@ -1556,9 +1566,10 @@ ${key}: ${value}`;
1556
1566
  const subtotalNormal = !isPoints ? productTotal.grossPrice : 0;
1557
1567
  return {
1558
1568
  subtotal: acc.subtotal + subtotalNormal,
1559
- totalDiscounts: acc.totalDiscounts + productTotal.totalDiscounts,
1560
- totalTaxes: acc.totalTaxes + productTotal.totalTaxes,
1561
- totalPoints: acc.totalPoints + points,
1569
+ totalDiscounts: productTotal.totalDiscounts !== null ? Number(acc.totalDiscounts) + productTotal.totalDiscounts : null,
1570
+ totalTaxes: productTotal.totalTaxes !== null ? Number(acc.totalTaxes) + productTotal.totalTaxes : null,
1571
+ shippingCost: null,
1572
+ totalPoints: points !== null ? Number(acc.totalPoints) + points : null,
1562
1573
  total: acc.total + normal
1563
1574
  };
1564
1575
  }, initialValue);
@@ -1570,8 +1581,8 @@ ${key}: ${value}`;
1570
1581
  const { grossPrice, netPrice, taxTotal, discountTotal } = shippingCost;
1571
1582
  const totalsWithShippingCost = {
1572
1583
  subtotal: totalsWithBenefits.subtotal + grossPrice,
1573
- totalDiscounts: totalsWithBenefits.totalDiscounts + discountTotal,
1574
- totalTaxes: totalsWithBenefits.totalTaxes + taxTotal,
1584
+ totalDiscounts: totalsWithBenefits.totalDiscounts !== null ? totalsWithBenefits.totalDiscounts + discountTotal : discountTotal,
1585
+ totalTaxes: totalsWithBenefits.totalTaxes !== null ? totalsWithBenefits.totalTaxes + taxTotal : taxTotal,
1575
1586
  shippingCost: netPrice,
1576
1587
  totalPoints: totalsWithBenefits.totalPoints,
1577
1588
  total: totalsWithBenefits.total + netPrice
@@ -1611,7 +1622,7 @@ ${key}: ${value}`;
1611
1622
  if (typeof (additionalInfo == null ? void 0 : additionalInfo.copayment) !== "undefined") {
1612
1623
  const copayment = additionalInfo == null ? void 0 : additionalInfo.copayment;
1613
1624
  const totalDiscount2 = copayment * discountPercentage;
1614
- const newTotalDiscounts2 = prevTotalDiscounts + totalDiscount2;
1625
+ const newTotalDiscounts2 = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount2 : totalDiscount2;
1615
1626
  const newTotal2 = (copayment - totalDiscount2).toFixed(4);
1616
1627
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1617
1628
  totalDiscounts: newTotalDiscounts2,
@@ -1620,7 +1631,7 @@ ${key}: ${value}`;
1620
1631
  }
1621
1632
  const newSubtotal = subtotal * discountPercentage;
1622
1633
  const totalDiscount = newSubtotal;
1623
- const newTotalDiscounts = prevTotalDiscounts + totalDiscount;
1634
+ const newTotalDiscounts = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount : totalDiscount;
1624
1635
  const newTotal = prevTotal - totalDiscount;
1625
1636
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1626
1637
  totalDiscounts: newTotalDiscounts,
@@ -1810,6 +1821,9 @@ ${key}: ${value}`;
1810
1821
  const { taxes, grossPrice } = prices[priceCategory];
1811
1822
  const taxTotal = getTaxTotal(taxes, grossPrice);
1812
1823
  const questionsSum = getModifiersTotalTaxes(cartProduct, setAmount);
1824
+ if (taxTotal === null || questionsSum === null) {
1825
+ return null;
1826
+ }
1813
1827
  return questionsSum + taxTotal * amount;
1814
1828
  };
1815
1829
  const getModifiersTotalTaxes = (product, setAmount) => {
@@ -1820,7 +1834,7 @@ ${key}: ${value}`;
1820
1834
  const { taxes, grossPrice } = prices[priceCategory];
1821
1835
  const taxTotal = getTaxTotal(taxes, grossPrice);
1822
1836
  const childrenTotal = getModifiersTotalTaxes(answer, setAmount);
1823
- return acc2 + amount * (taxTotal + childrenTotal);
1837
+ return acc2 + amount * (Number(taxTotal) + childrenTotal);
1824
1838
  }, 0);
1825
1839
  return acc + answersSum * setAmount;
1826
1840
  }, 0)) != null ? _b : 0;
@@ -1829,7 +1843,7 @@ ${key}: ${value}`;
1829
1843
  return getProductFieldPrice(product, "grossPrice", setAmount);
1830
1844
  };
1831
1845
  const getProductTotalDiscounts = (product, setAmount) => {
1832
- return 0;
1846
+ return null;
1833
1847
  };
1834
1848
  const getProductNetPrice = (product, setAmount) => {
1835
1849
  return getProductFieldPrice(product, "netPrice", setAmount);
@@ -1854,6 +1868,9 @@ ${key}: ${value}`;
1854
1868
  }, 0)) != null ? _b : 0;
1855
1869
  };
1856
1870
  const getTaxTotal = (taxes, grossPrice) => {
1871
+ if (!taxes.length) {
1872
+ return null;
1873
+ }
1857
1874
  return taxes.reduce((acc, tax) => {
1858
1875
  return acc + tax.percentage / 100 * grossPrice;
1859
1876
  }, 0);
@@ -4392,7 +4409,7 @@ ${key}: ${value}`;
4392
4409
  event_callback: callback,
4393
4410
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
4394
4411
  value: total,
4395
- points: totalPoints
4412
+ points: totalPoints != null ? totalPoints : 0
4396
4413
  }, transformedParams), transformedMeta));
4397
4414
  };
4398
4415
 
@@ -4446,7 +4463,7 @@ ${key}: ${value}`;
4446
4463
  contents: getProductContentFromShoppingCart(shoppingCart),
4447
4464
  num_items: productsIds.length,
4448
4465
  value: total,
4449
- points: totalPoints
4466
+ points: totalPoints != null ? totalPoints : 0
4450
4467
  }, transformedParams), transformedMeta));
4451
4468
  };
4452
4469
 
@@ -4496,11 +4513,11 @@ ${key}: ${value}`;
4496
4513
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
4497
4514
  analytics.track("Initiate Checkout", __spreadValues$31(__spreadValues$31({
4498
4515
  total,
4499
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
4500
- shipping: shippingCost,
4501
- tax: totalTaxes,
4516
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
4517
+ shipping: shippingCost != null ? shippingCost : 0,
4518
+ tax: totalTaxes != null ? totalTaxes : 0,
4502
4519
  products: mapProductsToSegmentProducts(products),
4503
- points: totalPoints
4520
+ points: totalPoints != null ? totalPoints : 0
4504
4521
  }, transformedParams), transformedMeta));
4505
4522
  };
4506
4523
 
@@ -10211,7 +10228,7 @@ ${key}: ${value}`;
10211
10228
  event_callback: callback,
10212
10229
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
10213
10230
  value: total,
10214
- points: totalPoints
10231
+ points: totalPoints != null ? totalPoints : 0
10215
10232
  }, transformedParams), transformedMeta));
10216
10233
  };
10217
10234
 
@@ -10265,7 +10282,7 @@ ${key}: ${value}`;
10265
10282
  contents: getProductContentFromShoppingCart(shoppingCart),
10266
10283
  num_items: productsIds.length,
10267
10284
  value: total,
10268
- points: totalPoints
10285
+ points: totalPoints != null ? totalPoints : 0
10269
10286
  }, transformedParams), transformedMeta));
10270
10287
  };
10271
10288
 
@@ -10315,11 +10332,11 @@ ${key}: ${value}`;
10315
10332
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
10316
10333
  analytics.track("Purchase Attempt", __spreadValues$16(__spreadValues$16({
10317
10334
  total,
10318
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
10319
- shipping: shippingCost,
10320
- tax: totalTaxes,
10335
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
10336
+ shipping: shippingCost != null ? shippingCost : 0,
10337
+ tax: totalTaxes != null ? totalTaxes : 0,
10321
10338
  products: mapProductsToSegmentProducts(products),
10322
- points: totalPoints
10339
+ points: totalPoints != null ? totalPoints : 0
10323
10340
  }, transformedParams), transformedMeta));
10324
10341
  };
10325
10342
 
@@ -10381,7 +10398,7 @@ ${key}: ${value}`;
10381
10398
  event_callback: callback,
10382
10399
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
10383
10400
  value: total,
10384
- points: totalPoints
10401
+ points: totalPoints != null ? totalPoints : 0
10385
10402
  }, transformedParams), transformedMeta));
10386
10403
  };
10387
10404
 
@@ -10435,7 +10452,7 @@ ${key}: ${value}`;
10435
10452
  contents: getProductContentFromShoppingCart(shoppingCart),
10436
10453
  num_items: productsIds.length,
10437
10454
  value: total,
10438
- points: totalPoints
10455
+ points: totalPoints != null ? totalPoints : 0
10439
10456
  }, transformedParams), transformedMeta));
10440
10457
  };
10441
10458
 
@@ -10485,11 +10502,11 @@ ${key}: ${value}`;
10485
10502
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
10486
10503
  analytics.track("Purchase Fail", __spreadValues$13(__spreadValues$13({
10487
10504
  total,
10488
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
10489
- shipping: shippingCost,
10490
- tax: totalTaxes,
10505
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
10506
+ shipping: shippingCost != null ? shippingCost : 0,
10507
+ tax: totalTaxes != null ? totalTaxes : 0,
10491
10508
  products: mapProductsToSegmentProducts(products),
10492
- points: totalPoints
10509
+ points: totalPoints != null ? totalPoints : 0
10493
10510
  }, transformedParams), transformedMeta));
10494
10511
  };
10495
10512
 
@@ -10551,10 +10568,10 @@ ${key}: ${value}`;
10551
10568
  event_callback: callback,
10552
10569
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
10553
10570
  value: total,
10554
- points: totalPoints,
10571
+ points: totalPoints != null ? totalPoints : 0,
10555
10572
  transaction_id: orderId,
10556
- shipping: shippingCost,
10557
- tax: totalTaxes
10573
+ shipping: shippingCost != null ? shippingCost : 0,
10574
+ tax: totalTaxes != null ? totalTaxes : 0
10558
10575
  }, transformedParams), transformedMeta));
10559
10576
  };
10560
10577
 
@@ -10608,7 +10625,7 @@ ${key}: ${value}`;
10608
10625
  contents: getProductContentFromShoppingCart(shoppingCart),
10609
10626
  num_items: productsIds.length,
10610
10627
  value: total,
10611
- points: totalPoints
10628
+ points: totalPoints != null ? totalPoints : 0
10612
10629
  }, transformedParams), transformedMeta));
10613
10630
  };
10614
10631
 
@@ -10658,11 +10675,11 @@ ${key}: ${value}`;
10658
10675
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
10659
10676
  analytics.track("Order Completed", __spreadValues$10(__spreadValues$10({
10660
10677
  total,
10661
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
10662
- shipping: shippingCost,
10663
- tax: totalTaxes,
10678
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
10679
+ shipping: shippingCost != null ? shippingCost : 0,
10680
+ tax: totalTaxes != null ? totalTaxes : 0,
10664
10681
  products: mapProductsToSegmentProducts(products),
10665
- points: totalPoints
10682
+ points: totalPoints != null ? totalPoints : 0
10666
10683
  }, transformedParams), transformedMeta));
10667
10684
  };
10668
10685