@active-reach/web-sdk 1.46.3 → 1.47.1

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.
@@ -1711,6 +1711,43 @@ class ConsentManager {
1711
1711
  updateGoogleConsent();
1712
1712
  }
1713
1713
  }
1714
+ const ITEM_TOUCH_KEY = "aegis_inapp_item_touch";
1715
+ const ITEM_TOUCH_TTL_MS = 30 * 60 * 1e3;
1716
+ function store() {
1717
+ try {
1718
+ return typeof sessionStorage === "undefined" ? null : sessionStorage;
1719
+ } catch {
1720
+ return null;
1721
+ }
1722
+ }
1723
+ function recordInAppItemTouch(touch) {
1724
+ if (!touch.campaign_id || !touch.sku) return;
1725
+ const s = store();
1726
+ if (!s) return;
1727
+ try {
1728
+ const rec = { ...touch, ts: touch.ts ?? Date.now() };
1729
+ s.setItem(ITEM_TOUCH_KEY, JSON.stringify(rec));
1730
+ } catch {
1731
+ }
1732
+ }
1733
+ function readInAppItemTouch(sku, now = Date.now()) {
1734
+ if (!sku) return null;
1735
+ const s = store();
1736
+ if (!s) return null;
1737
+ try {
1738
+ const raw = s.getItem(ITEM_TOUCH_KEY);
1739
+ if (!raw) return null;
1740
+ const rec = JSON.parse(raw);
1741
+ if (typeof rec.campaign_id !== "string" || typeof rec.sku !== "string" || typeof rec.ts !== "number") {
1742
+ return null;
1743
+ }
1744
+ if (rec.sku !== sku) return null;
1745
+ if (now - rec.ts > ITEM_TOUCH_TTL_MS || now < rec.ts) return null;
1746
+ return rec;
1747
+ } catch {
1748
+ return null;
1749
+ }
1750
+ }
1714
1751
  function sumItems(products) {
1715
1752
  return products.reduce((sum, p) => sum + (p.quantity ?? 1), 0);
1716
1753
  }
@@ -1833,7 +1870,12 @@ class EcommerceTracker {
1833
1870
  // -- Cart --
1834
1871
  addToCart(product) {
1835
1872
  const qty = product.quantity ?? 1;
1873
+ const touch = product.source_campaign_id ? null : readInAppItemTouch(product.sku);
1874
+ const sourceCampaignId = product.source_campaign_id ?? (touch == null ? void 0 : touch.campaign_id);
1836
1875
  this.aegis.track("cart_item_added", {
1876
+ source_campaign_id: sourceCampaignId,
1877
+ source_variant_id: sourceCampaignId ? product.source_variant_id ?? (touch == null ? void 0 : touch.variant_id) : void 0,
1878
+ source_surface: sourceCampaignId ? product.source_surface ?? (touch == null ? void 0 : touch.surface) : void 0,
1837
1879
  product_id: product.product_id,
1838
1880
  sku: product.sku,
1839
1881
  name: product.name,
@@ -3502,8 +3544,9 @@ export {
3502
3544
  RateLimiter as R,
3503
3545
  Storage as S,
3504
3546
  UserNamespace as U,
3547
+ recordInAppItemTouch as a,
3505
3548
  logger as l,
3506
3549
  murmurhash3_x86_32 as m,
3507
3550
  redactUrl as r
3508
3551
  };
3509
- //# sourceMappingURL=analytics-C-Go3Pm5.mjs.map
3552
+ //# sourceMappingURL=analytics-DAZx4Jcj.mjs.map