@azzas/azzas-tracker-web 2.0.0-preview.5 → 2.0.0-preview.6
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/dist/mod.cjs +228 -224
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +6 -2
- package/dist/mod.d.ts +6 -2
- package/dist/mod.global.js +227 -224
- package/dist/mod.global.js.map +1 -1
- package/dist/mod.js +227 -224
- package/dist/mod.js.map +1 -1
- package/dist/mod.vtex.global.js +265 -255
- package/package.json +1 -1
package/dist/mod.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
EVENTS: () => EVENTS,
|
|
24
24
|
default: () => src_default,
|
|
25
|
+
initTracker: () => initTracker,
|
|
25
26
|
trackWebEvent: () => trackWebEvent
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -1369,8 +1370,8 @@ var metaAdapters = {
|
|
|
1369
1370
|
pre_filled: (context) => {
|
|
1370
1371
|
return !!context.preFilled;
|
|
1371
1372
|
},
|
|
1372
|
-
currency: (
|
|
1373
|
-
if (
|
|
1373
|
+
currency: (_, config2) => {
|
|
1374
|
+
if (config2 == null ? void 0 : config2.currency) return config2.currency;
|
|
1374
1375
|
return "BRL";
|
|
1375
1376
|
},
|
|
1376
1377
|
slot_per_line: (context) => {
|
|
@@ -1512,8 +1513,8 @@ var decoAdapter = {
|
|
|
1512
1513
|
}
|
|
1513
1514
|
return null;
|
|
1514
1515
|
},
|
|
1515
|
-
brand: (context) => {
|
|
1516
|
-
if (
|
|
1516
|
+
brand: (context, config2) => {
|
|
1517
|
+
if (config2 == null ? void 0 : config2.brand) return config2.brand;
|
|
1517
1518
|
if (context == null ? void 0 : context.products) {
|
|
1518
1519
|
return normalizeBrand2(context.products.map((p) => {
|
|
1519
1520
|
var _a;
|
|
@@ -1563,210 +1564,8 @@ var decoAdapter = {
|
|
|
1563
1564
|
}
|
|
1564
1565
|
};
|
|
1565
1566
|
|
|
1566
|
-
// src/params/adapters/orderForm/utils.ts
|
|
1567
|
-
var getItemCategory5 = (item) => {
|
|
1568
|
-
var _a;
|
|
1569
|
-
const categories = item == null ? void 0 : item.productCategories;
|
|
1570
|
-
if (!categories) return "Cole\xE7\xE3o";
|
|
1571
|
-
const text = Object.values(categories).join(" ");
|
|
1572
|
-
const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
|
|
1573
|
-
return match != null ? match : "Cole\xE7\xE3o";
|
|
1574
|
-
};
|
|
1575
|
-
var getItemCategory23 = (item) => {
|
|
1576
|
-
var _a, _b;
|
|
1577
|
-
const AVOID_CATEGORIES = /outlet|bazar|sale/i;
|
|
1578
|
-
const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
|
|
1579
|
-
const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
|
|
1580
|
-
const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
|
|
1581
|
-
return capitalize(deepest);
|
|
1582
|
-
};
|
|
1583
|
-
function getItemShippingTier2(orderForm, item) {
|
|
1584
|
-
var _a, _b, _c, _d;
|
|
1585
|
-
const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
|
|
1586
|
-
(li) => li.itemId === item.id
|
|
1587
|
-
);
|
|
1588
|
-
const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
|
|
1589
|
-
return ((_d = selectedSla == null ? void 0 : selectedSla.pickupStoreInfo) == null ? void 0 : _d.friendlyName) ? `retirada em loja: ${selectedSla.pickupStoreInfo.friendlyName}` : (selectedSla == null ? void 0 : selectedSla.name) ? `Receba em casa: ${selectedSla.name}` : null;
|
|
1590
|
-
}
|
|
1591
|
-
var getOrderFormItems = (orderForm) => {
|
|
1592
|
-
const idSelected = orderForm == null ? void 0 : orderForm.selected;
|
|
1593
|
-
return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
|
|
1594
|
-
};
|
|
1595
|
-
|
|
1596
|
-
// src/params/adapters/orderForm/index.ts
|
|
1597
|
-
var orderFormAdapter = {
|
|
1598
|
-
...metaAdapters,
|
|
1599
|
-
items: (context) => {
|
|
1600
|
-
if (context == null ? void 0 : context.items) return context.items;
|
|
1601
|
-
if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
|
|
1602
|
-
return getOrderFormItems(context.orderForm).map((item, index) => {
|
|
1603
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1604
|
-
return {
|
|
1605
|
-
quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
|
|
1606
|
-
index: (_d = (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index) != null ? _d : null,
|
|
1607
|
-
item_brand: (_f = (_e = item.additionalInfo) == null ? void 0 : _e.brandName) != null ? _f : null,
|
|
1608
|
-
item_name: (_g = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _g : null,
|
|
1609
|
-
price: (item == null ? void 0 : item.price) / 100,
|
|
1610
|
-
discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
|
|
1611
|
-
item_variant: (_k = (_j = (_i = (_h = item == null ? void 0 : item.skuName) == null ? void 0 : _h.split(" - ")[0]) == null ? void 0 : _i.split("_").pop()) == null ? void 0 : _j.trim()) != null ? _k : null,
|
|
1612
|
-
item_variant2: (_n = (_m = (_l = item == null ? void 0 : item.skuName) == null ? void 0 : _l.split(" - ")[1]) == null ? void 0 : _m.trim()) != null ? _n : null,
|
|
1613
|
-
item_shipping_tier: getItemShippingTier2(context.orderForm, item),
|
|
1614
|
-
item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
|
|
1615
|
-
item_category: (_o = getItemCategory5(item)) != null ? _o : null,
|
|
1616
|
-
item_category2: (_p = getItemCategory23(item)) != null ? _p : null,
|
|
1617
|
-
item_id: (_q = item == null ? void 0 : item.productId) != null ? _q : null,
|
|
1618
|
-
item_sku: (_r = item == null ? void 0 : item.id) != null ? _r : null,
|
|
1619
|
-
item_url: (_s = item.detailUrl) != null ? _s : null,
|
|
1620
|
-
image_url: (_t = resizeVtexImage2(item.imageUrl)) != null ? _t : null,
|
|
1621
|
-
seller_id: (_u = item == null ? void 0 : item.seller) != null ? _u : null,
|
|
1622
|
-
item_list_name: (_w = (_v = context == null ? void 0 : context.orderForm) == null ? void 0 : _v.item_list_name) != null ? _w : null
|
|
1623
|
-
};
|
|
1624
|
-
});
|
|
1625
|
-
}
|
|
1626
|
-
return null;
|
|
1627
|
-
},
|
|
1628
|
-
brand: (context) => {
|
|
1629
|
-
var _a;
|
|
1630
|
-
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1631
|
-
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
1632
|
-
const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
|
|
1633
|
-
return normalizeBrand2(brands);
|
|
1634
|
-
},
|
|
1635
|
-
line_items: (context) => {
|
|
1636
|
-
var _a;
|
|
1637
|
-
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1638
|
-
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
1639
|
-
return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
|
|
1640
|
-
},
|
|
1641
|
-
value: (context) => {
|
|
1642
|
-
var _a;
|
|
1643
|
-
if (context == null ? void 0 : context.value) return context.value;
|
|
1644
|
-
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
1645
|
-
return getOrderFormItems(context.orderForm).map((item) => (item == null ? void 0 : item.price) / 100 * item.quantity).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1646
|
-
},
|
|
1647
|
-
payment_type: getPaymentType,
|
|
1648
|
-
total_discount: (context) => {
|
|
1649
|
-
var _a, _b;
|
|
1650
|
-
if (context == null ? void 0 : context.total_discount) return context.total_discount;
|
|
1651
|
-
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
1652
|
-
const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
|
|
1653
|
-
const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
|
|
1654
|
-
const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
|
|
1655
|
-
return acc + unitDiscount * item.quantity;
|
|
1656
|
-
}, 0);
|
|
1657
|
-
const discounts = totalsList.find((t) => t.id === "Discounts");
|
|
1658
|
-
return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
|
|
1659
|
-
},
|
|
1660
|
-
subtotal: (context) => {
|
|
1661
|
-
var _a, _b;
|
|
1662
|
-
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1663
|
-
const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
|
|
1664
|
-
return subtotal;
|
|
1665
|
-
},
|
|
1666
|
-
coupon_message: (context) => {
|
|
1667
|
-
var _a;
|
|
1668
|
-
if (context.couponMessage) return context.couponMessage;
|
|
1669
|
-
const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
|
|
1670
|
-
if (messages.length === 0) return null;
|
|
1671
|
-
const couponMessages = messages.filter(
|
|
1672
|
-
(msg) => msg.text.toLowerCase().includes("cupom")
|
|
1673
|
-
);
|
|
1674
|
-
if (couponMessages.length === 0) return null;
|
|
1675
|
-
return couponMessages.map((msg) => msg.text).join(" | ");
|
|
1676
|
-
},
|
|
1677
|
-
zipcode: (context) => {
|
|
1678
|
-
var _a;
|
|
1679
|
-
return (_a = context.zipcode) != null ? _a : null;
|
|
1680
|
-
},
|
|
1681
|
-
flag_pickup: (context) => {
|
|
1682
|
-
var _a;
|
|
1683
|
-
const orderForm = context.orderForm;
|
|
1684
|
-
if (!orderForm) return null;
|
|
1685
|
-
const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
|
|
1686
|
-
const hasPickup = logisticsInfo.some(
|
|
1687
|
-
(info) => {
|
|
1688
|
-
var _a2;
|
|
1689
|
-
return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
|
|
1690
|
-
}
|
|
1691
|
-
);
|
|
1692
|
-
return hasPickup;
|
|
1693
|
-
},
|
|
1694
|
-
shippings: (context) => {
|
|
1695
|
-
if (!context.orderForm) return null;
|
|
1696
|
-
const { items, shippingData } = context.orderForm;
|
|
1697
|
-
const acc = {};
|
|
1698
|
-
shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
|
|
1699
|
-
const item = items[itemIndex];
|
|
1700
|
-
if (!item) return;
|
|
1701
|
-
slas.forEach((sla) => {
|
|
1702
|
-
if (!acc[sla.name]) acc[sla.name] = {
|
|
1703
|
-
shipping_tier: sla.name,
|
|
1704
|
-
delivery_time: parseInt(sla.shippingEstimate),
|
|
1705
|
-
shipping: parseFloat((sla.price / 100).toFixed(1)),
|
|
1706
|
-
line_items: []
|
|
1707
|
-
};
|
|
1708
|
-
acc[sla.name].line_items.push(item.id);
|
|
1709
|
-
});
|
|
1710
|
-
});
|
|
1711
|
-
return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
|
|
1712
|
-
},
|
|
1713
|
-
shipping: (context) => {
|
|
1714
|
-
var _a, _b, _c;
|
|
1715
|
-
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1716
|
-
return logistics.reduce((total, item) => {
|
|
1717
|
-
var _a2, _b2;
|
|
1718
|
-
const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
|
|
1719
|
-
return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
|
|
1720
|
-
}, 0);
|
|
1721
|
-
},
|
|
1722
|
-
shipping_tier: (context) => {
|
|
1723
|
-
var _a, _b, _c;
|
|
1724
|
-
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1725
|
-
const selectedSlas = logistics.map((item) => {
|
|
1726
|
-
var _a2;
|
|
1727
|
-
if (!item.selectedSla) return null;
|
|
1728
|
-
return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
|
|
1729
|
-
}).filter(Boolean);
|
|
1730
|
-
if (selectedSlas.length === 0) return null;
|
|
1731
|
-
const uniqueTiers = Array.from(
|
|
1732
|
-
new Map(
|
|
1733
|
-
selectedSlas.map((sla) => {
|
|
1734
|
-
var _a2;
|
|
1735
|
-
const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
|
|
1736
|
-
return [key, sla];
|
|
1737
|
-
})
|
|
1738
|
-
).values()
|
|
1739
|
-
);
|
|
1740
|
-
const sortedTiers = uniqueTiers.sort((a, b) => {
|
|
1741
|
-
var _a2, _b2;
|
|
1742
|
-
const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1743
|
-
const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1744
|
-
if (aOrder !== bOrder) return aOrder - bOrder;
|
|
1745
|
-
const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
|
|
1746
|
-
const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
|
|
1747
|
-
return aLabel.localeCompare(bLabel, "pt-BR");
|
|
1748
|
-
});
|
|
1749
|
-
const shippingTier = sortedTiers.map((sla) => {
|
|
1750
|
-
var _a2;
|
|
1751
|
-
return sla.deliveryChannel === "pickup-in-point" ? `retirada em loja${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) ? `: ${sla.pickupStoreInfo.friendlyName}` : ""}` : sla.deliveryChannel === "delivery" ? `receba em casa${sla.name ? `: ${sla.name}` : ""}` : null;
|
|
1752
|
-
}).filter(Boolean).join(", ");
|
|
1753
|
-
return shippingTier || null;
|
|
1754
|
-
},
|
|
1755
|
-
transaction_id: (context) => {
|
|
1756
|
-
var _a, _b;
|
|
1757
|
-
return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
|
|
1758
|
-
},
|
|
1759
|
-
coupon: (context) => {
|
|
1760
|
-
var _a, _b;
|
|
1761
|
-
return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
|
|
1762
|
-
},
|
|
1763
|
-
seller_cod_name: (context) => {
|
|
1764
|
-
return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
|
|
1765
|
-
}
|
|
1766
|
-
};
|
|
1767
|
-
|
|
1768
1567
|
// src/params/adapters/headless/utils.ts
|
|
1769
|
-
var
|
|
1568
|
+
var getItemCategory5 = (item) => {
|
|
1770
1569
|
const keywords = ["outlet", "bazar", "sale"];
|
|
1771
1570
|
const regex = new RegExp(keywords.join("|"), "i");
|
|
1772
1571
|
const value = item == null ? void 0 : item.categories;
|
|
@@ -1779,7 +1578,7 @@ var getItemCategory6 = (item) => {
|
|
|
1779
1578
|
}
|
|
1780
1579
|
return "Cole\xE7\xE3o";
|
|
1781
1580
|
};
|
|
1782
|
-
var
|
|
1581
|
+
var getItemCategory23 = (item) => {
|
|
1783
1582
|
var _a, _b, _c;
|
|
1784
1583
|
const avoidList = /outlet|bazar|sale/i;
|
|
1785
1584
|
const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
|
|
@@ -1809,8 +1608,8 @@ var HeadlessPdpZone = {
|
|
|
1809
1608
|
item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
|
|
1810
1609
|
item_ref: (_l = item.productReference) != null ? _l : null,
|
|
1811
1610
|
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
1812
|
-
item_category:
|
|
1813
|
-
item_category2: (_m =
|
|
1611
|
+
item_category: getItemCategory5(item),
|
|
1612
|
+
item_category2: (_m = getItemCategory23(item)) != null ? _m : null,
|
|
1814
1613
|
item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
|
|
1815
1614
|
item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
|
|
1816
1615
|
item_url: (_q = item.link) != null ? _q : null,
|
|
@@ -1840,8 +1639,8 @@ var HeadlessPdpZone = {
|
|
|
1840
1639
|
}
|
|
1841
1640
|
return null;
|
|
1842
1641
|
},
|
|
1843
|
-
brand: (context) => {
|
|
1844
|
-
if (
|
|
1642
|
+
brand: (context, config2) => {
|
|
1643
|
+
if (config2 == null ? void 0 : config2.brand) return config2.brand;
|
|
1845
1644
|
if (context == null ? void 0 : context.products) {
|
|
1846
1645
|
return context.products.map((p) => p.brand).join().trim();
|
|
1847
1646
|
}
|
|
@@ -1870,8 +1669,8 @@ var HeadlessPdcZone = {
|
|
|
1870
1669
|
item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
|
|
1871
1670
|
item_ref: null,
|
|
1872
1671
|
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
1873
|
-
item_category:
|
|
1874
|
-
item_category2: (_j =
|
|
1672
|
+
item_category: getItemCategory5(item),
|
|
1673
|
+
item_category2: (_j = getItemCategory23(item)) != null ? _j : null,
|
|
1875
1674
|
item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
|
|
1876
1675
|
item_sku: (_l = item.sku) != null ? _l : null,
|
|
1877
1676
|
item_url: null,
|
|
@@ -1898,8 +1697,8 @@ var HeadlessPdcZone = {
|
|
|
1898
1697
|
}
|
|
1899
1698
|
return null;
|
|
1900
1699
|
},
|
|
1901
|
-
brand: (context) => {
|
|
1902
|
-
if (
|
|
1700
|
+
brand: (context, config2) => {
|
|
1701
|
+
if (config2 == null ? void 0 : config2.brand) return config2.brand;
|
|
1903
1702
|
if (context == null ? void 0 : context.products) {
|
|
1904
1703
|
return context.products.map((p) => p.brand.name).join().trim();
|
|
1905
1704
|
}
|
|
@@ -1911,14 +1710,12 @@ var HeadlessPdcZone = {
|
|
|
1911
1710
|
var headlessAdapter = {
|
|
1912
1711
|
...metaAdapters,
|
|
1913
1712
|
// global adapters
|
|
1914
|
-
|
|
1915
|
-
// orderForm adapters, confirmar se no storefront tem evento que usa essses params
|
|
1916
|
-
brand: (context) => {
|
|
1713
|
+
brand: (context, config2) => {
|
|
1917
1714
|
if (context.zone === "PDP") {
|
|
1918
|
-
return HeadlessPdpZone.brand(context);
|
|
1715
|
+
return HeadlessPdpZone.brand(context, config2);
|
|
1919
1716
|
}
|
|
1920
1717
|
if (context.zone === "PDC") {
|
|
1921
|
-
return HeadlessPdcZone.brand(context);
|
|
1718
|
+
return HeadlessPdcZone.brand(context, config2);
|
|
1922
1719
|
}
|
|
1923
1720
|
return null;
|
|
1924
1721
|
},
|
|
@@ -2004,6 +1801,208 @@ var pickupAdapter = {
|
|
|
2004
1801
|
}
|
|
2005
1802
|
};
|
|
2006
1803
|
|
|
1804
|
+
// src/params/adapters/orderForm/utils.ts
|
|
1805
|
+
var getItemCategory6 = (item) => {
|
|
1806
|
+
var _a;
|
|
1807
|
+
const categories = item == null ? void 0 : item.productCategories;
|
|
1808
|
+
if (!categories) return "Cole\xE7\xE3o";
|
|
1809
|
+
const text = Object.values(categories).join(" ");
|
|
1810
|
+
const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
|
|
1811
|
+
return match != null ? match : "Cole\xE7\xE3o";
|
|
1812
|
+
};
|
|
1813
|
+
var getItemCategory24 = (item) => {
|
|
1814
|
+
var _a, _b;
|
|
1815
|
+
const AVOID_CATEGORIES = /outlet|bazar|sale/i;
|
|
1816
|
+
const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
|
|
1817
|
+
const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
|
|
1818
|
+
const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
|
|
1819
|
+
return capitalize(deepest);
|
|
1820
|
+
};
|
|
1821
|
+
function getItemShippingTier2(orderForm, item) {
|
|
1822
|
+
var _a, _b, _c, _d;
|
|
1823
|
+
const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
|
|
1824
|
+
(li) => li.itemId === item.id
|
|
1825
|
+
);
|
|
1826
|
+
const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
|
|
1827
|
+
return ((_d = selectedSla == null ? void 0 : selectedSla.pickupStoreInfo) == null ? void 0 : _d.friendlyName) ? `retirada em loja: ${selectedSla.pickupStoreInfo.friendlyName}` : (selectedSla == null ? void 0 : selectedSla.name) ? `Receba em casa: ${selectedSla.name}` : null;
|
|
1828
|
+
}
|
|
1829
|
+
var getOrderFormItems = (orderForm) => {
|
|
1830
|
+
const idSelected = orderForm == null ? void 0 : orderForm.selected;
|
|
1831
|
+
return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
|
|
1832
|
+
};
|
|
1833
|
+
|
|
1834
|
+
// src/params/adapters/orderForm/index.ts
|
|
1835
|
+
var orderFormAdapter = {
|
|
1836
|
+
...metaAdapters,
|
|
1837
|
+
items: (context) => {
|
|
1838
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1839
|
+
if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
|
|
1840
|
+
return getOrderFormItems(context.orderForm).map((item, index) => {
|
|
1841
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1842
|
+
return {
|
|
1843
|
+
quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
|
|
1844
|
+
index: (_d = (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index) != null ? _d : null,
|
|
1845
|
+
item_brand: (_f = (_e = item.additionalInfo) == null ? void 0 : _e.brandName) != null ? _f : null,
|
|
1846
|
+
item_name: (_g = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _g : null,
|
|
1847
|
+
price: (item == null ? void 0 : item.price) / 100,
|
|
1848
|
+
discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
|
|
1849
|
+
item_variant: (_k = (_j = (_i = (_h = item == null ? void 0 : item.skuName) == null ? void 0 : _h.split(" - ")[0]) == null ? void 0 : _i.split("_").pop()) == null ? void 0 : _j.trim()) != null ? _k : null,
|
|
1850
|
+
item_variant2: (_n = (_m = (_l = item == null ? void 0 : item.skuName) == null ? void 0 : _l.split(" - ")[1]) == null ? void 0 : _m.trim()) != null ? _n : null,
|
|
1851
|
+
item_shipping_tier: getItemShippingTier2(context.orderForm, item),
|
|
1852
|
+
item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
|
|
1853
|
+
item_category: (_o = getItemCategory6(item)) != null ? _o : null,
|
|
1854
|
+
item_category2: (_p = getItemCategory24(item)) != null ? _p : null,
|
|
1855
|
+
item_id: (_q = item == null ? void 0 : item.productId) != null ? _q : null,
|
|
1856
|
+
item_sku: (_r = item == null ? void 0 : item.id) != null ? _r : null,
|
|
1857
|
+
item_url: (_s = item.detailUrl) != null ? _s : null,
|
|
1858
|
+
image_url: (_t = resizeVtexImage2(item.imageUrl)) != null ? _t : null,
|
|
1859
|
+
seller_id: (_u = item == null ? void 0 : item.seller) != null ? _u : null,
|
|
1860
|
+
item_list_name: (_w = (_v = context == null ? void 0 : context.orderForm) == null ? void 0 : _v.item_list_name) != null ? _w : null
|
|
1861
|
+
};
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
return null;
|
|
1865
|
+
},
|
|
1866
|
+
brand: (context, config2) => {
|
|
1867
|
+
var _a;
|
|
1868
|
+
if (config2 == null ? void 0 : config2.brand) return config2.brand;
|
|
1869
|
+
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
1870
|
+
const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
|
|
1871
|
+
return normalizeBrand2(brands);
|
|
1872
|
+
},
|
|
1873
|
+
line_items: (context) => {
|
|
1874
|
+
var _a;
|
|
1875
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1876
|
+
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
1877
|
+
return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
|
|
1878
|
+
},
|
|
1879
|
+
value: (context) => {
|
|
1880
|
+
var _a;
|
|
1881
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1882
|
+
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
1883
|
+
return getOrderFormItems(context.orderForm).map((item) => (item == null ? void 0 : item.price) / 100 * item.quantity).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1884
|
+
},
|
|
1885
|
+
payment_type: getPaymentType,
|
|
1886
|
+
total_discount: (context) => {
|
|
1887
|
+
var _a, _b;
|
|
1888
|
+
if (context == null ? void 0 : context.total_discount) return context.total_discount;
|
|
1889
|
+
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
1890
|
+
const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
|
|
1891
|
+
const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
|
|
1892
|
+
const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
|
|
1893
|
+
return acc + unitDiscount * item.quantity;
|
|
1894
|
+
}, 0);
|
|
1895
|
+
const discounts = totalsList.find((t) => t.id === "Discounts");
|
|
1896
|
+
return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
|
|
1897
|
+
},
|
|
1898
|
+
subtotal: (context) => {
|
|
1899
|
+
var _a, _b;
|
|
1900
|
+
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1901
|
+
const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
|
|
1902
|
+
return subtotal;
|
|
1903
|
+
},
|
|
1904
|
+
coupon_message: (context) => {
|
|
1905
|
+
var _a;
|
|
1906
|
+
if (context.couponMessage) return context.couponMessage;
|
|
1907
|
+
const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
|
|
1908
|
+
if (messages.length === 0) return null;
|
|
1909
|
+
const couponMessages = messages.filter(
|
|
1910
|
+
(msg) => msg.text.toLowerCase().includes("cupom")
|
|
1911
|
+
);
|
|
1912
|
+
if (couponMessages.length === 0) return null;
|
|
1913
|
+
return couponMessages.map((msg) => msg.text).join(" | ");
|
|
1914
|
+
},
|
|
1915
|
+
zipcode: (context) => {
|
|
1916
|
+
var _a;
|
|
1917
|
+
return (_a = context.zipcode) != null ? _a : null;
|
|
1918
|
+
},
|
|
1919
|
+
flag_pickup: (context) => {
|
|
1920
|
+
var _a;
|
|
1921
|
+
const orderForm = context.orderForm;
|
|
1922
|
+
if (!orderForm) return null;
|
|
1923
|
+
const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
|
|
1924
|
+
const hasPickup = logisticsInfo.some(
|
|
1925
|
+
(info) => {
|
|
1926
|
+
var _a2;
|
|
1927
|
+
return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
|
|
1928
|
+
}
|
|
1929
|
+
);
|
|
1930
|
+
return hasPickup;
|
|
1931
|
+
},
|
|
1932
|
+
shippings: (context) => {
|
|
1933
|
+
if (!context.orderForm) return null;
|
|
1934
|
+
const { items, shippingData } = context.orderForm;
|
|
1935
|
+
const acc = {};
|
|
1936
|
+
shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
|
|
1937
|
+
const item = items[itemIndex];
|
|
1938
|
+
if (!item) return;
|
|
1939
|
+
slas.forEach((sla) => {
|
|
1940
|
+
if (!acc[sla.name]) acc[sla.name] = {
|
|
1941
|
+
shipping_tier: sla.name,
|
|
1942
|
+
delivery_time: parseInt(sla.shippingEstimate),
|
|
1943
|
+
shipping: parseFloat((sla.price / 100).toFixed(1)),
|
|
1944
|
+
line_items: []
|
|
1945
|
+
};
|
|
1946
|
+
acc[sla.name].line_items.push(item.id);
|
|
1947
|
+
});
|
|
1948
|
+
});
|
|
1949
|
+
return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
|
|
1950
|
+
},
|
|
1951
|
+
shipping: (context) => {
|
|
1952
|
+
var _a, _b, _c;
|
|
1953
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1954
|
+
return logistics.reduce((total, item) => {
|
|
1955
|
+
var _a2, _b2;
|
|
1956
|
+
const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
|
|
1957
|
+
return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
|
|
1958
|
+
}, 0);
|
|
1959
|
+
},
|
|
1960
|
+
shipping_tier: (context) => {
|
|
1961
|
+
var _a, _b, _c;
|
|
1962
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1963
|
+
const selectedSlas = logistics.map((item) => {
|
|
1964
|
+
var _a2;
|
|
1965
|
+
if (!item.selectedSla) return null;
|
|
1966
|
+
return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
|
|
1967
|
+
}).filter(Boolean);
|
|
1968
|
+
if (selectedSlas.length === 0) return null;
|
|
1969
|
+
const uniqueTiers = Array.from(
|
|
1970
|
+
new Map(
|
|
1971
|
+
selectedSlas.map((sla) => {
|
|
1972
|
+
var _a2;
|
|
1973
|
+
const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
|
|
1974
|
+
return [key, sla];
|
|
1975
|
+
})
|
|
1976
|
+
).values()
|
|
1977
|
+
);
|
|
1978
|
+
const sortedTiers = uniqueTiers.sort((a, b) => {
|
|
1979
|
+
var _a2, _b2;
|
|
1980
|
+
const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1981
|
+
const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1982
|
+
if (aOrder !== bOrder) return aOrder - bOrder;
|
|
1983
|
+
const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
|
|
1984
|
+
const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
|
|
1985
|
+
return aLabel.localeCompare(bLabel, "pt-BR");
|
|
1986
|
+
});
|
|
1987
|
+
const shippingTier = sortedTiers.map((sla) => {
|
|
1988
|
+
var _a2;
|
|
1989
|
+
return sla.deliveryChannel === "pickup-in-point" ? `retirada em loja${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) ? `: ${sla.pickupStoreInfo.friendlyName}` : ""}` : sla.deliveryChannel === "delivery" ? `receba em casa${sla.name ? `: ${sla.name}` : ""}` : null;
|
|
1990
|
+
}).filter(Boolean).join(", ");
|
|
1991
|
+
return shippingTier || null;
|
|
1992
|
+
},
|
|
1993
|
+
transaction_id: (context) => {
|
|
1994
|
+
var _a, _b;
|
|
1995
|
+
return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
|
|
1996
|
+
},
|
|
1997
|
+
coupon: (context) => {
|
|
1998
|
+
var _a, _b;
|
|
1999
|
+
return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
|
|
2000
|
+
},
|
|
2001
|
+
seller_cod_name: (context) => {
|
|
2002
|
+
return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
|
|
2003
|
+
}
|
|
2004
|
+
};
|
|
2005
|
+
|
|
2007
2006
|
// src/formatter.ts
|
|
2008
2007
|
var adapters = {
|
|
2009
2008
|
DECO: decoAdapter,
|
|
@@ -2011,7 +2010,7 @@ var adapters = {
|
|
|
2011
2010
|
PICKUP: pickupAdapter,
|
|
2012
2011
|
ORDERFORM: orderFormAdapter
|
|
2013
2012
|
};
|
|
2014
|
-
async function getParameters(context, eventName) {
|
|
2013
|
+
async function getParameters(context, eventName, config2) {
|
|
2015
2014
|
var _a;
|
|
2016
2015
|
const eventConfig = EVENTS[eventName];
|
|
2017
2016
|
if (!eventConfig) return;
|
|
@@ -2024,16 +2023,20 @@ async function getParameters(context, eventName) {
|
|
|
2024
2023
|
console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
|
|
2025
2024
|
return [param, null];
|
|
2026
2025
|
}
|
|
2027
|
-
return [param, await getter(context,
|
|
2026
|
+
return [param, await getter(context, config2)];
|
|
2028
2027
|
})
|
|
2029
2028
|
);
|
|
2030
2029
|
return Object.fromEntries(entries);
|
|
2031
2030
|
}
|
|
2032
2031
|
|
|
2033
2032
|
// src/index.ts
|
|
2033
|
+
var config = { brand: "", currency: "BRL" };
|
|
2034
|
+
function initTracker(c) {
|
|
2035
|
+
config = c;
|
|
2036
|
+
}
|
|
2034
2037
|
async function trackWebEvent(event, context) {
|
|
2035
2038
|
try {
|
|
2036
|
-
const parameters = await getParameters(context, event);
|
|
2039
|
+
const parameters = await getParameters(context, event, config);
|
|
2037
2040
|
if (isDebugMode()) {
|
|
2038
2041
|
console.log(`[DT v2] ${event}, context e parameters: `, {
|
|
2039
2042
|
context,
|
|
@@ -2055,6 +2058,7 @@ var src_default = {
|
|
|
2055
2058
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2056
2059
|
0 && (module.exports = {
|
|
2057
2060
|
EVENTS,
|
|
2061
|
+
initTracker,
|
|
2058
2062
|
trackWebEvent
|
|
2059
2063
|
});
|
|
2060
2064
|
//# sourceMappingURL=mod.cjs.map
|