@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.
- package/CHANGELOG.md +9 -0
- package/dist/bundle.cjs.js +60 -44
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.esm.js +60 -44
- package/dist/bundle.esm.js.map +1 -1
- package/dist/bundle.umd.js +60 -44
- package/dist/bundle.umd.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
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.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)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **artisn:** fix ShoppingCartTotals ([412b147](https://bitbucket.org/tradesystem/artisn_sdk/commit/412b147e7e402aef26eb24c4ca7d987e7be9473b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
6
15
|
## [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
16
|
|
|
8
17
|
**Note:** Version bump only for package @artisan-commerce/analytics-web
|
package/dist/bundle.cjs.js
CHANGED
|
@@ -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.
|
|
42
|
+
var version = "0.2.0-canary.55";
|
|
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.
|
|
84
|
-
"@artisan-commerce/shopping-cart": "0.12.0-canary.
|
|
85
|
-
"@artisan-commerce/types": "0.14.0-canary.
|
|
83
|
+
"@artisan-commerce/products": "0.9.0-canary.36",
|
|
84
|
+
"@artisan-commerce/shopping-cart": "0.12.0-canary.53",
|
|
85
|
+
"@artisan-commerce/types": "0.14.0-canary.28"
|
|
86
86
|
};
|
|
87
87
|
var peerDependencies = {
|
|
88
88
|
"@artisan-commerce/products": "*",
|
|
@@ -1467,6 +1467,9 @@ const getProductTotalTaxes$1 = (product, setAmount) => {
|
|
|
1467
1467
|
const { taxes, grossPrice } = prices[priceCategory];
|
|
1468
1468
|
const taxTotal = getTaxTotal$1(taxes, grossPrice);
|
|
1469
1469
|
const questionsSum = getModifiersTotalTaxes$1(cartProduct, setAmount);
|
|
1470
|
+
if (taxTotal === null || questionsSum === null) {
|
|
1471
|
+
return null;
|
|
1472
|
+
}
|
|
1470
1473
|
return questionsSum + taxTotal * amount;
|
|
1471
1474
|
};
|
|
1472
1475
|
const getModifiersTotalTaxes$1 = (product, setAmount) => {
|
|
@@ -1477,7 +1480,7 @@ const getModifiersTotalTaxes$1 = (product, setAmount) => {
|
|
|
1477
1480
|
const { taxes, grossPrice } = prices[priceCategory];
|
|
1478
1481
|
const taxTotal = getTaxTotal$1(taxes, grossPrice);
|
|
1479
1482
|
const childrenTotal = getModifiersTotalTaxes$1(answer, setAmount);
|
|
1480
|
-
return acc2 + amount * (taxTotal + childrenTotal);
|
|
1483
|
+
return acc2 + amount * (Number(taxTotal) + childrenTotal);
|
|
1481
1484
|
}, 0);
|
|
1482
1485
|
return acc + answersSum * setAmount;
|
|
1483
1486
|
}, 0)) != null ? _b : 0;
|
|
@@ -1486,7 +1489,7 @@ const getProductGrossPrice$1 = (product, setAmount) => {
|
|
|
1486
1489
|
return getProductFieldPrice$1(product, "grossPrice", setAmount);
|
|
1487
1490
|
};
|
|
1488
1491
|
const getProductTotalDiscounts$1 = (product, setAmount) => {
|
|
1489
|
-
return
|
|
1492
|
+
return null;
|
|
1490
1493
|
};
|
|
1491
1494
|
const getProductNetPrice$1 = (product, setAmount) => {
|
|
1492
1495
|
return getProductFieldPrice$1(product, "netPrice", setAmount);
|
|
@@ -1511,6 +1514,9 @@ const getModifiersFieldTotal$1 = (product, field) => {
|
|
|
1511
1514
|
}, 0)) != null ? _b : 0;
|
|
1512
1515
|
};
|
|
1513
1516
|
const getTaxTotal$1 = (taxes, grossPrice) => {
|
|
1517
|
+
if (!taxes.length) {
|
|
1518
|
+
return null;
|
|
1519
|
+
}
|
|
1514
1520
|
return taxes.reduce((acc, tax) => {
|
|
1515
1521
|
return acc + tax.percentage / 100 * grossPrice;
|
|
1516
1522
|
}, 0);
|
|
@@ -1538,12 +1544,15 @@ const { toCartProduct: toCartProduct$4 } = transformers_utils;
|
|
|
1538
1544
|
const getShoppingCartTotal = (shoppingCart, config = {}) => {
|
|
1539
1545
|
const initialValue = {
|
|
1540
1546
|
subtotal: 0,
|
|
1541
|
-
totalDiscounts:
|
|
1542
|
-
|
|
1543
|
-
|
|
1547
|
+
totalDiscounts: null,
|
|
1548
|
+
shippingCost: null,
|
|
1549
|
+
totalTaxes: null,
|
|
1550
|
+
totalPoints: null,
|
|
1544
1551
|
total: 0
|
|
1545
1552
|
};
|
|
1546
1553
|
const products = getShoppingCartProducts(shoppingCart);
|
|
1554
|
+
if (!products.length)
|
|
1555
|
+
return initialValue;
|
|
1547
1556
|
const totals = products.reduce((acc, product) => {
|
|
1548
1557
|
const cartProduct = toCartProduct$4(product);
|
|
1549
1558
|
const { priceCategory } = cartProduct;
|
|
@@ -1554,9 +1563,10 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
|
|
|
1554
1563
|
const subtotalNormal = !isPoints ? productTotal.grossPrice : 0;
|
|
1555
1564
|
return {
|
|
1556
1565
|
subtotal: acc.subtotal + subtotalNormal,
|
|
1557
|
-
totalDiscounts: acc.totalDiscounts + productTotal.totalDiscounts,
|
|
1558
|
-
totalTaxes: acc.totalTaxes + productTotal.totalTaxes,
|
|
1559
|
-
|
|
1566
|
+
totalDiscounts: productTotal.totalDiscounts !== null ? Number(acc.totalDiscounts) + productTotal.totalDiscounts : null,
|
|
1567
|
+
totalTaxes: productTotal.totalTaxes !== null ? Number(acc.totalTaxes) + productTotal.totalTaxes : null,
|
|
1568
|
+
shippingCost: null,
|
|
1569
|
+
totalPoints: points !== null ? Number(acc.totalPoints) + points : null,
|
|
1560
1570
|
total: acc.total + normal
|
|
1561
1571
|
};
|
|
1562
1572
|
}, initialValue);
|
|
@@ -1568,8 +1578,8 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
|
|
|
1568
1578
|
const { grossPrice, netPrice, taxTotal, discountTotal } = shippingCost;
|
|
1569
1579
|
const totalsWithShippingCost = {
|
|
1570
1580
|
subtotal: totalsWithBenefits.subtotal + grossPrice,
|
|
1571
|
-
totalDiscounts: totalsWithBenefits.totalDiscounts + discountTotal,
|
|
1572
|
-
totalTaxes: totalsWithBenefits.totalTaxes + taxTotal,
|
|
1581
|
+
totalDiscounts: totalsWithBenefits.totalDiscounts !== null ? totalsWithBenefits.totalDiscounts + discountTotal : discountTotal,
|
|
1582
|
+
totalTaxes: totalsWithBenefits.totalTaxes !== null ? totalsWithBenefits.totalTaxes + taxTotal : taxTotal,
|
|
1573
1583
|
shippingCost: netPrice,
|
|
1574
1584
|
totalPoints: totalsWithBenefits.totalPoints,
|
|
1575
1585
|
total: totalsWithBenefits.total + netPrice
|
|
@@ -1609,7 +1619,7 @@ const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) =>
|
|
|
1609
1619
|
if (typeof (additionalInfo == null ? void 0 : additionalInfo.copayment) !== "undefined") {
|
|
1610
1620
|
const copayment = additionalInfo == null ? void 0 : additionalInfo.copayment;
|
|
1611
1621
|
const totalDiscount2 = copayment * discountPercentage;
|
|
1612
|
-
const newTotalDiscounts2 = prevTotalDiscounts + totalDiscount2;
|
|
1622
|
+
const newTotalDiscounts2 = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount2 : totalDiscount2;
|
|
1613
1623
|
const newTotal2 = (copayment - totalDiscount2).toFixed(4);
|
|
1614
1624
|
return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
|
|
1615
1625
|
totalDiscounts: newTotalDiscounts2,
|
|
@@ -1618,7 +1628,7 @@ const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) =>
|
|
|
1618
1628
|
}
|
|
1619
1629
|
const newSubtotal = subtotal * discountPercentage;
|
|
1620
1630
|
const totalDiscount = newSubtotal;
|
|
1621
|
-
const newTotalDiscounts = prevTotalDiscounts + totalDiscount;
|
|
1631
|
+
const newTotalDiscounts = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount : totalDiscount;
|
|
1622
1632
|
const newTotal = prevTotal - totalDiscount;
|
|
1623
1633
|
return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
|
|
1624
1634
|
totalDiscounts: newTotalDiscounts,
|
|
@@ -1808,6 +1818,9 @@ const getProductTotalTaxes = (product, setAmount) => {
|
|
|
1808
1818
|
const { taxes, grossPrice } = prices[priceCategory];
|
|
1809
1819
|
const taxTotal = getTaxTotal(taxes, grossPrice);
|
|
1810
1820
|
const questionsSum = getModifiersTotalTaxes(cartProduct, setAmount);
|
|
1821
|
+
if (taxTotal === null || questionsSum === null) {
|
|
1822
|
+
return null;
|
|
1823
|
+
}
|
|
1811
1824
|
return questionsSum + taxTotal * amount;
|
|
1812
1825
|
};
|
|
1813
1826
|
const getModifiersTotalTaxes = (product, setAmount) => {
|
|
@@ -1818,7 +1831,7 @@ const getModifiersTotalTaxes = (product, setAmount) => {
|
|
|
1818
1831
|
const { taxes, grossPrice } = prices[priceCategory];
|
|
1819
1832
|
const taxTotal = getTaxTotal(taxes, grossPrice);
|
|
1820
1833
|
const childrenTotal = getModifiersTotalTaxes(answer, setAmount);
|
|
1821
|
-
return acc2 + amount * (taxTotal + childrenTotal);
|
|
1834
|
+
return acc2 + amount * (Number(taxTotal) + childrenTotal);
|
|
1822
1835
|
}, 0);
|
|
1823
1836
|
return acc + answersSum * setAmount;
|
|
1824
1837
|
}, 0)) != null ? _b : 0;
|
|
@@ -1827,7 +1840,7 @@ const getProductGrossPrice = (product, setAmount) => {
|
|
|
1827
1840
|
return getProductFieldPrice(product, "grossPrice", setAmount);
|
|
1828
1841
|
};
|
|
1829
1842
|
const getProductTotalDiscounts = (product, setAmount) => {
|
|
1830
|
-
return
|
|
1843
|
+
return null;
|
|
1831
1844
|
};
|
|
1832
1845
|
const getProductNetPrice = (product, setAmount) => {
|
|
1833
1846
|
return getProductFieldPrice(product, "netPrice", setAmount);
|
|
@@ -1852,6 +1865,9 @@ const getModifiersFieldTotal = (product, field) => {
|
|
|
1852
1865
|
}, 0)) != null ? _b : 0;
|
|
1853
1866
|
};
|
|
1854
1867
|
const getTaxTotal = (taxes, grossPrice) => {
|
|
1868
|
+
if (!taxes.length) {
|
|
1869
|
+
return null;
|
|
1870
|
+
}
|
|
1855
1871
|
return taxes.reduce((acc, tax) => {
|
|
1856
1872
|
return acc + tax.percentage / 100 * grossPrice;
|
|
1857
1873
|
}, 0);
|
|
@@ -4390,7 +4406,7 @@ const initiateCheckout$2 = (provider, params) => {
|
|
|
4390
4406
|
event_callback: callback,
|
|
4391
4407
|
items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
|
|
4392
4408
|
value: total,
|
|
4393
|
-
points: totalPoints
|
|
4409
|
+
points: totalPoints != null ? totalPoints : 0
|
|
4394
4410
|
}, transformedParams), transformedMeta));
|
|
4395
4411
|
};
|
|
4396
4412
|
|
|
@@ -4444,7 +4460,7 @@ const initiateCheckout$1 = (provider, params) => {
|
|
|
4444
4460
|
contents: getProductContentFromShoppingCart(shoppingCart),
|
|
4445
4461
|
num_items: productsIds.length,
|
|
4446
4462
|
value: total,
|
|
4447
|
-
points: totalPoints
|
|
4463
|
+
points: totalPoints != null ? totalPoints : 0
|
|
4448
4464
|
}, transformedParams), transformedMeta));
|
|
4449
4465
|
};
|
|
4450
4466
|
|
|
@@ -4494,11 +4510,11 @@ const initiateCheckout = (provider, params) => {
|
|
|
4494
4510
|
const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
|
|
4495
4511
|
analytics.track("Initiate Checkout", __spreadValues$31(__spreadValues$31({
|
|
4496
4512
|
total,
|
|
4497
|
-
revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
|
|
4498
|
-
shipping: shippingCost,
|
|
4499
|
-
tax: totalTaxes,
|
|
4513
|
+
revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
|
|
4514
|
+
shipping: shippingCost != null ? shippingCost : 0,
|
|
4515
|
+
tax: totalTaxes != null ? totalTaxes : 0,
|
|
4500
4516
|
products: mapProductsToSegmentProducts(products),
|
|
4501
|
-
points: totalPoints
|
|
4517
|
+
points: totalPoints != null ? totalPoints : 0
|
|
4502
4518
|
}, transformedParams), transformedMeta));
|
|
4503
4519
|
};
|
|
4504
4520
|
|
|
@@ -10209,7 +10225,7 @@ const purchaseAttempt$2 = (provider, params) => {
|
|
|
10209
10225
|
event_callback: callback,
|
|
10210
10226
|
items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
|
|
10211
10227
|
value: total,
|
|
10212
|
-
points: totalPoints
|
|
10228
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10213
10229
|
}, transformedParams), transformedMeta));
|
|
10214
10230
|
};
|
|
10215
10231
|
|
|
@@ -10263,7 +10279,7 @@ const purchaseAttempt$1 = (provider, params) => {
|
|
|
10263
10279
|
contents: getProductContentFromShoppingCart(shoppingCart),
|
|
10264
10280
|
num_items: productsIds.length,
|
|
10265
10281
|
value: total,
|
|
10266
|
-
points: totalPoints
|
|
10282
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10267
10283
|
}, transformedParams), transformedMeta));
|
|
10268
10284
|
};
|
|
10269
10285
|
|
|
@@ -10313,11 +10329,11 @@ const purchaseAttempt = (provider, params) => {
|
|
|
10313
10329
|
const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
|
|
10314
10330
|
analytics.track("Purchase Attempt", __spreadValues$16(__spreadValues$16({
|
|
10315
10331
|
total,
|
|
10316
|
-
revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
|
|
10317
|
-
shipping: shippingCost,
|
|
10318
|
-
tax: totalTaxes,
|
|
10332
|
+
revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
|
|
10333
|
+
shipping: shippingCost != null ? shippingCost : 0,
|
|
10334
|
+
tax: totalTaxes != null ? totalTaxes : 0,
|
|
10319
10335
|
products: mapProductsToSegmentProducts(products),
|
|
10320
|
-
points: totalPoints
|
|
10336
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10321
10337
|
}, transformedParams), transformedMeta));
|
|
10322
10338
|
};
|
|
10323
10339
|
|
|
@@ -10379,7 +10395,7 @@ const purchaseFail$2 = (provider, params) => {
|
|
|
10379
10395
|
event_callback: callback,
|
|
10380
10396
|
items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
|
|
10381
10397
|
value: total,
|
|
10382
|
-
points: totalPoints
|
|
10398
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10383
10399
|
}, transformedParams), transformedMeta));
|
|
10384
10400
|
};
|
|
10385
10401
|
|
|
@@ -10433,7 +10449,7 @@ const purchaseFail$1 = (provider, params) => {
|
|
|
10433
10449
|
contents: getProductContentFromShoppingCart(shoppingCart),
|
|
10434
10450
|
num_items: productsIds.length,
|
|
10435
10451
|
value: total,
|
|
10436
|
-
points: totalPoints
|
|
10452
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10437
10453
|
}, transformedParams), transformedMeta));
|
|
10438
10454
|
};
|
|
10439
10455
|
|
|
@@ -10483,11 +10499,11 @@ const purchaseFail = (provider, params) => {
|
|
|
10483
10499
|
const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
|
|
10484
10500
|
analytics.track("Purchase Fail", __spreadValues$13(__spreadValues$13({
|
|
10485
10501
|
total,
|
|
10486
|
-
revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
|
|
10487
|
-
shipping: shippingCost,
|
|
10488
|
-
tax: totalTaxes,
|
|
10502
|
+
revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
|
|
10503
|
+
shipping: shippingCost != null ? shippingCost : 0,
|
|
10504
|
+
tax: totalTaxes != null ? totalTaxes : 0,
|
|
10489
10505
|
products: mapProductsToSegmentProducts(products),
|
|
10490
|
-
points: totalPoints
|
|
10506
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10491
10507
|
}, transformedParams), transformedMeta));
|
|
10492
10508
|
};
|
|
10493
10509
|
|
|
@@ -10549,10 +10565,10 @@ const purchaseSuccess$2 = (provider, params) => {
|
|
|
10549
10565
|
event_callback: callback,
|
|
10550
10566
|
items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
|
|
10551
10567
|
value: total,
|
|
10552
|
-
points: totalPoints,
|
|
10568
|
+
points: totalPoints != null ? totalPoints : 0,
|
|
10553
10569
|
transaction_id: orderId,
|
|
10554
|
-
shipping: shippingCost,
|
|
10555
|
-
tax: totalTaxes
|
|
10570
|
+
shipping: shippingCost != null ? shippingCost : 0,
|
|
10571
|
+
tax: totalTaxes != null ? totalTaxes : 0
|
|
10556
10572
|
}, transformedParams), transformedMeta));
|
|
10557
10573
|
};
|
|
10558
10574
|
|
|
@@ -10606,7 +10622,7 @@ const purchaseSuccess$1 = (provider, params) => {
|
|
|
10606
10622
|
contents: getProductContentFromShoppingCart(shoppingCart),
|
|
10607
10623
|
num_items: productsIds.length,
|
|
10608
10624
|
value: total,
|
|
10609
|
-
points: totalPoints
|
|
10625
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10610
10626
|
}, transformedParams), transformedMeta));
|
|
10611
10627
|
};
|
|
10612
10628
|
|
|
@@ -10656,11 +10672,11 @@ const purchaseSuccess = (provider, params) => {
|
|
|
10656
10672
|
const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
|
|
10657
10673
|
analytics.track("Order Completed", __spreadValues$10(__spreadValues$10({
|
|
10658
10674
|
total,
|
|
10659
|
-
revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
|
|
10660
|
-
shipping: shippingCost,
|
|
10661
|
-
tax: totalTaxes,
|
|
10675
|
+
revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
|
|
10676
|
+
shipping: shippingCost != null ? shippingCost : 0,
|
|
10677
|
+
tax: totalTaxes != null ? totalTaxes : 0,
|
|
10662
10678
|
products: mapProductsToSegmentProducts(products),
|
|
10663
|
-
points: totalPoints
|
|
10679
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10664
10680
|
}, transformedParams), transformedMeta));
|
|
10665
10681
|
};
|
|
10666
10682
|
|