@bidspark/analytics 0.43.1 → 0.45.2
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/analytics.global.js +1 -1
- package/dist/index.d.mts +40 -10
- package/dist/index.d.ts +40 -10
- package/dist/index.js +331 -131
- package/dist/index.mjs +329 -130
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -42,14 +42,15 @@ __export(src_exports, {
|
|
|
42
42
|
getPrebidEventKey: () => getPrebidEventKey,
|
|
43
43
|
idToBytes: () => idToBytes,
|
|
44
44
|
idToString: () => idToString,
|
|
45
|
+
isAutomatedClient: () => isAutomatedClient,
|
|
45
46
|
isSessionActive: () => isSessionActive,
|
|
46
47
|
isTrustedEndpoint: () => isTrustedEndpoint,
|
|
47
48
|
isVisitorSampled: () => isVisitorSampled,
|
|
48
49
|
normalizeLogLevel: () => normalizeLogLevel,
|
|
49
50
|
normalizeSampleRate: () => normalizeSampleRate,
|
|
50
51
|
onSessionResume: () => onSessionResume,
|
|
52
|
+
parseBidDimensions: () => parseBidDimensions,
|
|
51
53
|
registerPrebidAnalytics: () => registerPrebidAnalytics,
|
|
52
|
-
resetTcfListener: () => resetTcfListener,
|
|
53
54
|
sendEvents: () => sendEvents,
|
|
54
55
|
sessionStarted: () => sessionStarted
|
|
55
56
|
});
|
|
@@ -336,6 +337,8 @@ var TraceEventType = {
|
|
|
336
337
|
* signals (bitmask), sdk_loaded, device (mobile|desktop), browser, forced ("1" on forced show).
|
|
337
338
|
*/
|
|
338
339
|
RECOVERY: 20,
|
|
340
|
+
/** PAGEVIEW - Pageview start (once per initial load or SPA navigate()). */
|
|
341
|
+
PAGEVIEW: 21,
|
|
339
342
|
UNRECOGNIZED: -1
|
|
340
343
|
};
|
|
341
344
|
var BidderOutcome = {
|
|
@@ -377,7 +380,8 @@ function createBaseTraceEventBatch() {
|
|
|
377
380
|
deviceModel: "",
|
|
378
381
|
city: "",
|
|
379
382
|
postalCode: "",
|
|
380
|
-
sampleRate: void 0
|
|
383
|
+
sampleRate: void 0,
|
|
384
|
+
automated: false
|
|
381
385
|
};
|
|
382
386
|
}
|
|
383
387
|
var TraceEventBatch = {
|
|
@@ -432,6 +436,9 @@ var TraceEventBatch = {
|
|
|
432
436
|
if (message.sampleRate !== void 0) {
|
|
433
437
|
writer.uint32(129).double(message.sampleRate);
|
|
434
438
|
}
|
|
439
|
+
if (message.automated !== void 0 && message.automated !== false) {
|
|
440
|
+
writer.uint32(136).bool(message.automated);
|
|
441
|
+
}
|
|
435
442
|
return writer;
|
|
436
443
|
},
|
|
437
444
|
decode(input, length) {
|
|
@@ -556,6 +563,13 @@ var TraceEventBatch = {
|
|
|
556
563
|
message.sampleRate = reader.double();
|
|
557
564
|
continue;
|
|
558
565
|
}
|
|
566
|
+
case 17: {
|
|
567
|
+
if (tag !== 136) {
|
|
568
|
+
break;
|
|
569
|
+
}
|
|
570
|
+
message.automated = reader.bool();
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
559
573
|
}
|
|
560
574
|
if ((tag & 7) === 4 || tag === 0) {
|
|
561
575
|
break;
|
|
@@ -1073,6 +1087,33 @@ function isVisitorSampled(visitorKey, sampleRate) {
|
|
|
1073
1087
|
}
|
|
1074
1088
|
return (hash >>> 0) / 4294967296 < rate;
|
|
1075
1089
|
}
|
|
1090
|
+
var AUTOMATED_UA_RE = /headless|phantomjs|slimerjs|puppeteer|playwright/i;
|
|
1091
|
+
var DESKTOP_CHROME_UA_RE = /Chrome\/\d+/i;
|
|
1092
|
+
var NON_DESKTOP_CHROME_UA_RE = /Mobile|Android|iPhone|iPad|iPod|CriOS|FxiOS|Edg\/|OPR\/|SamsungBrowser/i;
|
|
1093
|
+
function isAutomatedClient() {
|
|
1094
|
+
const g = typeof globalThis !== "undefined" ? globalThis : void 0;
|
|
1095
|
+
const nav = g && "navigator" in g ? g.navigator : void 0;
|
|
1096
|
+
if (!nav) return false;
|
|
1097
|
+
if (nav.webdriver === true) return true;
|
|
1098
|
+
const ua = typeof nav.userAgent === "string" ? nav.userAgent : "";
|
|
1099
|
+
if (AUTOMATED_UA_RE.test(ua)) return true;
|
|
1100
|
+
const win = g && "window" in g ? g.window : g;
|
|
1101
|
+
let weakSignals = 0;
|
|
1102
|
+
if (win && typeof win.outerWidth === "number" && typeof win.outerHeight === "number" && win.outerWidth === 0 && win.outerHeight === 0) {
|
|
1103
|
+
weakSignals++;
|
|
1104
|
+
}
|
|
1105
|
+
if (Array.isArray(nav.languages) && nav.languages.length === 0) {
|
|
1106
|
+
weakSignals++;
|
|
1107
|
+
}
|
|
1108
|
+
if (DESKTOP_CHROME_UA_RE.test(ua) && !NON_DESKTOP_CHROME_UA_RE.test(ua)) {
|
|
1109
|
+
if (win && !win.chrome) weakSignals++;
|
|
1110
|
+
const plugins = nav.plugins;
|
|
1111
|
+
if (plugins !== void 0 && plugins !== null && plugins.length === 0) {
|
|
1112
|
+
weakSignals++;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
return weakSignals >= 2;
|
|
1116
|
+
}
|
|
1076
1117
|
|
|
1077
1118
|
// ../../protogen/usage_event.ts
|
|
1078
1119
|
var usage_event_exports = {};
|
|
@@ -1238,6 +1279,8 @@ function sendEvents(opts) {
|
|
|
1238
1279
|
viewableDurationMs: void 0,
|
|
1239
1280
|
bidderOutcomes: []
|
|
1240
1281
|
}));
|
|
1282
|
+
const nav = g && "navigator" in g ? g.navigator : void 0;
|
|
1283
|
+
const automated = isAutomatedClient();
|
|
1241
1284
|
const batch = {
|
|
1242
1285
|
propertyId: idToBytes(opts.propertyId),
|
|
1243
1286
|
pageviewId: idToBytes(pageviewId),
|
|
@@ -1249,10 +1292,10 @@ function sendEvents(opts) {
|
|
|
1249
1292
|
deviceType: void 0,
|
|
1250
1293
|
domain,
|
|
1251
1294
|
events: traceEvents,
|
|
1252
|
-
...sampleRate < 1 ? { sampleRate } : {}
|
|
1295
|
+
...sampleRate < 1 ? { sampleRate } : {},
|
|
1296
|
+
...automated ? { automated: true } : {}
|
|
1253
1297
|
};
|
|
1254
1298
|
const encoded = TraceEventBatch.encode(batch).finish();
|
|
1255
|
-
const nav = g && "navigator" in g ? g.navigator : void 0;
|
|
1256
1299
|
if (nav && typeof nav.sendBeacon === "function") {
|
|
1257
1300
|
try {
|
|
1258
1301
|
const blob = new Blob([encoded], { type: SAFE_CONTENT_TYPE });
|
|
@@ -1541,6 +1584,15 @@ function sameEndpointOrigin(a, b) {
|
|
|
1541
1584
|
return false;
|
|
1542
1585
|
}
|
|
1543
1586
|
}
|
|
1587
|
+
function normalizePageUrl(raw) {
|
|
1588
|
+
if (!raw) return "";
|
|
1589
|
+
try {
|
|
1590
|
+
const u = new URL(raw);
|
|
1591
|
+
return u.origin + u.pathname;
|
|
1592
|
+
} catch {
|
|
1593
|
+
return raw;
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1544
1596
|
var SESSION_PERSIST_INTERVAL_MS = 60 * 1e3;
|
|
1545
1597
|
var persistedSessionTs = 0;
|
|
1546
1598
|
var ACTIVITY_EVENTS = ["pointerdown", "pointermove", "keydown", "scroll", "wheel", "touchstart"];
|
|
@@ -1650,7 +1702,7 @@ function getOrCreateUserId() {
|
|
|
1650
1702
|
if (storageAllowed && typeof localStorage !== "undefined") {
|
|
1651
1703
|
const stored = localStorage.getItem(USER_ID_KEY);
|
|
1652
1704
|
if (stored) return stored;
|
|
1653
|
-
const newId = generateUUID2();
|
|
1705
|
+
const newId = inMemorySessionId || generateUUID2();
|
|
1654
1706
|
localStorage.setItem(USER_ID_KEY, newId);
|
|
1655
1707
|
return newId;
|
|
1656
1708
|
}
|
|
@@ -1684,6 +1736,16 @@ function tcDataToConsentRecord(tcData) {
|
|
|
1684
1736
|
purposesConsented: purposes
|
|
1685
1737
|
};
|
|
1686
1738
|
}
|
|
1739
|
+
function resolveTcfStorageAllowed(tcData, success) {
|
|
1740
|
+
if (!success || !tcData) return void 0;
|
|
1741
|
+
if (tcData.eventStatus === "cmpuishown" && !tcData.tcString) return false;
|
|
1742
|
+
const allowed = storageAllowedBy(tcDataToConsentRecord(tcData));
|
|
1743
|
+
if (!allowed) {
|
|
1744
|
+
clearStoredSession();
|
|
1745
|
+
clearStoredUserId();
|
|
1746
|
+
}
|
|
1747
|
+
return allowed;
|
|
1748
|
+
}
|
|
1687
1749
|
function probeTcfStorageAllowed() {
|
|
1688
1750
|
if (typeof window === "undefined") return void 0;
|
|
1689
1751
|
const win = window;
|
|
@@ -1691,27 +1753,22 @@ function probeTcfStorageAllowed() {
|
|
|
1691
1753
|
let allowed = void 0;
|
|
1692
1754
|
try {
|
|
1693
1755
|
win.__tcfapi("getTCData", 2, (tcData, success) => {
|
|
1694
|
-
|
|
1695
|
-
allowed = storageAllowedBy(tcDataToConsentRecord(tcData));
|
|
1696
|
-
}
|
|
1756
|
+
allowed = resolveTcfStorageAllowed(tcData, success);
|
|
1697
1757
|
});
|
|
1698
1758
|
} catch {
|
|
1699
1759
|
}
|
|
1700
1760
|
return allowed !== void 0 ? allowed : false;
|
|
1701
1761
|
}
|
|
1702
|
-
var
|
|
1703
|
-
function resetTcfListener() {
|
|
1704
|
-
tcfListenerAttached = false;
|
|
1705
|
-
}
|
|
1762
|
+
var attachedTcfApi = null;
|
|
1706
1763
|
function attachTcfListener() {
|
|
1707
|
-
if (
|
|
1764
|
+
if (typeof window === "undefined") return;
|
|
1708
1765
|
const win = window;
|
|
1709
|
-
if (typeof win.__tcfapi !== "function") return;
|
|
1710
|
-
|
|
1766
|
+
if (typeof win.__tcfapi !== "function" || attachedTcfApi === win.__tcfapi) return;
|
|
1767
|
+
attachedTcfApi = win.__tcfapi;
|
|
1711
1768
|
try {
|
|
1712
1769
|
win.__tcfapi("addEventListener", 2, (tcData, success) => {
|
|
1713
|
-
|
|
1714
|
-
BidsparkPrebidAnalytics.setStorageAllowed(
|
|
1770
|
+
const allowed = resolveTcfStorageAllowed(tcData, success);
|
|
1771
|
+
if (allowed !== void 0) BidsparkPrebidAnalytics.setStorageAllowed(allowed);
|
|
1715
1772
|
});
|
|
1716
1773
|
} catch {
|
|
1717
1774
|
}
|
|
@@ -1802,18 +1859,48 @@ var PrebidEventDeduper = class {
|
|
|
1802
1859
|
}
|
|
1803
1860
|
};
|
|
1804
1861
|
function parseBidDimensions(bid) {
|
|
1805
|
-
if (Number.isFinite(bid?.width) && Number.isFinite(bid?.height)) {
|
|
1862
|
+
if (Number.isFinite(bid?.width) && bid.width > 0 && Number.isFinite(bid?.height) && bid.height > 0) {
|
|
1806
1863
|
return { width: bid.width, height: bid.height };
|
|
1807
1864
|
}
|
|
1865
|
+
if (Number.isFinite(bid?.w) && bid.w > 0 && Number.isFinite(bid?.h) && bid.h > 0) {
|
|
1866
|
+
return { width: bid.w, height: bid.h };
|
|
1867
|
+
}
|
|
1868
|
+
if (Number.isFinite(bid?.playerWidth) && bid.playerWidth > 0 && Number.isFinite(bid?.playerHeight) && bid.playerHeight > 0) {
|
|
1869
|
+
return { width: bid.playerWidth, height: bid.playerHeight };
|
|
1870
|
+
}
|
|
1871
|
+
const ps = bid?.mediaTypes?.video?.playerSize;
|
|
1872
|
+
if (Array.isArray(ps) && ps.length > 0) {
|
|
1873
|
+
const tuple = Array.isArray(ps[0]) ? ps[0] : ps;
|
|
1874
|
+
if (Number.isFinite(tuple[0]) && tuple[0] > 0 && Number.isFinite(tuple[1]) && tuple[1] > 0) {
|
|
1875
|
+
return { width: tuple[0], height: tuple[1] };
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1808
1878
|
if (typeof bid?.size === "string") {
|
|
1809
1879
|
const match = bid.size.match(/^(\d+)x(\d+)$/);
|
|
1810
1880
|
if (match) {
|
|
1811
1881
|
return { width: Number(match[1]), height: Number(match[2]) };
|
|
1812
1882
|
}
|
|
1813
1883
|
}
|
|
1884
|
+
const w = Number.isFinite(bid?.width) ? bid.width : Number.isFinite(bid?.w) ? bid.w : Number.isFinite(bid?.playerWidth) ? bid.playerWidth : 0;
|
|
1885
|
+
const h = Number.isFinite(bid?.height) ? bid.height : Number.isFinite(bid?.h) ? bid.h : Number.isFinite(bid?.playerHeight) ? bid.playerHeight : 0;
|
|
1886
|
+
return { width: w, height: h };
|
|
1887
|
+
}
|
|
1888
|
+
function resolveBidPricing(bid, fallback) {
|
|
1889
|
+
if (Number.isFinite(bid?.cpm)) {
|
|
1890
|
+
return {
|
|
1891
|
+
cpm: bid.cpm,
|
|
1892
|
+
currency: bid?.currency || bid?.originalCurrency || fallback?.currency || "USD"
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1895
|
+
if (Number.isFinite(bid?.originalCpm)) {
|
|
1896
|
+
return {
|
|
1897
|
+
cpm: bid.originalCpm,
|
|
1898
|
+
currency: bid?.originalCurrency || bid?.currency || fallback?.currency || "USD"
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1814
1901
|
return {
|
|
1815
|
-
|
|
1816
|
-
|
|
1902
|
+
cpm: fallback?.cpm ?? 0,
|
|
1903
|
+
currency: fallback?.currency || bid?.currency || bid?.originalCurrency || "USD"
|
|
1817
1904
|
};
|
|
1818
1905
|
}
|
|
1819
1906
|
var defaultLogger = createLogger({
|
|
@@ -1841,14 +1928,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
1841
1928
|
storageAllowed = allowed;
|
|
1842
1929
|
persistedSessionTs = 0;
|
|
1843
1930
|
for (const inst of _BidsparkPrebidAnalytics.allInstances) {
|
|
1844
|
-
inst.
|
|
1845
|
-
if (!allowed) {
|
|
1846
|
-
inst.config.userId = "";
|
|
1847
|
-
inst.config.visitorId = inst.config.visitorId || inst.config.pageviewId;
|
|
1848
|
-
} else if (!inst.config.userId) {
|
|
1849
|
-
inst.config.userId = getOrCreateUserId();
|
|
1850
|
-
inst.config.visitorId = inst.config.userId || inst.config.pageviewId;
|
|
1851
|
-
}
|
|
1931
|
+
inst.applyStorageAllowed(allowed);
|
|
1852
1932
|
}
|
|
1853
1933
|
}
|
|
1854
1934
|
static isStorageAllowed() {
|
|
@@ -1895,9 +1975,15 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
1895
1975
|
recordedConsentKeys = /* @__PURE__ */ new Set();
|
|
1896
1976
|
consentCount = 0;
|
|
1897
1977
|
cmpDetach = null;
|
|
1978
|
+
pageviewEmitted = false;
|
|
1898
1979
|
logger;
|
|
1899
1980
|
// True when managing session lifecycle internally; false if caller supplied fixed sessionId.
|
|
1900
1981
|
managesSessionId;
|
|
1982
|
+
configuredUserId;
|
|
1983
|
+
// True when visitor sampling key is derived internally from storage/session rather than caller config.
|
|
1984
|
+
managesVisitorId;
|
|
1985
|
+
// True once visitorId is settled (storage read, caller-supplied, or first batch drained).
|
|
1986
|
+
visitorKeyLocked;
|
|
1901
1987
|
constructor(config) {
|
|
1902
1988
|
const tcfStorage = probeTcfStorageAllowed();
|
|
1903
1989
|
if (typeof window !== "undefined" && typeof window.__tcfapi === "function") {
|
|
@@ -1911,32 +1997,33 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
1911
1997
|
const requestedEndpoint = config.endpoint || "";
|
|
1912
1998
|
const endpoint = !requestedEndpoint || isTrustedEndpoint(requestedEndpoint) ? requestedEndpoint : "";
|
|
1913
1999
|
const pageviewId = config.pageviewId || generateUUID2();
|
|
2000
|
+
recordActivity();
|
|
2001
|
+
this.managesSessionId = !config.sessionId;
|
|
2002
|
+
const sessionId = config.sessionId || getOrCreateSessionId();
|
|
2003
|
+
this.configuredUserId = config.userId || "";
|
|
1914
2004
|
let initialUserId = "";
|
|
1915
|
-
let initialVisitorId = "";
|
|
1916
2005
|
if (isStorageOn) {
|
|
1917
|
-
initialUserId =
|
|
1918
|
-
if (
|
|
2006
|
+
initialUserId = this.configuredUserId || getOrCreateUserId();
|
|
2007
|
+
if (this.configuredUserId) {
|
|
1919
2008
|
try {
|
|
1920
2009
|
if (typeof localStorage !== "undefined") {
|
|
1921
|
-
localStorage.setItem(USER_ID_KEY,
|
|
2010
|
+
localStorage.setItem(USER_ID_KEY, this.configuredUserId);
|
|
1922
2011
|
}
|
|
1923
2012
|
} catch {
|
|
1924
2013
|
}
|
|
1925
2014
|
}
|
|
1926
|
-
initialVisitorId = config.visitorId || initialUserId || pageviewId;
|
|
1927
|
-
} else {
|
|
1928
|
-
initialUserId = "";
|
|
1929
|
-
initialVisitorId = config.visitorId || pageviewId;
|
|
1930
2015
|
}
|
|
2016
|
+
this.managesVisitorId = !config.visitorId && !config.userId && !config.sessionId;
|
|
2017
|
+
this.visitorKeyLocked = isStorageOn || !this.managesVisitorId;
|
|
1931
2018
|
const usageEndpoint = config.usageEndpoint || "";
|
|
1932
2019
|
this.config = {
|
|
1933
2020
|
endpoint,
|
|
1934
2021
|
usageEndpoint,
|
|
1935
2022
|
propertyId: config.propertyId || "",
|
|
1936
2023
|
pageviewId,
|
|
1937
|
-
sessionId
|
|
2024
|
+
sessionId,
|
|
1938
2025
|
userId: initialUserId,
|
|
1939
|
-
visitorId:
|
|
2026
|
+
visitorId: config.visitorId || this.configuredUserId || initialUserId || sessionId,
|
|
1940
2027
|
deviceType: config.deviceType || "desktop",
|
|
1941
2028
|
country: config.country || "",
|
|
1942
2029
|
region: config.region || "",
|
|
@@ -1956,9 +2043,6 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
1956
2043
|
prefix: "[analytics]",
|
|
1957
2044
|
logLevel: this.config.logLevel
|
|
1958
2045
|
});
|
|
1959
|
-
recordActivity();
|
|
1960
|
-
this.managesSessionId = !config.sessionId;
|
|
1961
|
-
if (this.managesSessionId) this.config.sessionId = getOrCreateSessionId();
|
|
1962
2046
|
if (requestedEndpoint && !endpoint) {
|
|
1963
2047
|
this.log(
|
|
1964
2048
|
"ERROR",
|
|
@@ -1971,6 +2055,31 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
1971
2055
|
};
|
|
1972
2056
|
this.boundVisibilityChange = () => this.handleVisibilityChange();
|
|
1973
2057
|
}
|
|
2058
|
+
applyStorageAllowed(allowed) {
|
|
2059
|
+
this.config.storageAllowed = allowed;
|
|
2060
|
+
if (!allowed) {
|
|
2061
|
+
this.config.userId = "";
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
this.syncSessionId();
|
|
2065
|
+
if (!this.config.userId) {
|
|
2066
|
+
this.config.userId = this.configuredUserId || getOrCreateUserId();
|
|
2067
|
+
}
|
|
2068
|
+
if (this.managesVisitorId && !this.visitorKeyLocked) {
|
|
2069
|
+
this.config.visitorId = this.config.userId || this.config.sessionId;
|
|
2070
|
+
this.visitorKeyLocked = true;
|
|
2071
|
+
if (!this.isSampledVisitor()) {
|
|
2072
|
+
this.queue = [];
|
|
2073
|
+
if (this.revenueFlushTimer) {
|
|
2074
|
+
clearTimeout(this.revenueFlushTimer);
|
|
2075
|
+
this.revenueFlushTimer = null;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
if (this.isEnabled) {
|
|
2080
|
+
this.resendPersistedBatches();
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
1974
2083
|
setLogLevel(level) {
|
|
1975
2084
|
const norm = normalizeLogLevel(level);
|
|
1976
2085
|
this.config.logLevel = norm;
|
|
@@ -1984,6 +2093,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
1984
2093
|
if (this.isEnabled) return;
|
|
1985
2094
|
this.isEnabled = true;
|
|
1986
2095
|
_BidsparkPrebidAnalytics.activeInstances.add(this);
|
|
2096
|
+
_BidsparkPrebidAnalytics.allInstances.add(this);
|
|
1987
2097
|
this.logger.setLevel(this.config.logLevel);
|
|
1988
2098
|
if (this.config.attachPbjsListeners && this.config.usageEndpoint && !this.usageRecorder) {
|
|
1989
2099
|
this.usageRecorder = new UsageRecorder({
|
|
@@ -2013,18 +2123,17 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2013
2123
|
this.cmpDetach = this.attachCmp();
|
|
2014
2124
|
if (typeof window !== "undefined") {
|
|
2015
2125
|
if (!this.pageUrl) {
|
|
2016
|
-
|
|
2017
|
-
const u = new URL(window.location.href);
|
|
2018
|
-
this.pageUrl = u.origin + u.pathname;
|
|
2019
|
-
} catch {
|
|
2020
|
-
this.pageUrl = window.location.href;
|
|
2021
|
-
}
|
|
2126
|
+
this.pageUrl = normalizePageUrl(window.location.href);
|
|
2022
2127
|
}
|
|
2023
2128
|
window.addEventListener("pagehide", this.boundFlushBeacon);
|
|
2024
2129
|
if (typeof document !== "undefined") {
|
|
2025
2130
|
document.addEventListener("visibilitychange", this.boundVisibilityChange);
|
|
2026
2131
|
}
|
|
2027
2132
|
bindActivityListeners();
|
|
2133
|
+
if (!this.pageviewEmitted) {
|
|
2134
|
+
this.pageviewEmitted = true;
|
|
2135
|
+
this.enqueue(TraceEventType.PAGEVIEW, "pageview", {});
|
|
2136
|
+
}
|
|
2028
2137
|
this.flushTimer = setInterval(() => this.flush(), FLUSH_INTERVAL_MS);
|
|
2029
2138
|
this.resendPersistedBatches();
|
|
2030
2139
|
}
|
|
@@ -2194,6 +2303,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2194
2303
|
}
|
|
2195
2304
|
});
|
|
2196
2305
|
}
|
|
2306
|
+
record.accumulatedTimeInViewMs = 0;
|
|
2197
2307
|
}
|
|
2198
2308
|
this.flushBeacon();
|
|
2199
2309
|
} else if (document.visibilityState === "visible") {
|
|
@@ -2631,7 +2741,15 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2631
2741
|
hasImpressionEmitted(slotId, refreshIndex, auctionId, creativeId, adId) {
|
|
2632
2742
|
const rIndex = refreshIndex ?? this.slotRefreshIndices.get(slotId) ?? 0;
|
|
2633
2743
|
const baseSlotKey = `${escapeKeyPart(slotId)}:${rIndex}`;
|
|
2744
|
+
if (auctionId ? this.slotEmittedImpressionKeys.has(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}`) : this.slotEmittedImpressionKeys.has(baseSlotKey)) {
|
|
2745
|
+
return true;
|
|
2746
|
+
}
|
|
2634
2747
|
if (adId) {
|
|
2748
|
+
if (auctionId && this.slotEmittedImpressionKeys.has(
|
|
2749
|
+
`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:render`
|
|
2750
|
+
) || this.slotEmittedImpressionKeys.has(`${baseSlotKey}:render`)) {
|
|
2751
|
+
return true;
|
|
2752
|
+
}
|
|
2635
2753
|
if (auctionId) {
|
|
2636
2754
|
if (this.slotEmittedImpressionKeys.has(
|
|
2637
2755
|
`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:ad:${escapeKeyPart(adId)}`
|
|
@@ -2654,6 +2772,11 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2654
2772
|
}
|
|
2655
2773
|
return false;
|
|
2656
2774
|
}
|
|
2775
|
+
if (auctionId && this.slotEmittedImpressionKeys.has(
|
|
2776
|
+
`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:ad-emitted`
|
|
2777
|
+
) || this.slotEmittedImpressionKeys.has(`${baseSlotKey}:ad-emitted`)) {
|
|
2778
|
+
return true;
|
|
2779
|
+
}
|
|
2657
2780
|
if (creativeId) {
|
|
2658
2781
|
if (auctionId) {
|
|
2659
2782
|
return this.slotEmittedImpressionKeys.has(
|
|
@@ -2662,10 +2785,10 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2662
2785
|
}
|
|
2663
2786
|
return this.slotEmittedImpressionKeys.has(`${baseSlotKey}:${escapeKeyPart(creativeId)}`);
|
|
2664
2787
|
}
|
|
2665
|
-
if (auctionId) {
|
|
2666
|
-
return
|
|
2788
|
+
if (auctionId && this.slotEmittedImpressionKeys.has(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:any`)) {
|
|
2789
|
+
return true;
|
|
2667
2790
|
}
|
|
2668
|
-
return
|
|
2791
|
+
return false;
|
|
2669
2792
|
}
|
|
2670
2793
|
markImpressionEmitted(slotId, refreshIndex, auctionId, creativeId, adId) {
|
|
2671
2794
|
const baseSlotKey = `${escapeKeyPart(slotId)}:${refreshIndex}`;
|
|
@@ -2673,10 +2796,13 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2673
2796
|
if (hasIdentity) {
|
|
2674
2797
|
if (adId) {
|
|
2675
2798
|
this.addImpressionKey(`${baseSlotKey}:ad:${escapeKeyPart(adId)}`);
|
|
2799
|
+
this.addImpressionKey(`${baseSlotKey}:ad-emitted`);
|
|
2676
2800
|
if (auctionId) {
|
|
2677
2801
|
this.addImpressionKey(
|
|
2678
2802
|
`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:ad:${escapeKeyPart(adId)}`
|
|
2679
2803
|
);
|
|
2804
|
+
this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:any`);
|
|
2805
|
+
this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:ad-emitted`);
|
|
2680
2806
|
}
|
|
2681
2807
|
}
|
|
2682
2808
|
if (creativeId && creativeId !== adId) {
|
|
@@ -2685,15 +2811,21 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2685
2811
|
this.addImpressionKey(
|
|
2686
2812
|
`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:${escapeKeyPart(creativeId)}`
|
|
2687
2813
|
);
|
|
2814
|
+
this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:any`);
|
|
2688
2815
|
}
|
|
2689
2816
|
}
|
|
2690
|
-
if (
|
|
2691
|
-
this.addImpressionKey(`${baseSlotKey}:
|
|
2817
|
+
if (!adId) {
|
|
2818
|
+
this.addImpressionKey(`${baseSlotKey}:render`);
|
|
2819
|
+
if (auctionId) {
|
|
2820
|
+
this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:render`);
|
|
2821
|
+
}
|
|
2692
2822
|
}
|
|
2693
2823
|
} else {
|
|
2694
2824
|
this.addImpressionKey(baseSlotKey);
|
|
2825
|
+
this.addImpressionKey(`${baseSlotKey}:render`);
|
|
2695
2826
|
if (auctionId) {
|
|
2696
2827
|
this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}`);
|
|
2828
|
+
this.addImpressionKey(`${baseSlotKey}:auc:${escapeKeyPart(auctionId)}:render`);
|
|
2697
2829
|
}
|
|
2698
2830
|
}
|
|
2699
2831
|
}
|
|
@@ -2716,13 +2848,12 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2716
2848
|
);
|
|
2717
2849
|
const bidTrace = {
|
|
2718
2850
|
bidder: rawBid.bidderCode || rawBid.bidder || cached?.bidTrace?.bidder || "",
|
|
2719
|
-
|
|
2720
|
-
currency: rawBid.originalCurrency ?? rawBid.currency ?? cached?.bidTrace?.currency ?? "USD",
|
|
2851
|
+
...resolveBidPricing(rawBid, cached?.bidTrace),
|
|
2721
2852
|
...parseBidDimensions(rawBid).width ? parseBidDimensions(rawBid) : cached?.bidTrace ? { width: cached.bidTrace.width, height: cached.bidTrace.height } : parseBidDimensions(rawBid),
|
|
2722
2853
|
dealId: rawBid.dealId || cached?.bidTrace?.dealId || "",
|
|
2723
2854
|
mediaType,
|
|
2724
|
-
latencyMs: Number.isFinite(rawBid.timeToRespond) ? rawBid.timeToRespond : cached?.bidTrace?.latencyMs ?? 0,
|
|
2725
|
-
advertiserDomain: rawBid.meta?.advertiserDomains?.[0] || cached?.bidTrace?.advertiserDomain || "",
|
|
2855
|
+
latencyMs: Number.isFinite(rawBid.timeToRespond) ? rawBid.timeToRespond : Number.isFinite(rawBid.latencyMs) ? rawBid.latencyMs : cached?.bidTrace?.latencyMs ?? 0,
|
|
2856
|
+
advertiserDomain: rawBid.advertiserDomain || rawBid.meta?.advertiserDomains?.[0] || (Array.isArray(rawBid.adomain) ? rawBid.adomain[0] : "") || cached?.bidTrace?.advertiserDomain || "",
|
|
2726
2857
|
creativeId: rawBid.creativeId || cached?.bidTrace?.creativeId || ""
|
|
2727
2858
|
};
|
|
2728
2859
|
if (isDifferentAuction && targetSlot) {
|
|
@@ -2893,16 +3024,16 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2893
3024
|
const handler = (evt) => {
|
|
2894
3025
|
const detail = evt.detail;
|
|
2895
3026
|
if (detail) {
|
|
2896
|
-
this.recordConsent(detail);
|
|
2897
3027
|
this.followConsent(detail);
|
|
3028
|
+
this.recordConsent(detail);
|
|
2898
3029
|
}
|
|
2899
3030
|
};
|
|
2900
3031
|
document.addEventListener("ads:consent", handler);
|
|
2901
3032
|
const win = typeof window !== "undefined" ? window : {};
|
|
2902
3033
|
const existingRecord = win[this.config.alias]?.consent?.getRecord?.() || null;
|
|
2903
3034
|
if (existingRecord) {
|
|
2904
|
-
this.recordConsent(existingRecord);
|
|
2905
3035
|
this.followConsent(existingRecord);
|
|
3036
|
+
this.recordConsent(existingRecord);
|
|
2906
3037
|
}
|
|
2907
3038
|
let detached = false;
|
|
2908
3039
|
return () => {
|
|
@@ -2911,15 +3042,23 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2911
3042
|
document.removeEventListener("ads:consent", handler);
|
|
2912
3043
|
};
|
|
2913
3044
|
}
|
|
2914
|
-
/** Device storage follows the decision; a refusal also drops
|
|
3045
|
+
/** Device storage follows the decision; a refusal also drops stored session and user IDs. */
|
|
2915
3046
|
followConsent(record) {
|
|
2916
3047
|
const allowed = storageAllowedBy(record);
|
|
2917
|
-
if (!allowed)
|
|
3048
|
+
if (!allowed) {
|
|
3049
|
+
clearStoredSession();
|
|
3050
|
+
clearStoredUserId();
|
|
3051
|
+
}
|
|
2918
3052
|
_BidsparkPrebidAnalytics.setStorageAllowed(allowed);
|
|
2919
3053
|
}
|
|
2920
3054
|
setUserId(userId) {
|
|
3055
|
+
this.configuredUserId = userId;
|
|
2921
3056
|
this.config.userId = userId;
|
|
2922
|
-
if (userId)
|
|
3057
|
+
if (userId) {
|
|
3058
|
+
this.config.visitorId = userId;
|
|
3059
|
+
this.managesVisitorId = false;
|
|
3060
|
+
this.visitorKeyLocked = true;
|
|
3061
|
+
}
|
|
2923
3062
|
if (this.config.storageAllowed && typeof localStorage !== "undefined") {
|
|
2924
3063
|
try {
|
|
2925
3064
|
if (userId) {
|
|
@@ -2933,6 +3072,8 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2933
3072
|
}
|
|
2934
3073
|
setVisitorId(visitorId) {
|
|
2935
3074
|
this.config.visitorId = visitorId;
|
|
3075
|
+
this.managesVisitorId = !visitorId;
|
|
3076
|
+
if (visitorId) this.visitorKeyLocked = true;
|
|
2936
3077
|
}
|
|
2937
3078
|
setSampleRate(sampleRate) {
|
|
2938
3079
|
this.config.sampleRate = normalizeSampleRate(sampleRate);
|
|
@@ -2942,7 +3083,32 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2942
3083
|
this.managesSessionId = !sessionId;
|
|
2943
3084
|
if (this.managesSessionId) this.config.sessionId = getOrCreateSessionId();
|
|
2944
3085
|
}
|
|
2945
|
-
|
|
3086
|
+
getSessionId() {
|
|
3087
|
+
this.syncSessionId();
|
|
3088
|
+
return this.config.sessionId;
|
|
3089
|
+
}
|
|
3090
|
+
getPageviewId() {
|
|
3091
|
+
return this.config.pageviewId;
|
|
3092
|
+
}
|
|
3093
|
+
getContext() {
|
|
3094
|
+
return { pageviewId: this.getPageviewId(), sessionId: this.getSessionId() };
|
|
3095
|
+
}
|
|
3096
|
+
/**
|
|
3097
|
+
* Continues the pageview of the instance this one replaces: re-registering on
|
|
3098
|
+
* the same page must not count a second pageview or replay Prebid's history.
|
|
3099
|
+
*/
|
|
3100
|
+
continuePageview(previous) {
|
|
3101
|
+
this.config.pageviewId = previous.config.pageviewId;
|
|
3102
|
+
this.pageviewEmitted = previous.pageviewEmitted;
|
|
3103
|
+
this.deduper = previous.deduper;
|
|
3104
|
+
this.replayedEventCount = previous.replayedEventCount;
|
|
3105
|
+
}
|
|
3106
|
+
navigate(pageviewId, pageUrl = "") {
|
|
3107
|
+
const nextPageUrl = normalizePageUrl(pageUrl);
|
|
3108
|
+
if (this.isEnabled && this.pageviewEmitted && pageviewId !== "" && pageviewId === this.config.pageviewId && (!nextPageUrl || nextPageUrl === this.pageUrl)) {
|
|
3109
|
+
recordActivity();
|
|
3110
|
+
return;
|
|
3111
|
+
}
|
|
2946
3112
|
this.disable();
|
|
2947
3113
|
this.slotRefreshIndices.clear();
|
|
2948
3114
|
this.slotNames.clear();
|
|
@@ -2950,26 +3116,24 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
2950
3116
|
this.floorDecisions.clear();
|
|
2951
3117
|
this.recordedConsentKeys.clear();
|
|
2952
3118
|
this.consentCount = 0;
|
|
3119
|
+
this.pageviewEmitted = false;
|
|
2953
3120
|
this.config.pageviewId = pageviewId || generateUUID2();
|
|
2954
|
-
|
|
2955
|
-
try {
|
|
2956
|
-
const u = new URL(pageUrl);
|
|
2957
|
-
this.pageUrl = u.origin + u.pathname;
|
|
2958
|
-
} catch {
|
|
2959
|
-
this.pageUrl = pageUrl;
|
|
2960
|
-
}
|
|
2961
|
-
} else {
|
|
2962
|
-
this.pageUrl = "";
|
|
2963
|
-
}
|
|
3121
|
+
this.pageUrl = nextPageUrl;
|
|
2964
3122
|
this.logger.resetTiming();
|
|
3123
|
+
const prevSessionId = this.config.sessionId;
|
|
2965
3124
|
recordActivity();
|
|
3125
|
+
this.syncSessionId();
|
|
3126
|
+
if (!this.config.visitorId || this.config.sessionId !== prevSessionId && this.config.visitorId === prevSessionId) {
|
|
3127
|
+
this.config.visitorId = this.config.userId || this.config.sessionId;
|
|
3128
|
+
}
|
|
2966
3129
|
this.enable();
|
|
2967
3130
|
}
|
|
2968
|
-
recordAuctionStart(auctionId, adUnitCode = "", bidderCount) {
|
|
3131
|
+
recordAuctionStart(auctionId, adUnitCode = "", bidderCount, mediaType) {
|
|
2969
3132
|
if (!this.isEnabled || !this.config.auctionEnabled) return;
|
|
2970
3133
|
this.enqueue(TraceEventType.AUCTION_START, "auctionStart", {
|
|
2971
3134
|
auctionId,
|
|
2972
3135
|
adUnitCode,
|
|
3136
|
+
...mediaType ? { bid: { mediaType } } : {},
|
|
2973
3137
|
...typeof bidderCount === "number" ? { metadata: { bidderCount: String(bidderCount) } } : {}
|
|
2974
3138
|
});
|
|
2975
3139
|
}
|
|
@@ -3029,7 +3193,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3029
3193
|
data.bids.forEach((bid) => {
|
|
3030
3194
|
const adUnitCode = bid.adUnitCode || "";
|
|
3031
3195
|
const mediaTypes = Object.keys(bid.mediaTypes || {});
|
|
3032
|
-
const mediaType = mediaTypes.length > 0 ? mediaTypes[0] :
|
|
3196
|
+
const mediaType = bid.mediaType || (bid.mediaTypes?.video ? "video" : mediaTypes.length > 0 ? mediaTypes[0] : "banner");
|
|
3033
3197
|
const key = `${bidder}:${adUnitCode}`;
|
|
3034
3198
|
if (!auctionMap.has(key)) {
|
|
3035
3199
|
auctionMap.set(key, {
|
|
@@ -3047,15 +3211,15 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3047
3211
|
const auctionId = data.auctionId || "";
|
|
3048
3212
|
const bidder = data.bidderCode || data.bidder || "";
|
|
3049
3213
|
const adUnitCode = data.adUnitCode || "";
|
|
3050
|
-
const
|
|
3214
|
+
const pricing = resolveBidPricing(data);
|
|
3215
|
+
const cpm = pricing.cpm;
|
|
3051
3216
|
const latencyMs = Number.isFinite(data.timeToRespond) ? data.timeToRespond : 0;
|
|
3052
3217
|
const resMediaTypes = Object.keys(data.mediaTypes || {});
|
|
3053
3218
|
const mediaType = data.mediaType || (data.mediaTypes?.video ? "video" : resMediaTypes.length > 0 ? resMediaTypes[0] : "banner");
|
|
3054
3219
|
if (!auctionId || !bidder) return;
|
|
3055
3220
|
const bid = cpm > 0 ? {
|
|
3056
3221
|
bidder,
|
|
3057
|
-
|
|
3058
|
-
currency: data.originalCurrency ?? data.currency ?? "USD",
|
|
3222
|
+
...pricing,
|
|
3059
3223
|
...parseBidDimensions(data),
|
|
3060
3224
|
dealId: data.dealId || "",
|
|
3061
3225
|
mediaType,
|
|
@@ -3105,8 +3269,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3105
3269
|
const resolvedMediaType = data.mediaType || (data.mediaTypes?.video ? "video" : wonMediaTypes.length > 0 ? wonMediaTypes[0] : "banner");
|
|
3106
3270
|
const bidTrace = {
|
|
3107
3271
|
bidder: data.bidderCode || data.bidder || "",
|
|
3108
|
-
|
|
3109
|
-
currency: data.originalCurrency ?? data.currency ?? "USD",
|
|
3272
|
+
...resolveBidPricing(data),
|
|
3110
3273
|
...parseBidDimensions(data),
|
|
3111
3274
|
dealId: data.dealId || "",
|
|
3112
3275
|
mediaType: resolvedMediaType,
|
|
@@ -3200,8 +3363,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3200
3363
|
const resolvedMediaType = isVideo ? "video" : mediaType || cached?.bidTrace?.mediaType || "banner";
|
|
3201
3364
|
const bidTrace = {
|
|
3202
3365
|
bidder: bid.bidderCode || bid.bidder || cached?.bidTrace?.bidder || "",
|
|
3203
|
-
|
|
3204
|
-
currency: bid.originalCurrency ?? bid.currency ?? cached?.bidTrace?.currency ?? "USD",
|
|
3366
|
+
...resolveBidPricing(bid, cached?.bidTrace),
|
|
3205
3367
|
...parseBidDimensions(bid).width ? parseBidDimensions(bid) : cached?.bidTrace ? { width: cached.bidTrace.width, height: cached.bidTrace.height } : parseBidDimensions(bid),
|
|
3206
3368
|
dealId: bid.dealId || cached?.bidTrace?.dealId || "",
|
|
3207
3369
|
mediaType: resolvedMediaType,
|
|
@@ -3233,35 +3395,28 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3233
3395
|
}
|
|
3234
3396
|
}
|
|
3235
3397
|
const currentRefreshIndex = adUnitCode ? this.slotRefreshIndices.get(adUnitCode) ?? (record ? record.refreshIndex : 0) : 0;
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
if (
|
|
3244
|
-
|
|
3245
|
-
this.markImpressionEmitted(
|
|
3246
|
-
adUnitCode,
|
|
3247
|
-
currentRefreshIndex,
|
|
3248
|
-
resolvedAuctionId,
|
|
3249
|
-
bidTrace.creativeId
|
|
3250
|
-
);
|
|
3251
|
-
}
|
|
3252
|
-
this.enqueue(TraceEventType.IMPRESSION, "impression", {
|
|
3253
|
-
auctionId: resolvedAuctionId,
|
|
3254
|
-
transactionId: resolvedTransactionId,
|
|
3398
|
+
const alreadyEmitted = adUnitCode ? this.hasImpressionEmitted(
|
|
3399
|
+
adUnitCode,
|
|
3400
|
+
currentRefreshIndex,
|
|
3401
|
+
resolvedAuctionId,
|
|
3402
|
+
bidTrace.creativeId
|
|
3403
|
+
) : false;
|
|
3404
|
+
if (!alreadyEmitted) {
|
|
3405
|
+
if (adUnitCode) {
|
|
3406
|
+
this.markImpressionEmitted(
|
|
3255
3407
|
adUnitCode,
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3408
|
+
currentRefreshIndex,
|
|
3409
|
+
resolvedAuctionId,
|
|
3410
|
+
bidTrace.creativeId
|
|
3411
|
+
);
|
|
3259
3412
|
}
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3413
|
+
this.enqueue(TraceEventType.IMPRESSION, "impression", {
|
|
3414
|
+
auctionId: resolvedAuctionId,
|
|
3415
|
+
transactionId: resolvedTransactionId,
|
|
3416
|
+
adUnitCode,
|
|
3417
|
+
bid: bidTrace,
|
|
3418
|
+
metadata: { refresh_index: String(currentRefreshIndex) }
|
|
3419
|
+
});
|
|
3265
3420
|
}
|
|
3266
3421
|
if (this.config.viewabilityEnabled && typeof document !== "undefined") {
|
|
3267
3422
|
let el = adUnitCode && this.slotElements.get(adUnitCode) || null;
|
|
@@ -3315,9 +3470,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3315
3470
|
enqueue(type, eventName, data) {
|
|
3316
3471
|
if (!this.isEnabled) return;
|
|
3317
3472
|
if (!this.shouldSample(type)) return;
|
|
3318
|
-
|
|
3319
|
-
this.config.sessionId = getOrCreateSessionId();
|
|
3320
|
-
}
|
|
3473
|
+
this.syncSessionId();
|
|
3321
3474
|
const protoEvent = {
|
|
3322
3475
|
eventId: idToBytes(generateUUID2()),
|
|
3323
3476
|
timestampMs: Date.now(),
|
|
@@ -3331,19 +3484,20 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3331
3484
|
namespace: data.ns || data.namespace || ""
|
|
3332
3485
|
};
|
|
3333
3486
|
if (data.bid) {
|
|
3487
|
+
const dims = parseBidDimensions(data.bid);
|
|
3334
3488
|
protoEvent.bid = {
|
|
3335
|
-
bidder: data.bid.bidder || "",
|
|
3489
|
+
bidder: data.bid.bidder || data.bid.bidderCode || "",
|
|
3336
3490
|
cpm: Number.isFinite(data.bid.cpm) ? data.bid.cpm : 0,
|
|
3337
3491
|
// No defaults here: handlers with a priced bid (bidWon, impression)
|
|
3338
3492
|
// set currency/mediaType themselves. Defaulting for the rest would
|
|
3339
3493
|
// stamp fake "USD"/"banner" on rows that carried no bid.
|
|
3340
3494
|
currency: data.bid.currency || "",
|
|
3341
|
-
width:
|
|
3342
|
-
height:
|
|
3495
|
+
width: dims.width,
|
|
3496
|
+
height: dims.height,
|
|
3343
3497
|
dealId: data.bid.dealId || "",
|
|
3344
3498
|
mediaType: data.bid.mediaType || "",
|
|
3345
|
-
latencyMs: Number.isFinite(data.bid.latencyMs) ? data.bid.latencyMs : 0,
|
|
3346
|
-
advertiserDomain: data.bid.advertiserDomain || "",
|
|
3499
|
+
latencyMs: Number.isFinite(data.bid.latencyMs) ? data.bid.latencyMs : Number.isFinite(data.bid.timeToRespond) ? data.bid.timeToRespond : 0,
|
|
3500
|
+
advertiserDomain: data.bid.advertiserDomain || data.bid.meta?.advertiserDomains?.[0] || (Array.isArray(data.bid.adomain) ? data.bid.adomain[0] : "") || "",
|
|
3347
3501
|
creativeId: data.bid.creativeId || ""
|
|
3348
3502
|
};
|
|
3349
3503
|
}
|
|
@@ -3408,12 +3562,19 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3408
3562
|
}, this.config.revenueFlushDelayMs);
|
|
3409
3563
|
}
|
|
3410
3564
|
}
|
|
3565
|
+
// Follows the page's session, which consent or a lapse can move after this
|
|
3566
|
+
// instance took its ID. A settled session is read as is: only a pageview or
|
|
3567
|
+
// visitor input may start a new one, never a flush.
|
|
3568
|
+
syncSessionId() {
|
|
3569
|
+
if (!this.managesSessionId) return;
|
|
3570
|
+
this.config.sessionId = sessionNeedsSync() ? getOrCreateSessionId() : inMemorySessionId;
|
|
3571
|
+
}
|
|
3411
3572
|
isSampledVisitor() {
|
|
3412
|
-
const key = this.config.
|
|
3573
|
+
const key = this.config.visitorId || this.config.sessionId;
|
|
3413
3574
|
return isVisitorSampled(key, this.config.sampleRate);
|
|
3414
3575
|
}
|
|
3415
3576
|
shouldSample(type) {
|
|
3416
|
-
if (!this.isSampledVisitor()) {
|
|
3577
|
+
if (this.visitorKeyLocked && !this.isSampledVisitor()) {
|
|
3417
3578
|
return false;
|
|
3418
3579
|
}
|
|
3419
3580
|
if (type === TraceEventType.ERROR) {
|
|
@@ -3440,8 +3601,15 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3440
3601
|
// Shared by flush() and flushBeacon().
|
|
3441
3602
|
drainBatch() {
|
|
3442
3603
|
if (this.queue.length === 0 || !this.config.endpoint) return null;
|
|
3604
|
+
this.syncSessionId();
|
|
3605
|
+
this.visitorKeyLocked = true;
|
|
3606
|
+
if (!this.isSampledVisitor()) {
|
|
3607
|
+
this.queue = [];
|
|
3608
|
+
return null;
|
|
3609
|
+
}
|
|
3443
3610
|
const domain = typeof window !== "undefined" ? window.location.hostname : "";
|
|
3444
3611
|
const sampleRate = normalizeSampleRate(this.config.sampleRate);
|
|
3612
|
+
const automated = isAutomatedClient();
|
|
3445
3613
|
const buildBatch = (evts) => ({
|
|
3446
3614
|
propertyId: idToBytes(this.config.propertyId),
|
|
3447
3615
|
pageviewId: idToBytes(this.config.pageviewId),
|
|
@@ -3453,7 +3621,8 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3453
3621
|
userId: this.config.userId || "",
|
|
3454
3622
|
domain,
|
|
3455
3623
|
events: evts,
|
|
3456
|
-
...sampleRate < 1 ? { sampleRate } : {}
|
|
3624
|
+
...sampleRate < 1 ? { sampleRate } : {},
|
|
3625
|
+
...automated ? { automated: true } : {}
|
|
3457
3626
|
});
|
|
3458
3627
|
const headerBytes = TraceEventBatch.encode(buildBatch([])).finish().byteLength;
|
|
3459
3628
|
for (; ; ) {
|
|
@@ -3554,8 +3723,10 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3554
3723
|
flush() {
|
|
3555
3724
|
if (Date.now() < this.nextSendAllowedAt) return;
|
|
3556
3725
|
let payload = this.drainBatch();
|
|
3726
|
+
let useKeepalive = true;
|
|
3557
3727
|
while (payload) {
|
|
3558
|
-
this.sendFetch(payload,
|
|
3728
|
+
this.sendFetch(payload, useKeepalive);
|
|
3729
|
+
useKeepalive = false;
|
|
3559
3730
|
if (Date.now() < this.nextSendAllowedAt) break;
|
|
3560
3731
|
payload = this.drainBatch();
|
|
3561
3732
|
}
|
|
@@ -3641,7 +3812,7 @@ var BidsparkPrebidAnalytics = class _BidsparkPrebidAnalytics {
|
|
|
3641
3812
|
// event timestamps, so late rows attribute correctly.
|
|
3642
3813
|
resendPersistedBatches() {
|
|
3643
3814
|
try {
|
|
3644
|
-
if (typeof localStorage === "undefined" || !this.config.endpoint) return;
|
|
3815
|
+
if (!storageAllowed || typeof localStorage === "undefined" || !this.config.endpoint) return;
|
|
3645
3816
|
if (!this.config.propertyId) return;
|
|
3646
3817
|
const ownPrefix = this.pendingKeyPrefix();
|
|
3647
3818
|
const keys = [];
|
|
@@ -3759,6 +3930,7 @@ function registerPrebidAnalytics(pbjsGlobalName = "pbjs", defaults) {
|
|
|
3759
3930
|
}
|
|
3760
3931
|
}
|
|
3761
3932
|
const analytics = new BidsparkPrebidAnalytics(merged);
|
|
3933
|
+
if (previous && !merged.pageviewId) analytics.continuePageview(previous);
|
|
3762
3934
|
analytics.enable();
|
|
3763
3935
|
win._bidsparkPrebidAnalytics = analytics;
|
|
3764
3936
|
return analytics;
|
|
@@ -4199,8 +4371,8 @@ function attachImaAdsManager(analytics, adsManager, options) {
|
|
|
4199
4371
|
}
|
|
4200
4372
|
const slotId = options?.slotId || options?.adUnitCode || "video";
|
|
4201
4373
|
const adUnitCode = options?.adUnitCode || slotId;
|
|
4202
|
-
const auctionId = options?.auctionId || "";
|
|
4203
|
-
const transactionId = options?.transactionId || "";
|
|
4374
|
+
const auctionId = options?.auctionId || options?.bid?.auctionId || "";
|
|
4375
|
+
const transactionId = options?.transactionId || options?.bid?.transactionId || "";
|
|
4204
4376
|
const getWinningBid = (adData) => {
|
|
4205
4377
|
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);
|
|
4206
4378
|
if (!cached) {
|
|
@@ -4263,11 +4435,7 @@ function attachImaAdsManager(analytics, adsManager, options) {
|
|
|
4263
4435
|
const resolvedTransactionId = transactionId || cached?.transactionId || "";
|
|
4264
4436
|
const creativeId = session.creativeId || adData.creativeId || cached?.bidTrace?.creativeId || options?.bid?.creativeId || "";
|
|
4265
4437
|
const stableAdIdentity = session.adId || adData.adId || creativeId || session.sessionId;
|
|
4266
|
-
const mergedBid =
|
|
4267
|
-
...cached?.rawBid || options?.bid,
|
|
4268
|
-
mediaType: "video",
|
|
4269
|
-
creativeId
|
|
4270
|
-
};
|
|
4438
|
+
const mergedBid = resolveMergedBid(cached, creativeId);
|
|
4271
4439
|
const emitted = self.recordImpression(resolvedSlotId, {
|
|
4272
4440
|
adUnitCode: resolvedAdUnitCode,
|
|
4273
4441
|
auctionId: resolvedAuctionId,
|
|
@@ -4300,6 +4468,19 @@ function attachImaAdsManager(analytics, adsManager, options) {
|
|
|
4300
4468
|
}
|
|
4301
4469
|
}
|
|
4302
4470
|
};
|
|
4471
|
+
const resolveMergedBid = (cached, extraCreativeId) => {
|
|
4472
|
+
const rawDims = parseBidDimensions(cached?.rawBid);
|
|
4473
|
+
const optDims = parseBidDimensions(options?.bid);
|
|
4474
|
+
const creativeId = extraCreativeId || options?.bid?.creativeId || cached?.bidTrace?.creativeId || "";
|
|
4475
|
+
return {
|
|
4476
|
+
...cached?.rawBid,
|
|
4477
|
+
...options?.bid,
|
|
4478
|
+
...options?.bid?.bidder || options?.bid?.bidderCode ? { bidderCode: options.bid.bidderCode || options.bid.bidder } : {},
|
|
4479
|
+
...optDims.width > 0 && optDims.height > 0 ? optDims : rawDims,
|
|
4480
|
+
mediaType: "video",
|
|
4481
|
+
...creativeId ? { creativeId } : {}
|
|
4482
|
+
};
|
|
4483
|
+
};
|
|
4303
4484
|
const onMilestone = (milestone) => {
|
|
4304
4485
|
self.log("DEBUG", `IMA AdEvent milestone: ${milestone}`);
|
|
4305
4486
|
if (options?.onMilestone) {
|
|
@@ -4318,7 +4499,7 @@ function attachImaAdsManager(analytics, adsManager, options) {
|
|
|
4318
4499
|
auctionId: auctionId || cached?.auctionId,
|
|
4319
4500
|
transactionId: transactionId || cached?.transactionId,
|
|
4320
4501
|
adUnitCode: resolvedAdUnitCode,
|
|
4321
|
-
bid: cached
|
|
4502
|
+
bid: cached || options?.bid ? resolveMergedBid(cached) : void 0,
|
|
4322
4503
|
metadata: {
|
|
4323
4504
|
...options?.metadata,
|
|
4324
4505
|
media_type: "video"
|
|
@@ -4334,7 +4515,7 @@ function attachImaAdsManager(analytics, adsManager, options) {
|
|
|
4334
4515
|
adUnitCode: resolvedAdUnitCode,
|
|
4335
4516
|
auctionId: auctionId || cached?.auctionId,
|
|
4336
4517
|
transactionId: transactionId || cached?.transactionId,
|
|
4337
|
-
bid: cached
|
|
4518
|
+
bid: cached || options?.bid ? resolveMergedBid(cached) : void 0,
|
|
4338
4519
|
metadata: options?.metadata
|
|
4339
4520
|
});
|
|
4340
4521
|
if (options?.onError) {
|
|
@@ -4746,6 +4927,24 @@ function getAdsGlobal(alias = DEFAULT_ALIAS) {
|
|
|
4746
4927
|
const win = window;
|
|
4747
4928
|
win[alias] = win[alias] || { q: [] };
|
|
4748
4929
|
const sdk = win[alias];
|
|
4930
|
+
if (!sdk.getContext) {
|
|
4931
|
+
sdk.getContext = () => {
|
|
4932
|
+
const inst = win._bidsparkPrebidAnalytics;
|
|
4933
|
+
return inst?.getContext ? inst.getContext() : { pageviewId: inst?.getPageviewId?.() || "", sessionId: getOrCreateSessionId() };
|
|
4934
|
+
};
|
|
4935
|
+
}
|
|
4936
|
+
if (!sdk.getSessionId) {
|
|
4937
|
+
sdk.getSessionId = () => {
|
|
4938
|
+
const inst = win._bidsparkPrebidAnalytics;
|
|
4939
|
+
return inst?.getSessionId ? inst.getSessionId() : getOrCreateSessionId();
|
|
4940
|
+
};
|
|
4941
|
+
}
|
|
4942
|
+
if (!sdk.getPageviewId) {
|
|
4943
|
+
sdk.getPageviewId = () => {
|
|
4944
|
+
const inst = win._bidsparkPrebidAnalytics;
|
|
4945
|
+
return inst?.getPageviewId ? inst.getPageviewId() : "";
|
|
4946
|
+
};
|
|
4947
|
+
}
|
|
4749
4948
|
if (!sdk.attachVideoPlayer) {
|
|
4750
4949
|
sdk.attachVideoPlayer = (target, options) => {
|
|
4751
4950
|
const inst = win._bidsparkPrebidAnalytics;
|
|
@@ -4792,14 +4991,15 @@ function getAdsGlobal(alias = DEFAULT_ALIAS) {
|
|
|
4792
4991
|
getPrebidEventKey,
|
|
4793
4992
|
idToBytes,
|
|
4794
4993
|
idToString,
|
|
4994
|
+
isAutomatedClient,
|
|
4795
4995
|
isSessionActive,
|
|
4796
4996
|
isTrustedEndpoint,
|
|
4797
4997
|
isVisitorSampled,
|
|
4798
4998
|
normalizeLogLevel,
|
|
4799
4999
|
normalizeSampleRate,
|
|
4800
5000
|
onSessionResume,
|
|
5001
|
+
parseBidDimensions,
|
|
4801
5002
|
registerPrebidAnalytics,
|
|
4802
|
-
resetTcfListener,
|
|
4803
5003
|
sendEvents,
|
|
4804
5004
|
sessionStarted
|
|
4805
5005
|
});
|