@bidspark/analytics 0.44.0 → 0.46.0

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/index.mjs CHANGED
@@ -1035,6 +1035,33 @@ function isVisitorSampled(visitorKey, sampleRate) {
1035
1035
  }
1036
1036
  return (hash >>> 0) / 4294967296 < rate;
1037
1037
  }
1038
+ var AUTOMATED_UA_RE = /headless|phantomjs|slimerjs|puppeteer|playwright/i;
1039
+ var DESKTOP_CHROME_UA_RE = /Chrome\/\d+/i;
1040
+ var NON_DESKTOP_CHROME_UA_RE = /Mobile|Android|iPhone|iPad|iPod|CriOS|FxiOS|Edg\/|OPR\/|SamsungBrowser/i;
1041
+ function isAutomatedClient() {
1042
+ const g = typeof globalThis !== "undefined" ? globalThis : void 0;
1043
+ const nav = g && "navigator" in g ? g.navigator : void 0;
1044
+ if (!nav) return false;
1045
+ if (nav.webdriver === true) return true;
1046
+ const ua = typeof nav.userAgent === "string" ? nav.userAgent : "";
1047
+ if (AUTOMATED_UA_RE.test(ua)) return true;
1048
+ const win = g && "window" in g ? g.window : g;
1049
+ let weakSignals = 0;
1050
+ if (win && typeof win.outerWidth === "number" && typeof win.outerHeight === "number" && win.outerWidth === 0 && win.outerHeight === 0) {
1051
+ weakSignals++;
1052
+ }
1053
+ if (Array.isArray(nav.languages) && nav.languages.length === 0) {
1054
+ weakSignals++;
1055
+ }
1056
+ if (DESKTOP_CHROME_UA_RE.test(ua) && !NON_DESKTOP_CHROME_UA_RE.test(ua)) {
1057
+ if (win && !win.chrome) weakSignals++;
1058
+ const plugins = nav.plugins;
1059
+ if (plugins !== void 0 && plugins !== null && plugins.length === 0) {
1060
+ weakSignals++;
1061
+ }
1062
+ }
1063
+ return weakSignals >= 2;
1064
+ }
1038
1065
 
1039
1066
  // ../../protogen/usage_event.ts
1040
1067
  var usage_event_exports = {};
@@ -1201,7 +1228,7 @@ function sendEvents(opts) {
1201
1228
  bidderOutcomes: []
1202
1229
  }));
1203
1230
  const nav = g && "navigator" in g ? g.navigator : void 0;
1204
- const automated = Boolean(nav && nav.webdriver === true);
1231
+ const automated = isAutomatedClient();
1205
1232
  const batch = {
1206
1233
  propertyId: idToBytes(opts.propertyId),
1207
1234
  pageviewId: idToBytes(pageviewId),
@@ -1439,9 +1466,11 @@ var CLICK_DEDUP_MS = 1e3;
1439
1466
  var SESSION_KEY = "ads_session";
1440
1467
  var SESSION_TS_KEY = "ads_session_ts";
1441
1468
  var THIRTY_MINUTES_MS = 30 * 60 * 1e3;
1469
+ var PAGE_EVENT_NAME_RE = /^[a-zA-Z0-9:_.-]{1,64}$/;
1442
1470
  var inMemorySessionId = null;
1443
1471
  var inMemorySessionTs = 0;
1444
1472
  var sessionStartedHere = false;
1473
+ var announcedSessionId = "";
1445
1474
  var storageAllowed = true;
1446
1475
  function generateUUID2() {
1447
1476
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
@@ -1505,6 +1534,15 @@ function sameEndpointOrigin(a, b) {
1505
1534
  return false;
1506
1535
  }
1507
1536
  }
1537
+ function normalizePageUrl(raw) {
1538
+ if (!raw) return "";
1539
+ try {
1540
+ const u = new URL(raw);
1541
+ return u.origin + u.pathname;
1542
+ } catch {
1543
+ return raw;
1544
+ }
1545
+ }
1508
1546
  var SESSION_PERSIST_INTERVAL_MS = 60 * 1e3;
1509
1547
  var persistedSessionTs = 0;
1510
1548
  var ACTIVITY_EVENTS = ["pointerdown", "pointermove", "keydown", "scroll", "wheel", "touchstart"];
@@ -1614,7 +1652,7 @@ function getOrCreateUserId() {
1614
1652
  if (storageAllowed && typeof localStorage !== "undefined") {
1615
1653
  const stored = localStorage.getItem(USER_ID_KEY);
1616
1654
  if (stored) return stored;
1617
- const newId = generateUUID2();
1655
+ const newId = inMemorySessionId || generateUUID2();
1618
1656
  localStorage.setItem(USER_ID_KEY, newId);
1619
1657
  return newId;
1620
1658
  }
@@ -1648,6 +1686,16 @@ function tcDataToConsentRecord(tcData) {
1648
1686
  purposesConsented: purposes
1649
1687
  };
1650
1688
  }
1689
+ function resolveTcfStorageAllowed(tcData, success) {
1690
+ if (!success || !tcData) return void 0;
1691
+ if (tcData.eventStatus === "cmpuishown" && !tcData.tcString) return false;
1692
+ const allowed = storageAllowedBy(tcDataToConsentRecord(tcData));
1693
+ if (!allowed) {
1694
+ clearStoredSession();
1695
+ clearStoredUserId();
1696
+ }
1697
+ return allowed;
1698
+ }
1651
1699
  function probeTcfStorageAllowed() {
1652
1700
  if (typeof window === "undefined") return void 0;
1653
1701
  const win = window;
@@ -1655,27 +1703,22 @@ function probeTcfStorageAllowed() {
1655
1703
  let allowed = void 0;
1656
1704
  try {
1657
1705
  win.__tcfapi("getTCData", 2, (tcData, success) => {
1658
- if (success && tcData) {
1659
- allowed = storageAllowedBy(tcDataToConsentRecord(tcData));
1660
- }
1706
+ allowed = resolveTcfStorageAllowed(tcData, success);
1661
1707
  });
1662
1708
  } catch {
1663
1709
  }
1664
1710
  return allowed !== void 0 ? allowed : false;
1665
1711
  }
1666
- var tcfListenerAttached = false;
1667
- function resetTcfListener() {
1668
- tcfListenerAttached = false;
1669
- }
1712
+ var attachedTcfApi = null;
1670
1713
  function attachTcfListener() {
1671
- if (tcfListenerAttached || typeof window === "undefined") return;
1714
+ if (typeof window === "undefined") return;
1672
1715
  const win = window;
1673
- if (typeof win.__tcfapi !== "function") return;
1674
- tcfListenerAttached = true;
1716
+ if (typeof win.__tcfapi !== "function" || attachedTcfApi === win.__tcfapi) return;
1717
+ attachedTcfApi = win.__tcfapi;
1675
1718
  try {
1676
1719
  win.__tcfapi("addEventListener", 2, (tcData, success) => {
1677
- if (!success || !tcData) return;
1678
- BidsparkPrebidAnalytics.setStorageAllowed(storageAllowedBy(tcDataToConsentRecord(tcData)));
1720
+ const allowed = resolveTcfStorageAllowed(tcData, success);
1721
+ if (allowed !== void 0) BidsparkPrebidAnalytics.setStorageAllowed(allowed);
1679
1722
  });
1680
1723
  } catch {
1681
1724
  }
@@ -1766,19 +1809,31 @@ var PrebidEventDeduper = class {
1766
1809
  }
1767
1810
  };
1768
1811
  function parseBidDimensions(bid) {
1769
- if (Number.isFinite(bid?.width) && Number.isFinite(bid?.height)) {
1812
+ if (Number.isFinite(bid?.width) && bid.width > 0 && Number.isFinite(bid?.height) && bid.height > 0) {
1770
1813
  return { width: bid.width, height: bid.height };
1771
1814
  }
1815
+ if (Number.isFinite(bid?.w) && bid.w > 0 && Number.isFinite(bid?.h) && bid.h > 0) {
1816
+ return { width: bid.w, height: bid.h };
1817
+ }
1818
+ if (Number.isFinite(bid?.playerWidth) && bid.playerWidth > 0 && Number.isFinite(bid?.playerHeight) && bid.playerHeight > 0) {
1819
+ return { width: bid.playerWidth, height: bid.playerHeight };
1820
+ }
1821
+ const ps = bid?.mediaTypes?.video?.playerSize;
1822
+ if (Array.isArray(ps) && ps.length > 0) {
1823
+ const tuple = Array.isArray(ps[0]) ? ps[0] : ps;
1824
+ if (Number.isFinite(tuple[0]) && tuple[0] > 0 && Number.isFinite(tuple[1]) && tuple[1] > 0) {
1825
+ return { width: tuple[0], height: tuple[1] };
1826
+ }
1827
+ }
1772
1828
  if (typeof bid?.size === "string") {
1773
1829
  const match = bid.size.match(/^(\d+)x(\d+)$/);
1774
1830
  if (match) {
1775
1831
  return { width: Number(match[1]), height: Number(match[2]) };
1776
1832
  }
1777
1833
  }
1778
- return {
1779
- width: Number.isFinite(bid?.width) ? bid.width : 0,
1780
- height: Number.isFinite(bid?.height) ? bid.height : 0
1781
- };
1834
+ const w = Number.isFinite(bid?.width) ? bid.width : Number.isFinite(bid?.w) ? bid.w : Number.isFinite(bid?.playerWidth) ? bid.playerWidth : 0;
1835
+ const h = Number.isFinite(bid?.height) ? bid.height : Number.isFinite(bid?.h) ? bid.h : Number.isFinite(bid?.playerHeight) ? bid.playerHeight : 0;
1836
+ return { width: w, height: h };
1782
1837
  }
1783
1838
  function resolveBidPricing(bid, fallback) {
1784
1839
  if (Number.isFinite(bid?.cpm)) {
@@ -1823,14 +1878,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
1823
1878
  storageAllowed = allowed;
1824
1879
  persistedSessionTs = 0;
1825
1880
  for (const inst of _BidsparkPrebidAnalytics.allInstances) {
1826
- inst.config.storageAllowed = allowed;
1827
- if (!allowed) {
1828
- inst.config.userId = "";
1829
- inst.config.visitorId = inst.config.visitorId || inst.config.pageviewId;
1830
- } else if (!inst.config.userId) {
1831
- inst.config.userId = getOrCreateUserId();
1832
- inst.config.visitorId = inst.config.visitorId || inst.config.userId || inst.config.pageviewId;
1833
- }
1881
+ inst.applyStorageAllowed(allowed);
1834
1882
  }
1835
1883
  }
1836
1884
  static isStorageAllowed() {
@@ -1877,10 +1925,16 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
1877
1925
  recordedConsentKeys = /* @__PURE__ */ new Set();
1878
1926
  consentCount = 0;
1879
1927
  cmpDetach = null;
1928
+ sessionResumeUnsub = null;
1880
1929
  pageviewEmitted = false;
1881
1930
  logger;
1882
1931
  // True when managing session lifecycle internally; false if caller supplied fixed sessionId.
1883
1932
  managesSessionId;
1933
+ configuredUserId;
1934
+ // True when visitor sampling key is derived internally from storage/session rather than caller config.
1935
+ managesVisitorId;
1936
+ // True once visitorId is settled (storage read, caller-supplied, or first batch drained).
1937
+ visitorKeyLocked;
1884
1938
  constructor(config) {
1885
1939
  const tcfStorage = probeTcfStorageAllowed();
1886
1940
  if (typeof window !== "undefined" && typeof window.__tcfapi === "function") {
@@ -1894,32 +1948,33 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
1894
1948
  const requestedEndpoint = config.endpoint || "";
1895
1949
  const endpoint = !requestedEndpoint || isTrustedEndpoint(requestedEndpoint) ? requestedEndpoint : "";
1896
1950
  const pageviewId = config.pageviewId || generateUUID2();
1951
+ recordActivity();
1952
+ this.managesSessionId = !config.sessionId;
1953
+ const sessionId = config.sessionId || getOrCreateSessionId();
1954
+ this.configuredUserId = config.userId || "";
1897
1955
  let initialUserId = "";
1898
- let initialVisitorId = "";
1899
1956
  if (isStorageOn) {
1900
- initialUserId = config.userId || getOrCreateUserId();
1901
- if (config.userId) {
1957
+ initialUserId = this.configuredUserId || getOrCreateUserId();
1958
+ if (this.configuredUserId) {
1902
1959
  try {
1903
1960
  if (typeof localStorage !== "undefined") {
1904
- localStorage.setItem(USER_ID_KEY, config.userId);
1961
+ localStorage.setItem(USER_ID_KEY, this.configuredUserId);
1905
1962
  }
1906
1963
  } catch {
1907
1964
  }
1908
1965
  }
1909
- initialVisitorId = config.visitorId || initialUserId || pageviewId;
1910
- } else {
1911
- initialUserId = "";
1912
- initialVisitorId = config.visitorId || pageviewId;
1913
1966
  }
1967
+ this.managesVisitorId = !config.visitorId && !config.userId && !config.sessionId;
1968
+ this.visitorKeyLocked = isStorageOn || !this.managesVisitorId;
1914
1969
  const usageEndpoint = config.usageEndpoint || "";
1915
1970
  this.config = {
1916
1971
  endpoint,
1917
1972
  usageEndpoint,
1918
1973
  propertyId: config.propertyId || "",
1919
1974
  pageviewId,
1920
- sessionId: config.sessionId || "",
1975
+ sessionId,
1921
1976
  userId: initialUserId,
1922
- visitorId: initialVisitorId,
1977
+ visitorId: config.visitorId || this.configuredUserId || initialUserId || sessionId,
1923
1978
  deviceType: config.deviceType || "desktop",
1924
1979
  country: config.country || "",
1925
1980
  region: config.region || "",
@@ -1932,16 +1987,14 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
1932
1987
  pbjsGlobalName: config.pbjsGlobalName || "pbjs",
1933
1988
  attachPbjsListeners: config.attachPbjsListeners ?? true,
1934
1989
  revenueFlushDelayMs: Number.isFinite(config.revenueFlushDelayMs) && config.revenueFlushDelayMs >= 0 ? config.revenueFlushDelayMs : REVENUE_FLUSH_DELAY_MS,
1935
- alias: config.alias || DEFAULT_ALIAS
1990
+ alias: config.alias || DEFAULT_ALIAS,
1991
+ events: config.events || {}
1936
1992
  };
1937
1993
  _BidsparkPrebidAnalytics.allInstances.add(this);
1938
1994
  this.logger = createLogger({
1939
1995
  prefix: "[analytics]",
1940
1996
  logLevel: this.config.logLevel
1941
1997
  });
1942
- recordActivity();
1943
- this.managesSessionId = !config.sessionId;
1944
- if (this.managesSessionId) this.config.sessionId = getOrCreateSessionId();
1945
1998
  if (requestedEndpoint && !endpoint) {
1946
1999
  this.log(
1947
2000
  "ERROR",
@@ -1954,6 +2007,31 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
1954
2007
  };
1955
2008
  this.boundVisibilityChange = () => this.handleVisibilityChange();
1956
2009
  }
2010
+ applyStorageAllowed(allowed) {
2011
+ this.config.storageAllowed = allowed;
2012
+ if (!allowed) {
2013
+ this.config.userId = "";
2014
+ return;
2015
+ }
2016
+ this.syncSessionId();
2017
+ if (!this.config.userId) {
2018
+ this.config.userId = this.configuredUserId || getOrCreateUserId();
2019
+ }
2020
+ if (this.managesVisitorId && !this.visitorKeyLocked) {
2021
+ this.config.visitorId = this.config.userId || this.config.sessionId;
2022
+ this.visitorKeyLocked = true;
2023
+ if (!this.isSampledVisitor()) {
2024
+ this.queue = [];
2025
+ if (this.revenueFlushTimer) {
2026
+ clearTimeout(this.revenueFlushTimer);
2027
+ this.revenueFlushTimer = null;
2028
+ }
2029
+ }
2030
+ }
2031
+ if (this.isEnabled) {
2032
+ this.resendPersistedBatches();
2033
+ }
2034
+ }
1957
2035
  setLogLevel(level) {
1958
2036
  const norm = normalizeLogLevel(level);
1959
2037
  this.config.logLevel = norm;
@@ -1967,6 +2045,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
1967
2045
  if (this.isEnabled) return;
1968
2046
  this.isEnabled = true;
1969
2047
  _BidsparkPrebidAnalytics.activeInstances.add(this);
2048
+ _BidsparkPrebidAnalytics.allInstances.add(this);
1970
2049
  this.logger.setLevel(this.config.logLevel);
1971
2050
  if (this.config.attachPbjsListeners && this.config.usageEndpoint && !this.usageRecorder) {
1972
2051
  this.usageRecorder = new UsageRecorder({
@@ -1996,20 +2075,18 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
1996
2075
  this.cmpDetach = this.attachCmp();
1997
2076
  if (typeof window !== "undefined") {
1998
2077
  if (!this.pageUrl) {
1999
- try {
2000
- const u = new URL(window.location.href);
2001
- this.pageUrl = u.origin + u.pathname;
2002
- } catch {
2003
- this.pageUrl = window.location.href;
2004
- }
2078
+ this.pageUrl = normalizePageUrl(window.location.href);
2005
2079
  }
2006
2080
  window.addEventListener("pagehide", this.boundFlushBeacon);
2007
2081
  if (typeof document !== "undefined") {
2008
2082
  document.addEventListener("visibilitychange", this.boundVisibilityChange);
2009
2083
  }
2010
2084
  bindActivityListeners();
2085
+ this.sessionResumeUnsub = onSessionResume(() => this.syncSessionAndRotateVisitor());
2086
+ this.syncSessionId();
2011
2087
  if (!this.pageviewEmitted) {
2012
2088
  this.pageviewEmitted = true;
2089
+ this.emitPageEvent("pageview");
2013
2090
  this.enqueue(TraceEventType.PAGEVIEW, "pageview", {});
2014
2091
  }
2015
2092
  this.flushTimer = setInterval(() => this.flush(), FLUSH_INTERVAL_MS);
@@ -2151,6 +2228,8 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
2151
2228
  }
2152
2229
  this.cmpDetach = null;
2153
2230
  }
2231
+ this.sessionResumeUnsub?.();
2232
+ this.sessionResumeUnsub = null;
2154
2233
  this.flush();
2155
2234
  }
2156
2235
  handleVisibilityChange() {
@@ -2619,7 +2698,15 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
2619
2698
  hasImpressionEmitted(slotId, refreshIndex, auctionId, creativeId, adId) {
2620
2699
  const rIndex = refreshIndex ?? this.slotRefreshIndices.get(slotId) ?? 0;
2621
2700
  const baseSlotKey = `${escapeKeyPart(slotId)}:${rIndex}`;
2701
+ if (auctionId ? this.slotEmittedImpressionKeys.has(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}`) : this.slotEmittedImpressionKeys.has(baseSlotKey)) {
2702
+ return true;
2703
+ }
2622
2704
  if (adId) {
2705
+ if (auctionId && this.slotEmittedImpressionKeys.has(
2706
+ `${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:render`
2707
+ ) || this.slotEmittedImpressionKeys.has(`${baseSlotKey}:render`)) {
2708
+ return true;
2709
+ }
2623
2710
  if (auctionId) {
2624
2711
  if (this.slotEmittedImpressionKeys.has(
2625
2712
  `${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:ad:${escapeKeyPart(adId)}`
@@ -2642,6 +2729,11 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
2642
2729
  }
2643
2730
  return false;
2644
2731
  }
2732
+ if (auctionId && this.slotEmittedImpressionKeys.has(
2733
+ `${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:ad-emitted`
2734
+ ) || this.slotEmittedImpressionKeys.has(`${baseSlotKey}:ad-emitted`)) {
2735
+ return true;
2736
+ }
2645
2737
  if (creativeId) {
2646
2738
  if (auctionId) {
2647
2739
  return this.slotEmittedImpressionKeys.has(
@@ -2650,10 +2742,10 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
2650
2742
  }
2651
2743
  return this.slotEmittedImpressionKeys.has(`${baseSlotKey}:${escapeKeyPart(creativeId)}`);
2652
2744
  }
2653
- if (auctionId) {
2654
- return this.slotEmittedImpressionKeys.has(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}`);
2745
+ if (auctionId && this.slotEmittedImpressionKeys.has(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:any`)) {
2746
+ return true;
2655
2747
  }
2656
- return this.slotEmittedImpressionKeys.has(baseSlotKey);
2748
+ return false;
2657
2749
  }
2658
2750
  markImpressionEmitted(slotId, refreshIndex, auctionId, creativeId, adId) {
2659
2751
  const baseSlotKey = `${escapeKeyPart(slotId)}:${refreshIndex}`;
@@ -2661,10 +2753,13 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
2661
2753
  if (hasIdentity) {
2662
2754
  if (adId) {
2663
2755
  this.addImpressionKey(`${baseSlotKey}:ad:${escapeKeyPart(adId)}`);
2756
+ this.addImpressionKey(`${baseSlotKey}:ad-emitted`);
2664
2757
  if (auctionId) {
2665
2758
  this.addImpressionKey(
2666
2759
  `${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:ad:${escapeKeyPart(adId)}`
2667
2760
  );
2761
+ this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:any`);
2762
+ this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:ad-emitted`);
2668
2763
  }
2669
2764
  }
2670
2765
  if (creativeId && creativeId !== adId) {
@@ -2673,15 +2768,21 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
2673
2768
  this.addImpressionKey(
2674
2769
  `${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:${escapeKeyPart(creativeId)}`
2675
2770
  );
2771
+ this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:any`);
2676
2772
  }
2677
2773
  }
2678
- if (auctionId) {
2679
- this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}`);
2774
+ if (!adId) {
2775
+ this.addImpressionKey(`${baseSlotKey}:render`);
2776
+ if (auctionId) {
2777
+ this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:render`);
2778
+ }
2680
2779
  }
2681
2780
  } else {
2682
2781
  this.addImpressionKey(baseSlotKey);
2782
+ this.addImpressionKey(`${baseSlotKey}:render`);
2683
2783
  if (auctionId) {
2684
2784
  this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}`);
2785
+ this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:render`);
2685
2786
  }
2686
2787
  }
2687
2788
  }
@@ -2708,8 +2809,8 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
2708
2809
  ...parseBidDimensions(rawBid).width ? parseBidDimensions(rawBid) : cached?.bidTrace ? { width: cached.bidTrace.width, height: cached.bidTrace.height } : parseBidDimensions(rawBid),
2709
2810
  dealId: rawBid.dealId || cached?.bidTrace?.dealId || "",
2710
2811
  mediaType,
2711
- latencyMs: Number.isFinite(rawBid.timeToRespond) ? rawBid.timeToRespond : cached?.bidTrace?.latencyMs ?? 0,
2712
- advertiserDomain: rawBid.meta?.advertiserDomains?.[0] || cached?.bidTrace?.advertiserDomain || "",
2812
+ latencyMs: Number.isFinite(rawBid.timeToRespond) ? rawBid.timeToRespond : Number.isFinite(rawBid.latencyMs) ? rawBid.latencyMs : cached?.bidTrace?.latencyMs ?? 0,
2813
+ advertiserDomain: rawBid.advertiserDomain || rawBid.meta?.advertiserDomains?.[0] || (Array.isArray(rawBid.adomain) ? rawBid.adomain[0] : "") || cached?.bidTrace?.advertiserDomain || "",
2713
2814
  creativeId: rawBid.creativeId || cached?.bidTrace?.creativeId || ""
2714
2815
  };
2715
2816
  if (isDifferentAuction && targetSlot) {
@@ -2880,16 +2981,16 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
2880
2981
  const handler = (evt) => {
2881
2982
  const detail = evt.detail;
2882
2983
  if (detail) {
2883
- this.recordConsent(detail);
2884
2984
  this.followConsent(detail);
2985
+ this.recordConsent(detail);
2885
2986
  }
2886
2987
  };
2887
2988
  document.addEventListener("ads:consent", handler);
2888
2989
  const win = typeof window !== "undefined" ? window : {};
2889
2990
  const existingRecord = win[this.config.alias]?.consent?.getRecord?.() || null;
2890
2991
  if (existingRecord) {
2891
- this.recordConsent(existingRecord);
2892
2992
  this.followConsent(existingRecord);
2993
+ this.recordConsent(existingRecord);
2893
2994
  }
2894
2995
  let detached = false;
2895
2996
  return () => {
@@ -2898,15 +2999,23 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
2898
2999
  document.removeEventListener("ads:consent", handler);
2899
3000
  };
2900
3001
  }
2901
- /** Device storage follows the decision; a refusal also drops the stored session. */
3002
+ /** Device storage follows the decision; a refusal also drops stored session and user IDs. */
2902
3003
  followConsent(record) {
2903
3004
  const allowed = storageAllowedBy(record);
2904
- if (!allowed) clearStoredSession();
3005
+ if (!allowed) {
3006
+ clearStoredSession();
3007
+ clearStoredUserId();
3008
+ }
2905
3009
  _BidsparkPrebidAnalytics.setStorageAllowed(allowed);
2906
3010
  }
2907
3011
  setUserId(userId) {
3012
+ this.configuredUserId = userId;
2908
3013
  this.config.userId = userId;
2909
- if (userId) this.config.visitorId = userId;
3014
+ if (userId) {
3015
+ this.config.visitorId = userId;
3016
+ this.managesVisitorId = false;
3017
+ this.visitorKeyLocked = true;
3018
+ }
2910
3019
  if (this.config.storageAllowed && typeof localStorage !== "undefined") {
2911
3020
  try {
2912
3021
  if (userId) {
@@ -2920,16 +3029,46 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
2920
3029
  }
2921
3030
  setVisitorId(visitorId) {
2922
3031
  this.config.visitorId = visitorId;
3032
+ this.managesVisitorId = !visitorId;
3033
+ if (visitorId) this.visitorKeyLocked = true;
2923
3034
  }
2924
3035
  setSampleRate(sampleRate) {
2925
3036
  this.config.sampleRate = normalizeSampleRate(sampleRate);
2926
3037
  }
3038
+ setEvents(events) {
3039
+ this.config.events = events || {};
3040
+ }
2927
3041
  setSessionId(sessionId) {
2928
3042
  this.config.sessionId = sessionId;
2929
3043
  this.managesSessionId = !sessionId;
2930
3044
  if (this.managesSessionId) this.config.sessionId = getOrCreateSessionId();
2931
3045
  }
2932
- navigate(pageviewId, pageUrl) {
3046
+ getSessionId() {
3047
+ this.syncSessionId();
3048
+ return this.config.sessionId;
3049
+ }
3050
+ getPageviewId() {
3051
+ return this.config.pageviewId;
3052
+ }
3053
+ getContext() {
3054
+ return { pageviewId: this.getPageviewId(), sessionId: this.getSessionId() };
3055
+ }
3056
+ /**
3057
+ * Continues the pageview of the instance this one replaces: re-registering on
3058
+ * the same page must not count a second pageview or replay Prebid's history.
3059
+ */
3060
+ continuePageview(previous) {
3061
+ this.config.pageviewId = previous.config.pageviewId;
3062
+ this.pageviewEmitted = previous.pageviewEmitted;
3063
+ this.deduper = previous.deduper;
3064
+ this.replayedEventCount = previous.replayedEventCount;
3065
+ }
3066
+ navigate(pageviewId, pageUrl = "") {
3067
+ const nextPageUrl = normalizePageUrl(pageUrl);
3068
+ if (this.isEnabled && this.pageviewEmitted && pageviewId !== "" && pageviewId === this.config.pageviewId && (!nextPageUrl || nextPageUrl === this.pageUrl)) {
3069
+ recordActivity();
3070
+ return;
3071
+ }
2933
3072
  this.disable();
2934
3073
  this.slotRefreshIndices.clear();
2935
3074
  this.slotNames.clear();
@@ -2939,26 +3078,18 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
2939
3078
  this.consentCount = 0;
2940
3079
  this.pageviewEmitted = false;
2941
3080
  this.config.pageviewId = pageviewId || generateUUID2();
2942
- this.config.visitorId = this.config.userId || this.config.pageviewId;
2943
- if (pageUrl) {
2944
- try {
2945
- const u = new URL(pageUrl);
2946
- this.pageUrl = u.origin + u.pathname;
2947
- } catch {
2948
- this.pageUrl = pageUrl;
2949
- }
2950
- } else {
2951
- this.pageUrl = "";
2952
- }
3081
+ this.pageUrl = nextPageUrl;
2953
3082
  this.logger.resetTiming();
2954
3083
  recordActivity();
3084
+ this.syncSessionAndRotateVisitor();
2955
3085
  this.enable();
2956
3086
  }
2957
- recordAuctionStart(auctionId, adUnitCode = "", bidderCount) {
3087
+ recordAuctionStart(auctionId, adUnitCode = "", bidderCount, mediaType) {
2958
3088
  if (!this.isEnabled || !this.config.auctionEnabled) return;
2959
3089
  this.enqueue(TraceEventType.AUCTION_START, "auctionStart", {
2960
3090
  auctionId,
2961
3091
  adUnitCode,
3092
+ ...mediaType ? { bid: { mediaType } } : {},
2962
3093
  ...typeof bidderCount === "number" ? { metadata: { bidderCount: String(bidderCount) } } : {}
2963
3094
  });
2964
3095
  }
@@ -3018,7 +3149,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
3018
3149
  data.bids.forEach((bid) => {
3019
3150
  const adUnitCode = bid.adUnitCode || "";
3020
3151
  const mediaTypes = Object.keys(bid.mediaTypes || {});
3021
- const mediaType = mediaTypes.length > 0 ? mediaTypes[0] : bid.mediaType || "banner";
3152
+ const mediaType = bid.mediaType || (bid.mediaTypes?.video ? "video" : mediaTypes.length > 0 ? mediaTypes[0] : "banner");
3022
3153
  const key = `${bidder}:${adUnitCode}`;
3023
3154
  if (!auctionMap.has(key)) {
3024
3155
  auctionMap.set(key, {
@@ -3220,35 +3351,28 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
3220
3351
  }
3221
3352
  }
3222
3353
  const currentRefreshIndex = adUnitCode ? this.slotRefreshIndices.get(adUnitCode) ?? (record ? record.refreshIndex : 0) : 0;
3223
- if (!isVideo) {
3224
- const alreadyEmitted = adUnitCode ? this.hasImpressionEmitted(
3225
- adUnitCode,
3226
- currentRefreshIndex,
3227
- resolvedAuctionId,
3228
- bidTrace.creativeId
3229
- ) : false;
3230
- if (!alreadyEmitted) {
3231
- if (adUnitCode) {
3232
- this.markImpressionEmitted(
3233
- adUnitCode,
3234
- currentRefreshIndex,
3235
- resolvedAuctionId,
3236
- bidTrace.creativeId
3237
- );
3238
- }
3239
- this.enqueue(TraceEventType.IMPRESSION, "impression", {
3240
- auctionId: resolvedAuctionId,
3241
- transactionId: resolvedTransactionId,
3354
+ const alreadyEmitted = adUnitCode ? this.hasImpressionEmitted(
3355
+ adUnitCode,
3356
+ currentRefreshIndex,
3357
+ resolvedAuctionId,
3358
+ bidTrace.creativeId
3359
+ ) : false;
3360
+ if (!alreadyEmitted) {
3361
+ if (adUnitCode) {
3362
+ this.markImpressionEmitted(
3242
3363
  adUnitCode,
3243
- bid: bidTrace,
3244
- metadata: { refresh_index: String(currentRefreshIndex) }
3245
- });
3364
+ currentRefreshIndex,
3365
+ resolvedAuctionId,
3366
+ bidTrace.creativeId
3367
+ );
3246
3368
  }
3247
- } else {
3248
- this.log(
3249
- "DEBUG",
3250
- `adRenderSucceeded received for video ad unit ${adUnitCode || "unknown"}: suppressing IMPRESSION until verified video lifecycle event`
3251
- );
3369
+ this.enqueue(TraceEventType.IMPRESSION, "impression", {
3370
+ auctionId: resolvedAuctionId,
3371
+ transactionId: resolvedTransactionId,
3372
+ adUnitCode,
3373
+ bid: bidTrace,
3374
+ metadata: { refresh_index: String(currentRefreshIndex) }
3375
+ });
3252
3376
  }
3253
3377
  if (this.config.viewabilityEnabled && typeof document !== "undefined") {
3254
3378
  let el = adUnitCode && this.slotElements.get(adUnitCode) || null;
@@ -3302,9 +3426,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
3302
3426
  enqueue(type, eventName, data) {
3303
3427
  if (!this.isEnabled) return;
3304
3428
  if (!this.shouldSample(type)) return;
3305
- if (this.managesSessionId && sessionNeedsSync()) {
3306
- this.config.sessionId = getOrCreateSessionId();
3307
- }
3429
+ this.syncSessionId();
3308
3430
  const protoEvent = {
3309
3431
  eventId: idToBytes(generateUUID2()),
3310
3432
  timestampMs: Date.now(),
@@ -3318,19 +3440,20 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
3318
3440
  namespace: data.ns || data.namespace || ""
3319
3441
  };
3320
3442
  if (data.bid) {
3443
+ const dims = parseBidDimensions(data.bid);
3321
3444
  protoEvent.bid = {
3322
- bidder: data.bid.bidder || "",
3445
+ bidder: data.bid.bidder || data.bid.bidderCode || "",
3323
3446
  cpm: Number.isFinite(data.bid.cpm) ? data.bid.cpm : 0,
3324
3447
  // No defaults here: handlers with a priced bid (bidWon, impression)
3325
3448
  // set currency/mediaType themselves. Defaulting for the rest would
3326
3449
  // stamp fake "USD"/"banner" on rows that carried no bid.
3327
3450
  currency: data.bid.currency || "",
3328
- width: Number.isFinite(data.bid.width) ? data.bid.width : 0,
3329
- height: Number.isFinite(data.bid.height) ? data.bid.height : 0,
3451
+ width: dims.width,
3452
+ height: dims.height,
3330
3453
  dealId: data.bid.dealId || "",
3331
3454
  mediaType: data.bid.mediaType || "",
3332
- latencyMs: Number.isFinite(data.bid.latencyMs) ? data.bid.latencyMs : 0,
3333
- advertiserDomain: data.bid.advertiserDomain || "",
3455
+ latencyMs: Number.isFinite(data.bid.latencyMs) ? data.bid.latencyMs : Number.isFinite(data.bid.timeToRespond) ? data.bid.timeToRespond : 0,
3456
+ advertiserDomain: data.bid.advertiserDomain || data.bid.meta?.advertiserDomains?.[0] || (Array.isArray(data.bid.adomain) ? data.bid.adomain[0] : "") || "",
3334
3457
  creativeId: data.bid.creativeId || ""
3335
3458
  };
3336
3459
  }
@@ -3395,12 +3518,68 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
3395
3518
  }, this.config.revenueFlushDelayMs);
3396
3519
  }
3397
3520
  }
3521
+ // Follows the page's session, which consent or a lapse can move after this
3522
+ // instance took its ID. A settled session is read as is: only a pageview or
3523
+ // visitor input may start a new one, never a flush.
3524
+ syncSessionId() {
3525
+ if (!this.managesSessionId) return;
3526
+ this.config.sessionId = sessionNeedsSync() ? getOrCreateSessionId() : inMemorySessionId;
3527
+ this.announceSession();
3528
+ }
3529
+ syncSessionAndRotateVisitor() {
3530
+ const prevSessionId = this.config.sessionId;
3531
+ this.syncSessionId();
3532
+ if (!this.config.visitorId || this.config.sessionId !== prevSessionId && this.config.visitorId === prevSessionId) {
3533
+ this.config.visitorId = this.config.userId || this.config.sessionId;
3534
+ }
3535
+ }
3536
+ announceSession() {
3537
+ if (!this.isEnabled || !this.managesSessionId || !sessionStartedHere || this.config.sessionId === announcedSessionId) {
3538
+ return;
3539
+ }
3540
+ announcedSessionId = this.config.sessionId;
3541
+ this.emitPageEvent("session");
3542
+ }
3543
+ emitPageEvent(key) {
3544
+ const detail = {
3545
+ pageviewId: this.config.pageviewId,
3546
+ sessionId: this.config.sessionId
3547
+ };
3548
+ const configured = this.config.events?.[key];
3549
+ if (typeof configured === "function") {
3550
+ try {
3551
+ configured(detail);
3552
+ } catch (e) {
3553
+ this.log("ERROR", `Error in ${key} event handler`, e);
3554
+ }
3555
+ return;
3556
+ }
3557
+ const defaultName = `${this.config.alias}:${key}`;
3558
+ let eventName = defaultName;
3559
+ const trimmed = typeof configured === "string" ? configured.trim() : "";
3560
+ if (trimmed) {
3561
+ if (PAGE_EVENT_NAME_RE.test(trimmed) && (!trimmed.startsWith("ads:") || trimmed === defaultName)) {
3562
+ eventName = trimmed;
3563
+ } else {
3564
+ this.log(
3565
+ "WARN",
3566
+ `Invalid ${key} event name "${configured}"; falling back to "${defaultName}".`
3567
+ );
3568
+ }
3569
+ }
3570
+ if (typeof window === "undefined" || typeof window.dispatchEvent !== "function") return;
3571
+ try {
3572
+ window.dispatchEvent(new CustomEvent(eventName, { detail }));
3573
+ } catch (e) {
3574
+ this.log("ERROR", `Failed to dispatch ${eventName} event`, e);
3575
+ }
3576
+ }
3398
3577
  isSampledVisitor() {
3399
- const key = this.config.visitorId || this.config.userId || this.config.pageviewId;
3578
+ const key = this.config.visitorId || this.config.sessionId;
3400
3579
  return isVisitorSampled(key, this.config.sampleRate);
3401
3580
  }
3402
3581
  shouldSample(type) {
3403
- if (!this.isSampledVisitor()) {
3582
+ if (this.visitorKeyLocked && !this.isSampledVisitor()) {
3404
3583
  return false;
3405
3584
  }
3406
3585
  if (type === TraceEventType.ERROR) {
@@ -3427,9 +3606,15 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
3427
3606
  // Shared by flush() and flushBeacon().
3428
3607
  drainBatch() {
3429
3608
  if (this.queue.length === 0 || !this.config.endpoint) return null;
3609
+ this.syncSessionId();
3610
+ this.visitorKeyLocked = true;
3611
+ if (!this.isSampledVisitor()) {
3612
+ this.queue = [];
3613
+ return null;
3614
+ }
3430
3615
  const domain = typeof window !== "undefined" ? window.location.hostname : "";
3431
3616
  const sampleRate = normalizeSampleRate(this.config.sampleRate);
3432
- const automated = typeof navigator !== "undefined" && navigator.webdriver === true;
3617
+ const automated = isAutomatedClient();
3433
3618
  const buildBatch = (evts) => ({
3434
3619
  propertyId: idToBytes(this.config.propertyId),
3435
3620
  pageviewId: idToBytes(this.config.pageviewId),
@@ -3632,7 +3817,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
3632
3817
  // event timestamps, so late rows attribute correctly.
3633
3818
  resendPersistedBatches() {
3634
3819
  try {
3635
- if (typeof localStorage === "undefined" || !this.config.endpoint) return;
3820
+ if (!storageAllowed || typeof localStorage === "undefined" || !this.config.endpoint) return;
3636
3821
  if (!this.config.propertyId) return;
3637
3822
  const ownPrefix = this.pendingKeyPrefix();
3638
3823
  const keys = [];
@@ -3750,6 +3935,7 @@ function registerPrebidAnalytics(pbjsGlobalName = "pbjs", defaults) {
3750
3935
  }
3751
3936
  }
3752
3937
  const analytics = new BidsparkPrebidAnalytics(merged);
3938
+ if (previous && !merged.pageviewId) analytics.continuePageview(previous);
3753
3939
  analytics.enable();
3754
3940
  win._bidsparkPrebidAnalytics = analytics;
3755
3941
  return analytics;
@@ -4190,8 +4376,8 @@ function attachImaAdsManager(analytics, adsManager, options) {
4190
4376
  }
4191
4377
  const slotId = options?.slotId || options?.adUnitCode || "video";
4192
4378
  const adUnitCode = options?.adUnitCode || slotId;
4193
- const auctionId = options?.auctionId || "";
4194
- const transactionId = options?.transactionId || "";
4379
+ const auctionId = options?.auctionId || options?.bid?.auctionId || "";
4380
+ const transactionId = options?.transactionId || options?.bid?.transactionId || "";
4195
4381
  const getWinningBid = (adData) => {
4196
4382
  let cached = (auctionId ? self.getCachedBid(`${auctionId}:${adUnitCode}`) : void 0) || (auctionId && slotId !== adUnitCode ? self.getCachedBid(`${auctionId}:${slotId}`) : void 0) || (adUnitCode !== "video" ? self.getCachedBid(adUnitCode) : void 0) || (slotId !== adUnitCode && slotId !== "video" ? self.getCachedBid(slotId) : void 0);
4197
4383
  if (!cached) {
@@ -4254,11 +4440,7 @@ function attachImaAdsManager(analytics, adsManager, options) {
4254
4440
  const resolvedTransactionId = transactionId || cached?.transactionId || "";
4255
4441
  const creativeId = session.creativeId || adData.creativeId || cached?.bidTrace?.creativeId || options?.bid?.creativeId || "";
4256
4442
  const stableAdIdentity = session.adId || adData.adId || creativeId || session.sessionId;
4257
- const mergedBid = {
4258
- ...cached?.rawBid || options?.bid,
4259
- mediaType: "video",
4260
- creativeId
4261
- };
4443
+ const mergedBid = resolveMergedBid(cached, creativeId);
4262
4444
  const emitted = self.recordImpression(resolvedSlotId, {
4263
4445
  adUnitCode: resolvedAdUnitCode,
4264
4446
  auctionId: resolvedAuctionId,
@@ -4291,6 +4473,19 @@ function attachImaAdsManager(analytics, adsManager, options) {
4291
4473
  }
4292
4474
  }
4293
4475
  };
4476
+ const resolveMergedBid = (cached, extraCreativeId) => {
4477
+ const rawDims = parseBidDimensions(cached?.rawBid);
4478
+ const optDims = parseBidDimensions(options?.bid);
4479
+ const creativeId = extraCreativeId || options?.bid?.creativeId || cached?.bidTrace?.creativeId || "";
4480
+ return {
4481
+ ...cached?.rawBid,
4482
+ ...options?.bid,
4483
+ ...options?.bid?.bidder || options?.bid?.bidderCode ? { bidderCode: options.bid.bidderCode || options.bid.bidder } : {},
4484
+ ...optDims.width > 0 && optDims.height > 0 ? optDims : rawDims,
4485
+ mediaType: "video",
4486
+ ...creativeId ? { creativeId } : {}
4487
+ };
4488
+ };
4294
4489
  const onMilestone = (milestone) => {
4295
4490
  self.log("DEBUG", `IMA AdEvent milestone: ${milestone}`);
4296
4491
  if (options?.onMilestone) {
@@ -4309,7 +4504,7 @@ function attachImaAdsManager(analytics, adsManager, options) {
4309
4504
  auctionId: auctionId || cached?.auctionId,
4310
4505
  transactionId: transactionId || cached?.transactionId,
4311
4506
  adUnitCode: resolvedAdUnitCode,
4312
- bid: cached?.bidTrace || options?.bid,
4507
+ bid: cached || options?.bid ? resolveMergedBid(cached) : void 0,
4313
4508
  metadata: {
4314
4509
  ...options?.metadata,
4315
4510
  media_type: "video"
@@ -4325,7 +4520,7 @@ function attachImaAdsManager(analytics, adsManager, options) {
4325
4520
  adUnitCode: resolvedAdUnitCode,
4326
4521
  auctionId: auctionId || cached?.auctionId,
4327
4522
  transactionId: transactionId || cached?.transactionId,
4328
- bid: cached?.bidTrace || options?.bid,
4523
+ bid: cached || options?.bid ? resolveMergedBid(cached) : void 0,
4329
4524
  metadata: options?.metadata
4330
4525
  });
4331
4526
  if (options?.onError) {
@@ -4737,6 +4932,24 @@ function getAdsGlobal(alias = DEFAULT_ALIAS) {
4737
4932
  const win = window;
4738
4933
  win[alias] = win[alias] || { q: [] };
4739
4934
  const sdk = win[alias];
4935
+ if (!sdk.getContext) {
4936
+ sdk.getContext = () => {
4937
+ const inst = win._bidsparkPrebidAnalytics;
4938
+ return inst?.getContext ? inst.getContext() : { pageviewId: inst?.getPageviewId?.() || "", sessionId: getOrCreateSessionId() };
4939
+ };
4940
+ }
4941
+ if (!sdk.getSessionId) {
4942
+ sdk.getSessionId = () => {
4943
+ const inst = win._bidsparkPrebidAnalytics;
4944
+ return inst?.getSessionId ? inst.getSessionId() : getOrCreateSessionId();
4945
+ };
4946
+ }
4947
+ if (!sdk.getPageviewId) {
4948
+ sdk.getPageviewId = () => {
4949
+ const inst = win._bidsparkPrebidAnalytics;
4950
+ return inst?.getPageviewId ? inst.getPageviewId() : "";
4951
+ };
4952
+ }
4740
4953
  if (!sdk.attachVideoPlayer) {
4741
4954
  sdk.attachVideoPlayer = (target, options) => {
4742
4955
  const inst = win._bidsparkPrebidAnalytics;
@@ -4782,14 +4995,15 @@ export {
4782
4995
  getPrebidEventKey,
4783
4996
  idToBytes,
4784
4997
  idToString,
4998
+ isAutomatedClient,
4785
4999
  isSessionActive,
4786
5000
  isTrustedEndpoint,
4787
5001
  isVisitorSampled,
4788
5002
  normalizeLogLevel,
4789
5003
  normalizeSampleRate,
4790
5004
  onSessionResume,
5005
+ parseBidDimensions,
4791
5006
  registerPrebidAnalytics,
4792
- resetTcfListener,
4793
5007
  sendEvents,
4794
5008
  sessionStarted
4795
5009
  };