@artisan-commerce/analytics-rn 0.3.0-canary.57 → 0.3.0-canary.59
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 +17 -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/package.json +4 -4
package/dist/bundle.esm.js
CHANGED
|
@@ -40,7 +40,7 @@ const getState$1 = () => {
|
|
|
40
40
|
|
|
41
41
|
var name = "@artisan-commerce/analytics-rn";
|
|
42
42
|
var description = "Artisn commerce analytics react native library";
|
|
43
|
-
var version = "0.3.0-canary.
|
|
43
|
+
var version = "0.3.0-canary.59";
|
|
44
44
|
var main = "./dist/bundle.esm.js";
|
|
45
45
|
var module = "./dist/bundle.esm.js";
|
|
46
46
|
var types = "./dist/bundle.d.ts";
|
|
@@ -82,8 +82,8 @@ var dependencies = {
|
|
|
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.
|
|
85
|
+
"@artisan-commerce/products": "0.9.0-canary.37",
|
|
86
|
+
"@artisan-commerce/shopping-cart": "0.12.0-canary.55",
|
|
87
87
|
"@artisan-commerce/types": "0.14.0-canary.28",
|
|
88
88
|
"@babel/core": "^7.13.15",
|
|
89
89
|
"@babel/preset-env": "^7.10.4",
|
|
@@ -103,7 +103,7 @@ var peerDependencies = {
|
|
|
103
103
|
react: ">=16.8.6",
|
|
104
104
|
"react-native-fbsdk-next": "*"
|
|
105
105
|
};
|
|
106
|
-
var gitHead = "
|
|
106
|
+
var gitHead = "e3e2910af9b158f332ccf19d1c3896c9a3f13d6c";
|
|
107
107
|
var packageJSON = {
|
|
108
108
|
name: name,
|
|
109
109
|
description: description,
|
|
@@ -1327,6 +1327,9 @@ const getProductTotalTaxes$1 = (product, setAmount) => {
|
|
|
1327
1327
|
const { taxes, grossPrice } = prices[priceCategory];
|
|
1328
1328
|
const taxTotal = getTaxTotal$1(taxes, grossPrice);
|
|
1329
1329
|
const questionsSum = getModifiersTotalTaxes$1(cartProduct, setAmount);
|
|
1330
|
+
if (taxTotal === null || questionsSum === null) {
|
|
1331
|
+
return null;
|
|
1332
|
+
}
|
|
1330
1333
|
return questionsSum + taxTotal * amount;
|
|
1331
1334
|
};
|
|
1332
1335
|
const getModifiersTotalTaxes$1 = (product, setAmount) => {
|
|
@@ -1337,7 +1340,7 @@ const getModifiersTotalTaxes$1 = (product, setAmount) => {
|
|
|
1337
1340
|
const { taxes, grossPrice } = prices[priceCategory];
|
|
1338
1341
|
const taxTotal = getTaxTotal$1(taxes, grossPrice);
|
|
1339
1342
|
const childrenTotal = getModifiersTotalTaxes$1(answer, setAmount);
|
|
1340
|
-
return acc2 + amount * (taxTotal + childrenTotal);
|
|
1343
|
+
return acc2 + amount * (Number(taxTotal) + childrenTotal);
|
|
1341
1344
|
}, 0);
|
|
1342
1345
|
return acc + answersSum * setAmount;
|
|
1343
1346
|
}, 0)) != null ? _b : 0;
|
|
@@ -1346,7 +1349,7 @@ const getProductGrossPrice$1 = (product, setAmount) => {
|
|
|
1346
1349
|
return getProductFieldPrice$1(product, "grossPrice", setAmount);
|
|
1347
1350
|
};
|
|
1348
1351
|
const getProductTotalDiscounts$1 = (product, setAmount) => {
|
|
1349
|
-
return
|
|
1352
|
+
return null;
|
|
1350
1353
|
};
|
|
1351
1354
|
const getProductNetPrice$1 = (product, setAmount) => {
|
|
1352
1355
|
return getProductFieldPrice$1(product, "netPrice", setAmount);
|
|
@@ -1371,6 +1374,9 @@ const getModifiersFieldTotal$1 = (product, field) => {
|
|
|
1371
1374
|
}, 0)) != null ? _b : 0;
|
|
1372
1375
|
};
|
|
1373
1376
|
const getTaxTotal$1 = (taxes, grossPrice) => {
|
|
1377
|
+
if (!taxes.length) {
|
|
1378
|
+
return null;
|
|
1379
|
+
}
|
|
1374
1380
|
return taxes.reduce((acc, tax) => {
|
|
1375
1381
|
return acc + tax.percentage / 100 * grossPrice;
|
|
1376
1382
|
}, 0);
|
|
@@ -1398,12 +1404,15 @@ const { toCartProduct: toCartProduct$4 } = transformers_utils;
|
|
|
1398
1404
|
const getShoppingCartTotal = (shoppingCart, config = {}) => {
|
|
1399
1405
|
const initialValue = {
|
|
1400
1406
|
subtotal: 0,
|
|
1401
|
-
totalDiscounts:
|
|
1402
|
-
|
|
1403
|
-
|
|
1407
|
+
totalDiscounts: null,
|
|
1408
|
+
shippingCost: null,
|
|
1409
|
+
totalTaxes: null,
|
|
1410
|
+
totalPoints: null,
|
|
1404
1411
|
total: 0
|
|
1405
1412
|
};
|
|
1406
1413
|
const products = getShoppingCartProducts(shoppingCart);
|
|
1414
|
+
if (!products.length)
|
|
1415
|
+
return initialValue;
|
|
1407
1416
|
const totals = products.reduce((acc, product) => {
|
|
1408
1417
|
const cartProduct = toCartProduct$4(product);
|
|
1409
1418
|
const { priceCategory } = cartProduct;
|
|
@@ -1414,9 +1423,10 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
|
|
|
1414
1423
|
const subtotalNormal = !isPoints ? productTotal.grossPrice : 0;
|
|
1415
1424
|
return {
|
|
1416
1425
|
subtotal: acc.subtotal + subtotalNormal,
|
|
1417
|
-
totalDiscounts: acc.totalDiscounts + productTotal.totalDiscounts,
|
|
1418
|
-
totalTaxes: acc.totalTaxes + productTotal.totalTaxes,
|
|
1419
|
-
|
|
1426
|
+
totalDiscounts: productTotal.totalDiscounts !== null ? Number(acc.totalDiscounts) + productTotal.totalDiscounts : null,
|
|
1427
|
+
totalTaxes: productTotal.totalTaxes !== null ? Number(acc.totalTaxes) + productTotal.totalTaxes : null,
|
|
1428
|
+
shippingCost: null,
|
|
1429
|
+
totalPoints: points !== null ? Number(acc.totalPoints) + points : null,
|
|
1420
1430
|
total: acc.total + normal
|
|
1421
1431
|
};
|
|
1422
1432
|
}, initialValue);
|
|
@@ -1428,8 +1438,8 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
|
|
|
1428
1438
|
const { grossPrice, netPrice, taxTotal, discountTotal } = shippingCost;
|
|
1429
1439
|
const totalsWithShippingCost = {
|
|
1430
1440
|
subtotal: totalsWithBenefits.subtotal + grossPrice,
|
|
1431
|
-
totalDiscounts: totalsWithBenefits.totalDiscounts + discountTotal,
|
|
1432
|
-
totalTaxes: totalsWithBenefits.totalTaxes + taxTotal,
|
|
1441
|
+
totalDiscounts: totalsWithBenefits.totalDiscounts !== null ? totalsWithBenefits.totalDiscounts + discountTotal : discountTotal,
|
|
1442
|
+
totalTaxes: totalsWithBenefits.totalTaxes !== null ? totalsWithBenefits.totalTaxes + taxTotal : taxTotal,
|
|
1433
1443
|
shippingCost: netPrice,
|
|
1434
1444
|
totalPoints: totalsWithBenefits.totalPoints,
|
|
1435
1445
|
total: totalsWithBenefits.total + netPrice
|
|
@@ -1469,7 +1479,7 @@ const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) =>
|
|
|
1469
1479
|
if (typeof (additionalInfo == null ? void 0 : additionalInfo.copayment) !== "undefined") {
|
|
1470
1480
|
const copayment = additionalInfo == null ? void 0 : additionalInfo.copayment;
|
|
1471
1481
|
const totalDiscount2 = copayment * discountPercentage;
|
|
1472
|
-
const newTotalDiscounts2 = prevTotalDiscounts + totalDiscount2;
|
|
1482
|
+
const newTotalDiscounts2 = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount2 : totalDiscount2;
|
|
1473
1483
|
const newTotal2 = (copayment - totalDiscount2).toFixed(4);
|
|
1474
1484
|
return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
|
|
1475
1485
|
totalDiscounts: newTotalDiscounts2,
|
|
@@ -1478,7 +1488,7 @@ const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) =>
|
|
|
1478
1488
|
}
|
|
1479
1489
|
const newSubtotal = subtotal * discountPercentage;
|
|
1480
1490
|
const totalDiscount = newSubtotal;
|
|
1481
|
-
const newTotalDiscounts = prevTotalDiscounts + totalDiscount;
|
|
1491
|
+
const newTotalDiscounts = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount : totalDiscount;
|
|
1482
1492
|
const newTotal = prevTotal - totalDiscount;
|
|
1483
1493
|
return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
|
|
1484
1494
|
totalDiscounts: newTotalDiscounts,
|
|
@@ -1668,6 +1678,9 @@ const getProductTotalTaxes = (product, setAmount) => {
|
|
|
1668
1678
|
const { taxes, grossPrice } = prices[priceCategory];
|
|
1669
1679
|
const taxTotal = getTaxTotal(taxes, grossPrice);
|
|
1670
1680
|
const questionsSum = getModifiersTotalTaxes(cartProduct, setAmount);
|
|
1681
|
+
if (taxTotal === null || questionsSum === null) {
|
|
1682
|
+
return null;
|
|
1683
|
+
}
|
|
1671
1684
|
return questionsSum + taxTotal * amount;
|
|
1672
1685
|
};
|
|
1673
1686
|
const getModifiersTotalTaxes = (product, setAmount) => {
|
|
@@ -1678,7 +1691,7 @@ const getModifiersTotalTaxes = (product, setAmount) => {
|
|
|
1678
1691
|
const { taxes, grossPrice } = prices[priceCategory];
|
|
1679
1692
|
const taxTotal = getTaxTotal(taxes, grossPrice);
|
|
1680
1693
|
const childrenTotal = getModifiersTotalTaxes(answer, setAmount);
|
|
1681
|
-
return acc2 + amount * (taxTotal + childrenTotal);
|
|
1694
|
+
return acc2 + amount * (Number(taxTotal) + childrenTotal);
|
|
1682
1695
|
}, 0);
|
|
1683
1696
|
return acc + answersSum * setAmount;
|
|
1684
1697
|
}, 0)) != null ? _b : 0;
|
|
@@ -1687,7 +1700,7 @@ const getProductGrossPrice = (product, setAmount) => {
|
|
|
1687
1700
|
return getProductFieldPrice(product, "grossPrice", setAmount);
|
|
1688
1701
|
};
|
|
1689
1702
|
const getProductTotalDiscounts = (product, setAmount) => {
|
|
1690
|
-
return
|
|
1703
|
+
return null;
|
|
1691
1704
|
};
|
|
1692
1705
|
const getProductNetPrice = (product, setAmount) => {
|
|
1693
1706
|
return getProductFieldPrice(product, "netPrice", setAmount);
|
|
@@ -1712,6 +1725,9 @@ const getModifiersFieldTotal = (product, field) => {
|
|
|
1712
1725
|
}, 0)) != null ? _b : 0;
|
|
1713
1726
|
};
|
|
1714
1727
|
const getTaxTotal = (taxes, grossPrice) => {
|
|
1728
|
+
if (!taxes.length) {
|
|
1729
|
+
return null;
|
|
1730
|
+
}
|
|
1715
1731
|
return taxes.reduce((acc, tax) => {
|
|
1716
1732
|
return acc + tax.percentage / 100 * grossPrice;
|
|
1717
1733
|
}, 0);
|
|
@@ -4155,7 +4171,7 @@ const initiateCheckout$2 = (provider, params) => {
|
|
|
4155
4171
|
analytics$1().logEvent("begin_checkout", __spreadValues$33(__spreadValues$33({
|
|
4156
4172
|
items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
|
|
4157
4173
|
value: total,
|
|
4158
|
-
points: totalPoints
|
|
4174
|
+
points: totalPoints != null ? totalPoints : 0
|
|
4159
4175
|
}, transformedParams), transformedMeta));
|
|
4160
4176
|
};
|
|
4161
4177
|
|
|
@@ -4205,11 +4221,11 @@ const initiateCheckout$1 = (provider, params) => {
|
|
|
4205
4221
|
const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
|
|
4206
4222
|
analytics.track("Initiate Checkout", __spreadValues$32(__spreadValues$32({
|
|
4207
4223
|
total,
|
|
4208
|
-
revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
|
|
4209
|
-
shipping: shippingCost,
|
|
4210
|
-
tax: totalTaxes,
|
|
4224
|
+
revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
|
|
4225
|
+
shipping: shippingCost != null ? shippingCost : 0,
|
|
4226
|
+
tax: totalTaxes != null ? totalTaxes : 0,
|
|
4211
4227
|
products: mapProductsToSegmentProducts(products),
|
|
4212
|
-
points: totalPoints
|
|
4228
|
+
points: totalPoints != null ? totalPoints : 0
|
|
4213
4229
|
}, transformedParams), transformedMeta));
|
|
4214
4230
|
};
|
|
4215
4231
|
|
|
@@ -4259,7 +4275,7 @@ const initiateCheckout = (provider, params) => {
|
|
|
4259
4275
|
fb_num_items: productsIds.length,
|
|
4260
4276
|
fb_currency: selectedCurrency,
|
|
4261
4277
|
fb_content_type: contentType,
|
|
4262
|
-
points: totalPoints
|
|
4278
|
+
points: totalPoints != null ? totalPoints : 0
|
|
4263
4279
|
}, transformedParams), transformedMeta));
|
|
4264
4280
|
};
|
|
4265
4281
|
|
|
@@ -9822,7 +9838,7 @@ const purchaseAttempt$2 = (provider, params) => {
|
|
|
9822
9838
|
analytics$1().logEvent("purchase_attempt", __spreadValues$18(__spreadValues$18({
|
|
9823
9839
|
products: transformArrayParam(productContents),
|
|
9824
9840
|
value: total,
|
|
9825
|
-
points: totalPoints
|
|
9841
|
+
points: totalPoints != null ? totalPoints : 0
|
|
9826
9842
|
}, transformedParams), transformedMeta));
|
|
9827
9843
|
};
|
|
9828
9844
|
|
|
@@ -9872,11 +9888,11 @@ const purchaseAttempt$1 = (provider, params) => {
|
|
|
9872
9888
|
const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
|
|
9873
9889
|
analytics.track("Purchase Attempt", __spreadValues$17(__spreadValues$17({
|
|
9874
9890
|
total,
|
|
9875
|
-
revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
|
|
9876
|
-
shipping: shippingCost,
|
|
9877
|
-
tax: totalTaxes,
|
|
9891
|
+
revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
|
|
9892
|
+
shipping: shippingCost != null ? shippingCost : 0,
|
|
9893
|
+
tax: totalTaxes != null ? totalTaxes : 0,
|
|
9878
9894
|
products: mapProductsToSegmentProducts(products),
|
|
9879
|
-
points: totalPoints
|
|
9895
|
+
points: totalPoints != null ? totalPoints : 0
|
|
9880
9896
|
}, transformedParams), transformedMeta));
|
|
9881
9897
|
};
|
|
9882
9898
|
|
|
@@ -9926,7 +9942,7 @@ const purchaseAttempt = (provider, params) => {
|
|
|
9926
9942
|
fb_num_items: productsIds.length,
|
|
9927
9943
|
fb_content_type: contentType,
|
|
9928
9944
|
fb_currency: selectedCurrency,
|
|
9929
|
-
points: totalPoints
|
|
9945
|
+
points: totalPoints != null ? totalPoints : 0
|
|
9930
9946
|
}, transformedParams), transformedMeta));
|
|
9931
9947
|
};
|
|
9932
9948
|
|
|
@@ -9987,7 +10003,7 @@ const purchaseFail$2 = (provider, params) => {
|
|
|
9987
10003
|
analytics$1().logEvent("purchase_fail", __spreadValues$15(__spreadValues$15({
|
|
9988
10004
|
products: transformArrayParam(productContents),
|
|
9989
10005
|
value: total,
|
|
9990
|
-
points: totalPoints
|
|
10006
|
+
points: totalPoints != null ? totalPoints : 0
|
|
9991
10007
|
}, transformedParams), transformedMeta));
|
|
9992
10008
|
};
|
|
9993
10009
|
|
|
@@ -10037,11 +10053,11 @@ const purchaseFail$1 = (provider, params) => {
|
|
|
10037
10053
|
const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
|
|
10038
10054
|
analytics.track("Purchase Fail", __spreadValues$14(__spreadValues$14({
|
|
10039
10055
|
total,
|
|
10040
|
-
revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
|
|
10041
|
-
shipping: shippingCost,
|
|
10042
|
-
tax: totalTaxes,
|
|
10056
|
+
revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
|
|
10057
|
+
shipping: shippingCost != null ? shippingCost : 0,
|
|
10058
|
+
tax: totalTaxes != null ? totalTaxes : 0,
|
|
10043
10059
|
products: mapProductsToSegmentProducts(products),
|
|
10044
|
-
points: totalPoints
|
|
10060
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10045
10061
|
}, transformedParams), transformedMeta));
|
|
10046
10062
|
};
|
|
10047
10063
|
|
|
@@ -10091,7 +10107,7 @@ const purchaseFail = (provider, params) => {
|
|
|
10091
10107
|
fb_num_items: productsIds.length,
|
|
10092
10108
|
fb_content_type: contentType,
|
|
10093
10109
|
fb_currency: selectedCurrency,
|
|
10094
|
-
points: totalPoints
|
|
10110
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10095
10111
|
}, transformedParams), transformedMeta));
|
|
10096
10112
|
};
|
|
10097
10113
|
|
|
@@ -10151,10 +10167,10 @@ const purchaseSuccess$2 = (provider, params) => {
|
|
|
10151
10167
|
analytics$1().logEvent("purchase", __spreadValues$12(__spreadValues$12({
|
|
10152
10168
|
items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
|
|
10153
10169
|
value: total,
|
|
10154
|
-
points: totalPoints,
|
|
10170
|
+
points: totalPoints != null ? totalPoints : 0,
|
|
10155
10171
|
transaction_id: orderId,
|
|
10156
|
-
shipping: shippingCost,
|
|
10157
|
-
tax: totalTaxes
|
|
10172
|
+
shipping: shippingCost != null ? shippingCost : 0,
|
|
10173
|
+
tax: totalTaxes != null ? totalTaxes : 0
|
|
10158
10174
|
}, transformedParams), transformedMeta));
|
|
10159
10175
|
};
|
|
10160
10176
|
|
|
@@ -10204,11 +10220,11 @@ const purchaseSuccess$1 = (provider, params) => {
|
|
|
10204
10220
|
const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
|
|
10205
10221
|
analytics.track("Order Completed", __spreadValues$11(__spreadValues$11({
|
|
10206
10222
|
total,
|
|
10207
|
-
revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
|
|
10208
|
-
shipping: shippingCost,
|
|
10209
|
-
tax: totalTaxes,
|
|
10223
|
+
revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
|
|
10224
|
+
shipping: shippingCost != null ? shippingCost : 0,
|
|
10225
|
+
tax: totalTaxes != null ? totalTaxes : 0,
|
|
10210
10226
|
products: mapProductsToSegmentProducts(products),
|
|
10211
|
-
points: totalPoints
|
|
10227
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10212
10228
|
}, transformedParams), transformedMeta));
|
|
10213
10229
|
};
|
|
10214
10230
|
|
|
@@ -10258,7 +10274,7 @@ const purchaseSuccess = (provider, params) => {
|
|
|
10258
10274
|
fb_contents: transformArrayParam(productContents),
|
|
10259
10275
|
fb_num_items: productsIds.length,
|
|
10260
10276
|
fb_content_type: contentType,
|
|
10261
|
-
points: totalPoints
|
|
10277
|
+
points: totalPoints != null ? totalPoints : 0
|
|
10262
10278
|
}, transformedParams), transformedMeta));
|
|
10263
10279
|
};
|
|
10264
10280
|
|