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