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