@azzas/azzas-tracker-web 2.0.0-preview.5 → 2.0.0-preview.7

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.
@@ -23,6 +23,7 @@ var AzzasTracker = (() => {
23
23
  __export(src_exports, {
24
24
  EVENTS: () => EVENTS,
25
25
  default: () => src_default,
26
+ initTracker: () => initTracker,
26
27
  trackWebEvent: () => trackWebEvent
27
28
  });
28
29
 
@@ -1357,9 +1358,6 @@ var AzzasTracker = (() => {
1357
1358
  // src/params/adapters/meta/index.ts
1358
1359
  var metaAdapters = {
1359
1360
  user_info: getUserInfo,
1360
- // brand: (context: MetaBrandContext) => {
1361
- // return context.meta.brand || null;
1362
- // },
1363
1361
  content_type: (context) => {
1364
1362
  return context.meta.content_type || null;
1365
1363
  },
@@ -1369,8 +1367,8 @@ var AzzasTracker = (() => {
1369
1367
  pre_filled: (context) => {
1370
1368
  return !!context.preFilled;
1371
1369
  },
1372
- currency: (context) => {
1373
- if (context == null ? void 0 : context.currency) return context.currency;
1370
+ currency: (_, config2) => {
1371
+ if (config2 == null ? void 0 : config2.currency) return config2.currency;
1374
1372
  return "BRL";
1375
1373
  },
1376
1374
  slot_per_line: (context) => {
@@ -1512,7 +1510,8 @@ var AzzasTracker = (() => {
1512
1510
  }
1513
1511
  return null;
1514
1512
  },
1515
- brand: (context) => {
1513
+ brand: (context, config2) => {
1514
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1516
1515
  if (context == null ? void 0 : context.brand) return context.brand;
1517
1516
  if (context == null ? void 0 : context.products) {
1518
1517
  return normalizeBrand2(context.products.map((p) => {
@@ -1563,210 +1562,8 @@ var AzzasTracker = (() => {
1563
1562
  }
1564
1563
  };
1565
1564
 
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
1565
  // src/params/adapters/headless/utils.ts
1769
- var getItemCategory6 = (item) => {
1566
+ var getItemCategory5 = (item) => {
1770
1567
  const keywords = ["outlet", "bazar", "sale"];
1771
1568
  const regex = new RegExp(keywords.join("|"), "i");
1772
1569
  const value = item == null ? void 0 : item.categories;
@@ -1779,7 +1576,7 @@ var AzzasTracker = (() => {
1779
1576
  }
1780
1577
  return "Cole\xE7\xE3o";
1781
1578
  };
1782
- var getItemCategory24 = (item) => {
1579
+ var getItemCategory23 = (item) => {
1783
1580
  var _a, _b, _c;
1784
1581
  const avoidList = /outlet|bazar|sale/i;
1785
1582
  const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
@@ -1809,8 +1606,8 @@ var AzzasTracker = (() => {
1809
1606
  item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
1810
1607
  item_ref: (_l = item.productReference) != null ? _l : null,
1811
1608
  // sem ref no retorno do IS na multi-lib produtos PDC
1812
- item_category: getItemCategory6(item),
1813
- item_category2: (_m = getItemCategory24(item)) != null ? _m : null,
1609
+ item_category: getItemCategory5(item),
1610
+ item_category2: (_m = getItemCategory23(item)) != null ? _m : null,
1814
1611
  item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
1815
1612
  item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
1816
1613
  item_url: (_q = item.link) != null ? _q : null,
@@ -1840,7 +1637,8 @@ var AzzasTracker = (() => {
1840
1637
  }
1841
1638
  return null;
1842
1639
  },
1843
- brand: (context) => {
1640
+ brand: (context, config2) => {
1641
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1844
1642
  if (context == null ? void 0 : context.brand) return context.brand;
1845
1643
  if (context == null ? void 0 : context.products) {
1846
1644
  return context.products.map((p) => p.brand).join().trim();
@@ -1870,8 +1668,8 @@ var AzzasTracker = (() => {
1870
1668
  item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
1871
1669
  item_ref: null,
1872
1670
  // sem ref no retorno do IS na multi-lib produtos PDC
1873
- item_category: getItemCategory6(item),
1874
- item_category2: (_j = getItemCategory24(item)) != null ? _j : null,
1671
+ item_category: getItemCategory5(item),
1672
+ item_category2: (_j = getItemCategory23(item)) != null ? _j : null,
1875
1673
  item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
1876
1674
  item_sku: (_l = item.sku) != null ? _l : null,
1877
1675
  item_url: null,
@@ -1898,7 +1696,8 @@ var AzzasTracker = (() => {
1898
1696
  }
1899
1697
  return null;
1900
1698
  },
1901
- brand: (context) => {
1699
+ brand: (context, config2) => {
1700
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1902
1701
  if (context == null ? void 0 : context.brand) return context.brand;
1903
1702
  if (context == null ? void 0 : context.products) {
1904
1703
  return context.products.map((p) => p.brand.name).join().trim();
@@ -1911,14 +1710,12 @@ var AzzasTracker = (() => {
1911
1710
  var headlessAdapter = {
1912
1711
  ...metaAdapters,
1913
1712
  // global adapters
1914
- ...orderFormAdapter,
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,209 @@ var AzzasTracker = (() => {
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 (context == null ? void 0 : context.brand) return context.brand;
1870
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1871
+ const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
1872
+ return normalizeBrand2(brands);
1873
+ },
1874
+ line_items: (context) => {
1875
+ var _a;
1876
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1877
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1878
+ return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
1879
+ },
1880
+ value: (context) => {
1881
+ var _a;
1882
+ if (context == null ? void 0 : context.value) return context.value;
1883
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1884
+ 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);
1885
+ },
1886
+ payment_type: getPaymentType,
1887
+ total_discount: (context) => {
1888
+ var _a, _b;
1889
+ if (context == null ? void 0 : context.total_discount) return context.total_discount;
1890
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1891
+ const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
1892
+ const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
1893
+ const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1894
+ return acc + unitDiscount * item.quantity;
1895
+ }, 0);
1896
+ const discounts = totalsList.find((t) => t.id === "Discounts");
1897
+ return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1898
+ },
1899
+ subtotal: (context) => {
1900
+ var _a, _b;
1901
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1902
+ const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1903
+ return subtotal;
1904
+ },
1905
+ coupon_message: (context) => {
1906
+ var _a;
1907
+ if (context.couponMessage) return context.couponMessage;
1908
+ const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1909
+ if (messages.length === 0) return null;
1910
+ const couponMessages = messages.filter(
1911
+ (msg) => msg.text.toLowerCase().includes("cupom")
1912
+ );
1913
+ if (couponMessages.length === 0) return null;
1914
+ return couponMessages.map((msg) => msg.text).join(" | ");
1915
+ },
1916
+ zipcode: (context) => {
1917
+ var _a;
1918
+ return (_a = context.zipcode) != null ? _a : null;
1919
+ },
1920
+ flag_pickup: (context) => {
1921
+ var _a;
1922
+ const orderForm = context.orderForm;
1923
+ if (!orderForm) return null;
1924
+ const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1925
+ const hasPickup = logisticsInfo.some(
1926
+ (info) => {
1927
+ var _a2;
1928
+ return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1929
+ }
1930
+ );
1931
+ return hasPickup;
1932
+ },
1933
+ shippings: (context) => {
1934
+ if (!context.orderForm) return null;
1935
+ const { items, shippingData } = context.orderForm;
1936
+ const acc = {};
1937
+ shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
1938
+ const item = items[itemIndex];
1939
+ if (!item) return;
1940
+ slas.forEach((sla) => {
1941
+ if (!acc[sla.name]) acc[sla.name] = {
1942
+ shipping_tier: sla.name,
1943
+ delivery_time: parseInt(sla.shippingEstimate),
1944
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
1945
+ line_items: []
1946
+ };
1947
+ acc[sla.name].line_items.push(item.id);
1948
+ });
1949
+ });
1950
+ return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
1951
+ },
1952
+ shipping: (context) => {
1953
+ var _a, _b, _c;
1954
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1955
+ return logistics.reduce((total, item) => {
1956
+ var _a2, _b2;
1957
+ const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1958
+ return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1959
+ }, 0);
1960
+ },
1961
+ shipping_tier: (context) => {
1962
+ var _a, _b, _c;
1963
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1964
+ const selectedSlas = logistics.map((item) => {
1965
+ var _a2;
1966
+ if (!item.selectedSla) return null;
1967
+ return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1968
+ }).filter(Boolean);
1969
+ if (selectedSlas.length === 0) return null;
1970
+ const uniqueTiers = Array.from(
1971
+ new Map(
1972
+ selectedSlas.map((sla) => {
1973
+ var _a2;
1974
+ const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1975
+ return [key, sla];
1976
+ })
1977
+ ).values()
1978
+ );
1979
+ const sortedTiers = uniqueTiers.sort((a, b) => {
1980
+ var _a2, _b2;
1981
+ const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1982
+ const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1983
+ if (aOrder !== bOrder) return aOrder - bOrder;
1984
+ const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1985
+ const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1986
+ return aLabel.localeCompare(bLabel, "pt-BR");
1987
+ });
1988
+ const shippingTier = sortedTiers.map((sla) => {
1989
+ var _a2;
1990
+ 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;
1991
+ }).filter(Boolean).join(", ");
1992
+ return shippingTier || null;
1993
+ },
1994
+ transaction_id: (context) => {
1995
+ var _a, _b;
1996
+ return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1997
+ },
1998
+ coupon: (context) => {
1999
+ var _a, _b;
2000
+ return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
2001
+ },
2002
+ seller_cod_name: (context) => {
2003
+ return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
2004
+ }
2005
+ };
2006
+
2007
2007
  // src/formatter.ts
2008
2008
  var adapters = {
2009
2009
  DECO: decoAdapter,
@@ -2011,7 +2011,7 @@ var AzzasTracker = (() => {
2011
2011
  PICKUP: pickupAdapter,
2012
2012
  ORDERFORM: orderFormAdapter
2013
2013
  };
2014
- async function getParameters(context, eventName) {
2014
+ async function getParameters(context, eventName, config2) {
2015
2015
  var _a;
2016
2016
  const eventConfig = EVENTS[eventName];
2017
2017
  if (!eventConfig) return;
@@ -2024,16 +2024,20 @@ var AzzasTracker = (() => {
2024
2024
  console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
2025
2025
  return [param, null];
2026
2026
  }
2027
- return [param, await getter(context, eventName)];
2027
+ return [param, await getter(context, config2)];
2028
2028
  })
2029
2029
  );
2030
2030
  return Object.fromEntries(entries);
2031
2031
  }
2032
2032
 
2033
2033
  // src/index.ts
2034
+ var config = { brand: "", currency: "BRL" };
2035
+ function initTracker(c) {
2036
+ config = c;
2037
+ }
2034
2038
  async function trackWebEvent(event, context) {
2035
2039
  try {
2036
- const parameters = await getParameters(context, event);
2040
+ const parameters = await getParameters(context, event, config);
2037
2041
  if (isDebugMode()) {
2038
2042
  console.log(`[DT v2] ${event}, context e parameters: `, {
2039
2043
  context,