@bidkernel/analytics 0.9.0 → 0.11.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/analytics.global.js +1 -1
- package/dist/index.d.mts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +722 -57
- package/dist/index.mjs +720 -57
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -24,11 +24,299 @@ __export(src_exports, {
|
|
|
24
24
|
PrebidEventDeduper: () => PrebidEventDeduper,
|
|
25
25
|
getPrebidEventKey: () => getPrebidEventKey,
|
|
26
26
|
getbidkernel: () => getbidkernel,
|
|
27
|
+
hookImaPrototype: () => hookImaPrototype,
|
|
28
|
+
initImaInterception: () => initImaInterception,
|
|
27
29
|
isTrustedEndpoint: () => isTrustedEndpoint,
|
|
28
30
|
registerPrebidAnalytics: () => registerPrebidAnalytics
|
|
29
31
|
});
|
|
30
32
|
module.exports = __toCommonJS(src_exports);
|
|
31
33
|
|
|
34
|
+
// ../logger/src/index.ts
|
|
35
|
+
var LogLevel = {
|
|
36
|
+
DEBUG: "DEBUG",
|
|
37
|
+
INFO: "INFO",
|
|
38
|
+
WARN: "WARN",
|
|
39
|
+
ERROR: "ERROR"
|
|
40
|
+
};
|
|
41
|
+
var LOG_LEVEL_MAP = {
|
|
42
|
+
[LogLevel.DEBUG]: 10,
|
|
43
|
+
[LogLevel.INFO]: 20,
|
|
44
|
+
[LogLevel.WARN]: 30,
|
|
45
|
+
[LogLevel.ERROR]: 40
|
|
46
|
+
};
|
|
47
|
+
var COLORS = {
|
|
48
|
+
badge: "color: #2dd4bf; font-weight: bold",
|
|
49
|
+
// teal - [ads] badge
|
|
50
|
+
badgeWarn: "background: #f59e0b; color: #fff; padding: 2px 4px; border-radius: 3px; font-weight: bold",
|
|
51
|
+
// amber - [ads] badge (warning)
|
|
52
|
+
badgeError: "background: #ef4444; color: #fff; padding: 2px 4px; border-radius: 3px; font-weight: bold",
|
|
53
|
+
// red - [ads] badge (error)
|
|
54
|
+
dim: "color: #6b7280",
|
|
55
|
+
// gray - timestamp
|
|
56
|
+
event: "color: #38bdf8; font-weight: bold",
|
|
57
|
+
// blue - event name
|
|
58
|
+
eventWarn: "color: #f59e0b; font-weight: bold",
|
|
59
|
+
// amber - event name (warning)
|
|
60
|
+
eventError: "color: #ef4444; font-weight: bold",
|
|
61
|
+
// red - event name (error)
|
|
62
|
+
reset: "color: inherit"
|
|
63
|
+
// back to default
|
|
64
|
+
};
|
|
65
|
+
var logCounter = 0;
|
|
66
|
+
var localGlobalListeners = /* @__PURE__ */ new Set();
|
|
67
|
+
function getGlobalListeners() {
|
|
68
|
+
if (typeof window !== "undefined") {
|
|
69
|
+
const win = window;
|
|
70
|
+
if (!win.__bidkernelLogListeners) {
|
|
71
|
+
win.__bidkernelLogListeners = /* @__PURE__ */ new Set();
|
|
72
|
+
}
|
|
73
|
+
return win.__bidkernelLogListeners;
|
|
74
|
+
}
|
|
75
|
+
return localGlobalListeners;
|
|
76
|
+
}
|
|
77
|
+
function formatTime(ms) {
|
|
78
|
+
if (ms < 0 || !Number.isFinite(ms)) ms = 0;
|
|
79
|
+
if (ms < 1e3) return `${ms.toFixed(2)}ms`;
|
|
80
|
+
const s = ms / 1e3;
|
|
81
|
+
if (s < 60) return `${s.toFixed(2)}s`;
|
|
82
|
+
const m = Math.floor(s / 60);
|
|
83
|
+
if (m < 60) return `${m}m ${(s % 60).toFixed(2)}s`;
|
|
84
|
+
const h = Math.floor(m / 60);
|
|
85
|
+
return `${h}h ${m % 60}m ${(s % 60).toFixed(2)}s`;
|
|
86
|
+
}
|
|
87
|
+
function normalizeLogLevel(level) {
|
|
88
|
+
if (typeof level === "string") {
|
|
89
|
+
const upper = level.toUpperCase();
|
|
90
|
+
if (upper === "DEBUG" || upper === "INFO" || upper === "WARN" || upper === "ERROR") {
|
|
91
|
+
return upper;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return LogLevel.INFO;
|
|
95
|
+
}
|
|
96
|
+
var Logger = class _Logger {
|
|
97
|
+
_prefix;
|
|
98
|
+
_level;
|
|
99
|
+
_loadedAt;
|
|
100
|
+
_now;
|
|
101
|
+
_console;
|
|
102
|
+
_customFormatTime;
|
|
103
|
+
_listeners = /* @__PURE__ */ new Set();
|
|
104
|
+
constructor(options = {}) {
|
|
105
|
+
this._prefix = options.prefix ?? "[bidkernel]";
|
|
106
|
+
this._level = normalizeLogLevel(options.logLevel ?? LogLevel.INFO);
|
|
107
|
+
this._now = options.now;
|
|
108
|
+
this._console = options.console;
|
|
109
|
+
this._customFormatTime = options.formatTime;
|
|
110
|
+
if (options.onLog) {
|
|
111
|
+
this._listeners.add(options.onLog);
|
|
112
|
+
}
|
|
113
|
+
this._loadedAt = options.loadedAt ?? (this._now ? this._now() : typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now());
|
|
114
|
+
}
|
|
115
|
+
get prefix() {
|
|
116
|
+
return this._prefix;
|
|
117
|
+
}
|
|
118
|
+
set prefix(val) {
|
|
119
|
+
this._prefix = val;
|
|
120
|
+
}
|
|
121
|
+
get logLevel() {
|
|
122
|
+
return this._level;
|
|
123
|
+
}
|
|
124
|
+
set logLevel(val) {
|
|
125
|
+
this._level = normalizeLogLevel(val);
|
|
126
|
+
}
|
|
127
|
+
getLevel() {
|
|
128
|
+
return this._level;
|
|
129
|
+
}
|
|
130
|
+
setLevel(level) {
|
|
131
|
+
this._level = normalizeLogLevel(level);
|
|
132
|
+
}
|
|
133
|
+
getPrefix() {
|
|
134
|
+
return this._prefix;
|
|
135
|
+
}
|
|
136
|
+
setPrefix(prefix) {
|
|
137
|
+
this._prefix = prefix;
|
|
138
|
+
}
|
|
139
|
+
resetTiming(loadedAt) {
|
|
140
|
+
this._loadedAt = loadedAt ?? (this._now ? this._now() : typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now());
|
|
141
|
+
}
|
|
142
|
+
getLoadedAt() {
|
|
143
|
+
return this._loadedAt;
|
|
144
|
+
}
|
|
145
|
+
addListener(listener) {
|
|
146
|
+
this._listeners.add(listener);
|
|
147
|
+
return () => {
|
|
148
|
+
this._listeners.delete(listener);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
removeListener(listener) {
|
|
152
|
+
this._listeners.delete(listener);
|
|
153
|
+
}
|
|
154
|
+
isEnabled(level) {
|
|
155
|
+
const target = normalizeLogLevel(level);
|
|
156
|
+
return (LOG_LEVEL_MAP[target] ?? 20) >= (LOG_LEVEL_MAP[this._level] ?? 20);
|
|
157
|
+
}
|
|
158
|
+
formatTime(ms) {
|
|
159
|
+
if (this._customFormatTime) {
|
|
160
|
+
return this._customFormatTime(ms);
|
|
161
|
+
}
|
|
162
|
+
return formatTime(ms);
|
|
163
|
+
}
|
|
164
|
+
_getConsole() {
|
|
165
|
+
if (this._console) return this._console;
|
|
166
|
+
if (typeof console !== "undefined") return console;
|
|
167
|
+
return void 0;
|
|
168
|
+
}
|
|
169
|
+
_getElapsed() {
|
|
170
|
+
const current = this._now ? this._now() : typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
|
|
171
|
+
return Math.max(0, current - this._loadedAt);
|
|
172
|
+
}
|
|
173
|
+
_dispatchRecord(record) {
|
|
174
|
+
for (const l of this._listeners) {
|
|
175
|
+
try {
|
|
176
|
+
l(record);
|
|
177
|
+
} catch {
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const globalListeners = getGlobalListeners();
|
|
181
|
+
for (const gl of globalListeners) {
|
|
182
|
+
if (!this._listeners.has(gl)) {
|
|
183
|
+
try {
|
|
184
|
+
gl(record);
|
|
185
|
+
} catch {
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (typeof window !== "undefined" && typeof window.dispatchEvent === "function") {
|
|
190
|
+
try {
|
|
191
|
+
window.dispatchEvent(new CustomEvent("__bidkernel_log__", { detail: record }));
|
|
192
|
+
} catch {
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
log(level, nameOrMsg, ...args) {
|
|
197
|
+
const normLevel = normalizeLogLevel(level);
|
|
198
|
+
if (!this.isEnabled(normLevel)) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const elapsed = this._getElapsed();
|
|
202
|
+
const formattedTimeStr = this.formatTime(elapsed);
|
|
203
|
+
const nowEpoch = Date.now();
|
|
204
|
+
const recordId = `bk_log_${nowEpoch}_${++logCounter}`;
|
|
205
|
+
const record = {
|
|
206
|
+
id: recordId,
|
|
207
|
+
timestamp: nowEpoch,
|
|
208
|
+
elapsedMs: elapsed,
|
|
209
|
+
level: normLevel,
|
|
210
|
+
prefix: this._prefix,
|
|
211
|
+
message: nameOrMsg,
|
|
212
|
+
args,
|
|
213
|
+
data: args.length === 1 ? args[0] : args.length > 1 ? args : void 0
|
|
214
|
+
};
|
|
215
|
+
this._dispatchRecord(record);
|
|
216
|
+
const c = this._getConsole();
|
|
217
|
+
if (!c) return;
|
|
218
|
+
let badgeStyle = COLORS.badge;
|
|
219
|
+
let eventStyle = COLORS.event;
|
|
220
|
+
if (normLevel === LogLevel.WARN) {
|
|
221
|
+
badgeStyle = COLORS.badgeWarn;
|
|
222
|
+
eventStyle = COLORS.eventWarn;
|
|
223
|
+
} else if (normLevel === LogLevel.ERROR) {
|
|
224
|
+
badgeStyle = COLORS.badgeError;
|
|
225
|
+
eventStyle = COLORS.eventError;
|
|
226
|
+
}
|
|
227
|
+
const fmt = `%c${this._prefix}%c ${formattedTimeStr} %c${nameOrMsg}%c`;
|
|
228
|
+
const styles = [badgeStyle, COLORS.dim, eventStyle, COLORS.reset];
|
|
229
|
+
const callArgs = [fmt, ...styles];
|
|
230
|
+
if (args.length > 0) {
|
|
231
|
+
callArgs.push(...args);
|
|
232
|
+
}
|
|
233
|
+
switch (normLevel) {
|
|
234
|
+
case LogLevel.DEBUG:
|
|
235
|
+
if (typeof c.log === "function") {
|
|
236
|
+
c.log(...callArgs);
|
|
237
|
+
} else if (typeof c.debug === "function") {
|
|
238
|
+
c.debug(...callArgs);
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
case LogLevel.INFO:
|
|
242
|
+
if (typeof c.info === "function") {
|
|
243
|
+
c.info(...callArgs);
|
|
244
|
+
} else if (typeof c.log === "function") {
|
|
245
|
+
c.log(...callArgs);
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
case LogLevel.WARN:
|
|
249
|
+
if (typeof c.warn === "function") {
|
|
250
|
+
c.warn(...callArgs);
|
|
251
|
+
} else if (typeof c.log === "function") {
|
|
252
|
+
c.log(...callArgs);
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
case LogLevel.ERROR:
|
|
256
|
+
if (typeof c.error === "function") {
|
|
257
|
+
c.error(...callArgs);
|
|
258
|
+
} else if (typeof c.log === "function") {
|
|
259
|
+
c.log(...callArgs);
|
|
260
|
+
}
|
|
261
|
+
break;
|
|
262
|
+
default:
|
|
263
|
+
if (typeof c.log === "function") {
|
|
264
|
+
c.log(...callArgs);
|
|
265
|
+
}
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
debug(nameOrMsg, ...args) {
|
|
270
|
+
this.log(LogLevel.DEBUG, nameOrMsg, ...args);
|
|
271
|
+
}
|
|
272
|
+
info(nameOrMsg, ...args) {
|
|
273
|
+
this.log(LogLevel.INFO, nameOrMsg, ...args);
|
|
274
|
+
}
|
|
275
|
+
warn(nameOrMsg, ...args) {
|
|
276
|
+
this.log(LogLevel.WARN, nameOrMsg, ...args);
|
|
277
|
+
}
|
|
278
|
+
error(nameOrMsg, ...args) {
|
|
279
|
+
this.log(LogLevel.ERROR, nameOrMsg, ...args);
|
|
280
|
+
}
|
|
281
|
+
logEvent(event) {
|
|
282
|
+
if (!event) return;
|
|
283
|
+
if (event.data !== void 0) {
|
|
284
|
+
this.log(event.level, event.eventName, event.data);
|
|
285
|
+
} else {
|
|
286
|
+
this.log(event.level, event.eventName);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
child(subNamespace, options = {}) {
|
|
290
|
+
let childPrefix = this._prefix;
|
|
291
|
+
if (subNamespace) {
|
|
292
|
+
const formattedSub = subNamespace.startsWith("[") && subNamespace.endsWith("]") ? subNamespace : `[${subNamespace}]`;
|
|
293
|
+
childPrefix = `${this._prefix}${formattedSub}`;
|
|
294
|
+
}
|
|
295
|
+
return new _Logger({
|
|
296
|
+
prefix: childPrefix,
|
|
297
|
+
logLevel: options.logLevel ?? this._level,
|
|
298
|
+
loadedAt: options.loadedAt ?? this._loadedAt,
|
|
299
|
+
now: options.now ?? this._now,
|
|
300
|
+
console: options.console ?? this._console,
|
|
301
|
+
formatTime: options.formatTime ?? this._customFormatTime,
|
|
302
|
+
...options
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
withPrefix(prefix) {
|
|
306
|
+
return new _Logger({
|
|
307
|
+
prefix,
|
|
308
|
+
logLevel: this._level,
|
|
309
|
+
loadedAt: this._loadedAt,
|
|
310
|
+
now: this._now,
|
|
311
|
+
console: this._console,
|
|
312
|
+
formatTime: this._customFormatTime
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
function createLogger(options) {
|
|
317
|
+
return new Logger(options);
|
|
318
|
+
}
|
|
319
|
+
|
|
32
320
|
// ../../protogen/trace_event.ts
|
|
33
321
|
var import_wire = require("@bufbuild/protobuf/wire");
|
|
34
322
|
var TraceEventType = {
|
|
@@ -998,8 +1286,264 @@ function parseBidDimensions(bid) {
|
|
|
998
1286
|
height: Number.isFinite(bid?.height) ? bid.height : 0
|
|
999
1287
|
};
|
|
1000
1288
|
}
|
|
1289
|
+
var adsLoaderListenerMap = /* @__PURE__ */ new WeakMap();
|
|
1290
|
+
function hookAdsManagerLoadedEvent(loadedEventCtor) {
|
|
1291
|
+
if (!loadedEventCtor) return;
|
|
1292
|
+
try {
|
|
1293
|
+
const loadedProto = loadedEventCtor.prototype;
|
|
1294
|
+
if (loadedProto && typeof loadedProto.getAdsManager === "function" && !loadedProto.getAdsManager.__bidkernelHooked) {
|
|
1295
|
+
const originalGetAdsManager = loadedProto.getAdsManager;
|
|
1296
|
+
const hookedGetAdsManager = function(...args) {
|
|
1297
|
+
const adsManager = originalGetAdsManager.apply(this, args);
|
|
1298
|
+
if (adsManager) {
|
|
1299
|
+
for (const instance of BidkernelPrebidAnalytics.getActiveInstances()) {
|
|
1300
|
+
try {
|
|
1301
|
+
instance.attachImaAdsManager(adsManager);
|
|
1302
|
+
} catch {
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
return adsManager;
|
|
1307
|
+
};
|
|
1308
|
+
hookedGetAdsManager.__bidkernelHooked = true;
|
|
1309
|
+
loadedProto.getAdsManager = hookedGetAdsManager;
|
|
1310
|
+
}
|
|
1311
|
+
} catch {
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
function hookAdsManagerPrototype(adsManagerCtorOrProto) {
|
|
1315
|
+
if (!adsManagerCtorOrProto) return;
|
|
1316
|
+
try {
|
|
1317
|
+
const proto = adsManagerCtorOrProto.prototype || adsManagerCtorOrProto;
|
|
1318
|
+
if (proto && typeof proto.init === "function" && !proto.init.__bidkernelHooked) {
|
|
1319
|
+
const origInit = proto.init;
|
|
1320
|
+
const hookedInit = function(...args) {
|
|
1321
|
+
for (const instance of BidkernelPrebidAnalytics.getActiveInstances()) {
|
|
1322
|
+
try {
|
|
1323
|
+
instance.attachImaAdsManager(this);
|
|
1324
|
+
} catch {
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
return origInit.apply(this, args);
|
|
1328
|
+
};
|
|
1329
|
+
hookedInit.__bidkernelHooked = true;
|
|
1330
|
+
proto.init = hookedInit;
|
|
1331
|
+
}
|
|
1332
|
+
if (proto && typeof proto.start === "function" && !proto.start.__bidkernelHooked) {
|
|
1333
|
+
const origStart = proto.start;
|
|
1334
|
+
const hookedStart = function(...args) {
|
|
1335
|
+
for (const instance of BidkernelPrebidAnalytics.getActiveInstances()) {
|
|
1336
|
+
try {
|
|
1337
|
+
instance.attachImaAdsManager(this);
|
|
1338
|
+
} catch {
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
return origStart.apply(this, args);
|
|
1342
|
+
};
|
|
1343
|
+
hookedStart.__bidkernelHooked = true;
|
|
1344
|
+
proto.start = hookedStart;
|
|
1345
|
+
}
|
|
1346
|
+
} catch {
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
function hookAdsLoader(adsLoaderCtor) {
|
|
1350
|
+
if (!adsLoaderCtor) return;
|
|
1351
|
+
try {
|
|
1352
|
+
const proto = adsLoaderCtor.prototype;
|
|
1353
|
+
if (!proto) return;
|
|
1354
|
+
if (typeof proto.addEventListener === "function" && !proto.addEventListener.__bidkernelHooked) {
|
|
1355
|
+
const origAddEventListener = proto.addEventListener;
|
|
1356
|
+
const hookedAddEventListener = function(type, listener, ...rest) {
|
|
1357
|
+
if ((type === "adsManagerLoaded" || type === (this?.AdsManagerLoadedEvent?.Type?.ADS_MANAGER_LOADED || "adsManagerLoaded")) && typeof listener === "function") {
|
|
1358
|
+
let wrappedListener = adsLoaderListenerMap.get(listener);
|
|
1359
|
+
if (!wrappedListener) {
|
|
1360
|
+
wrappedListener = function(event) {
|
|
1361
|
+
if (event && typeof event.getAdsManager === "function" && !event.getAdsManager.__bidkernelHooked) {
|
|
1362
|
+
const origGetAdsManager = event.getAdsManager;
|
|
1363
|
+
event.getAdsManager = function(...args) {
|
|
1364
|
+
const adsManager = origGetAdsManager.apply(this, args);
|
|
1365
|
+
if (adsManager) {
|
|
1366
|
+
for (const sdk of BidkernelPrebidAnalytics.getActiveInstances()) {
|
|
1367
|
+
try {
|
|
1368
|
+
sdk.attachImaAdsManager(adsManager);
|
|
1369
|
+
} catch {
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
return adsManager;
|
|
1374
|
+
};
|
|
1375
|
+
event.getAdsManager.__bidkernelHooked = true;
|
|
1376
|
+
}
|
|
1377
|
+
return listener.apply(this, arguments);
|
|
1378
|
+
};
|
|
1379
|
+
adsLoaderListenerMap.set(listener, wrappedListener);
|
|
1380
|
+
}
|
|
1381
|
+
return origAddEventListener.call(this, type, wrappedListener, ...rest);
|
|
1382
|
+
}
|
|
1383
|
+
return origAddEventListener.call(this, type, listener, ...rest);
|
|
1384
|
+
};
|
|
1385
|
+
hookedAddEventListener.__bidkernelHooked = true;
|
|
1386
|
+
proto.addEventListener = hookedAddEventListener;
|
|
1387
|
+
}
|
|
1388
|
+
if (typeof proto.removeEventListener === "function" && !proto.removeEventListener.__bidkernelHooked) {
|
|
1389
|
+
const origRemoveEventListener = proto.removeEventListener;
|
|
1390
|
+
const hookedRemoveEventListener = function(type, listener, ...rest) {
|
|
1391
|
+
const wrapped = typeof listener === "function" ? adsLoaderListenerMap.get(listener) : void 0;
|
|
1392
|
+
return origRemoveEventListener.call(this, type, wrapped || listener, ...rest);
|
|
1393
|
+
};
|
|
1394
|
+
hookedRemoveEventListener.__bidkernelHooked = true;
|
|
1395
|
+
proto.removeEventListener = hookedRemoveEventListener;
|
|
1396
|
+
}
|
|
1397
|
+
} catch {
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
function hookImaPrototype(ima) {
|
|
1401
|
+
if (!ima || typeof ima !== "object") return;
|
|
1402
|
+
try {
|
|
1403
|
+
if (ima.AdsManagerLoadedEvent) {
|
|
1404
|
+
hookAdsManagerLoadedEvent(ima.AdsManagerLoadedEvent);
|
|
1405
|
+
}
|
|
1406
|
+
const loadedDesc = Object.getOwnPropertyDescriptor(ima, "AdsManagerLoadedEvent");
|
|
1407
|
+
if (!loadedDesc || loadedDesc.configurable) {
|
|
1408
|
+
let _loadedEvent = ima.AdsManagerLoadedEvent;
|
|
1409
|
+
try {
|
|
1410
|
+
Object.defineProperty(ima, "AdsManagerLoadedEvent", {
|
|
1411
|
+
configurable: true,
|
|
1412
|
+
enumerable: true,
|
|
1413
|
+
get() {
|
|
1414
|
+
return _loadedEvent;
|
|
1415
|
+
},
|
|
1416
|
+
set(val) {
|
|
1417
|
+
_loadedEvent = val;
|
|
1418
|
+
hookAdsManagerLoadedEvent(val);
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
} catch {
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
if (ima.AdsLoader) {
|
|
1425
|
+
hookAdsLoader(ima.AdsLoader);
|
|
1426
|
+
}
|
|
1427
|
+
const loaderDesc = Object.getOwnPropertyDescriptor(ima, "AdsLoader");
|
|
1428
|
+
if (!loaderDesc || loaderDesc.configurable) {
|
|
1429
|
+
let _loader = ima.AdsLoader;
|
|
1430
|
+
try {
|
|
1431
|
+
Object.defineProperty(ima, "AdsLoader", {
|
|
1432
|
+
configurable: true,
|
|
1433
|
+
enumerable: true,
|
|
1434
|
+
get() {
|
|
1435
|
+
return _loader;
|
|
1436
|
+
},
|
|
1437
|
+
set(val) {
|
|
1438
|
+
_loader = val;
|
|
1439
|
+
hookAdsLoader(val);
|
|
1440
|
+
}
|
|
1441
|
+
});
|
|
1442
|
+
} catch {
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
if (ima.AdsManager) {
|
|
1446
|
+
hookAdsManagerPrototype(ima.AdsManager);
|
|
1447
|
+
}
|
|
1448
|
+
const mgrDesc = Object.getOwnPropertyDescriptor(ima, "AdsManager");
|
|
1449
|
+
if (!mgrDesc || mgrDesc.configurable) {
|
|
1450
|
+
let _mgr = ima.AdsManager;
|
|
1451
|
+
try {
|
|
1452
|
+
Object.defineProperty(ima, "AdsManager", {
|
|
1453
|
+
configurable: true,
|
|
1454
|
+
enumerable: true,
|
|
1455
|
+
get() {
|
|
1456
|
+
return _mgr;
|
|
1457
|
+
},
|
|
1458
|
+
set(val) {
|
|
1459
|
+
_mgr = val;
|
|
1460
|
+
hookAdsManagerPrototype(val);
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
} catch {
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
} catch {
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
function initImaInterception() {
|
|
1470
|
+
if (typeof window === "undefined") return;
|
|
1471
|
+
const win = window;
|
|
1472
|
+
if (win.google?.ima) {
|
|
1473
|
+
hookImaPrototype(win.google.ima);
|
|
1474
|
+
}
|
|
1475
|
+
if (win.google && typeof win.google === "object") {
|
|
1476
|
+
const imaDesc = Object.getOwnPropertyDescriptor(win.google, "ima");
|
|
1477
|
+
if (!imaDesc || imaDesc.configurable) {
|
|
1478
|
+
let _ima = win.google.ima;
|
|
1479
|
+
try {
|
|
1480
|
+
Object.defineProperty(win.google, "ima", {
|
|
1481
|
+
configurable: true,
|
|
1482
|
+
enumerable: true,
|
|
1483
|
+
get() {
|
|
1484
|
+
return _ima;
|
|
1485
|
+
},
|
|
1486
|
+
set(val) {
|
|
1487
|
+
_ima = val;
|
|
1488
|
+
hookImaPrototype(val);
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1491
|
+
} catch {
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
const googleDesc = Object.getOwnPropertyDescriptor(win, "google");
|
|
1496
|
+
if (!googleDesc || googleDesc.configurable) {
|
|
1497
|
+
let _google = win.google;
|
|
1498
|
+
try {
|
|
1499
|
+
Object.defineProperty(win, "google", {
|
|
1500
|
+
configurable: true,
|
|
1501
|
+
enumerable: true,
|
|
1502
|
+
get() {
|
|
1503
|
+
return _google;
|
|
1504
|
+
},
|
|
1505
|
+
set(val) {
|
|
1506
|
+
_google = val;
|
|
1507
|
+
if (_google && typeof _google === "object") {
|
|
1508
|
+
if (_google.ima) {
|
|
1509
|
+
hookImaPrototype(_google.ima);
|
|
1510
|
+
}
|
|
1511
|
+
const iDesc = Object.getOwnPropertyDescriptor(_google, "ima");
|
|
1512
|
+
if (!iDesc || iDesc.configurable) {
|
|
1513
|
+
let _i = _google.ima;
|
|
1514
|
+
try {
|
|
1515
|
+
Object.defineProperty(_google, "ima", {
|
|
1516
|
+
configurable: true,
|
|
1517
|
+
enumerable: true,
|
|
1518
|
+
get() {
|
|
1519
|
+
return _i;
|
|
1520
|
+
},
|
|
1521
|
+
set(iv) {
|
|
1522
|
+
_i = iv;
|
|
1523
|
+
hookImaPrototype(iv);
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1526
|
+
} catch {
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
} catch {
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
if (typeof window !== "undefined") {
|
|
1537
|
+
initImaInterception();
|
|
1538
|
+
}
|
|
1001
1539
|
var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
1002
1540
|
static activeInstances = /* @__PURE__ */ new Set();
|
|
1541
|
+
static getActiveInstances() {
|
|
1542
|
+
return _BidkernelPrebidAnalytics.activeInstances;
|
|
1543
|
+
}
|
|
1544
|
+
static initImaInterception() {
|
|
1545
|
+
initImaInterception();
|
|
1546
|
+
}
|
|
1003
1547
|
config;
|
|
1004
1548
|
queue = [];
|
|
1005
1549
|
errorCount = 0;
|
|
@@ -1036,6 +1580,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1036
1580
|
videoDetachCleanups = /* @__PURE__ */ new Set();
|
|
1037
1581
|
// Compacted bidder participation map per auction: auctionId -> Map<`${bidder}:${adUnitCode}`, BidderOutcomeEntry>
|
|
1038
1582
|
auctionBidderOutcomes = /* @__PURE__ */ new Map();
|
|
1583
|
+
logger;
|
|
1039
1584
|
constructor(config) {
|
|
1040
1585
|
const requestedEndpoint = config.endpoint || "";
|
|
1041
1586
|
const endpoint = !requestedEndpoint || isTrustedEndpoint(requestedEndpoint) ? requestedEndpoint : "";
|
|
@@ -1056,6 +1601,10 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1056
1601
|
pbjsGlobalName: config.pbjsGlobalName || "pbjs",
|
|
1057
1602
|
attachPbjsListeners: config.attachPbjsListeners ?? true
|
|
1058
1603
|
};
|
|
1604
|
+
this.logger = createLogger({
|
|
1605
|
+
prefix: "[bidkernel][prebid-analytics]",
|
|
1606
|
+
logLevel: this.config.logLevel
|
|
1607
|
+
});
|
|
1059
1608
|
if (requestedEndpoint && !endpoint) {
|
|
1060
1609
|
this.log(
|
|
1061
1610
|
"ERROR",
|
|
@@ -1072,6 +1621,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1072
1621
|
if (this.isEnabled) return;
|
|
1073
1622
|
this.isEnabled = true;
|
|
1074
1623
|
_BidkernelPrebidAnalytics.activeInstances.add(this);
|
|
1624
|
+
this.logger.setLevel(this.config.logLevel);
|
|
1075
1625
|
if (!this.config.endpoint) {
|
|
1076
1626
|
this.log("WARN", "Endpoint is empty. Analytics events will not be transmitted.");
|
|
1077
1627
|
}
|
|
@@ -1163,6 +1713,10 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1163
1713
|
}
|
|
1164
1714
|
this.flushTimer = setInterval(() => this.flush(), FLUSH_INTERVAL_MS);
|
|
1165
1715
|
this.resendPersistedBatches();
|
|
1716
|
+
initImaInterception();
|
|
1717
|
+
if (window.google?.ima) {
|
|
1718
|
+
hookImaPrototype(window.google.ima);
|
|
1719
|
+
}
|
|
1166
1720
|
}
|
|
1167
1721
|
}
|
|
1168
1722
|
disable() {
|
|
@@ -1643,6 +2197,72 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1643
2197
|
this.cachedWinningBids.delete(oldest.value);
|
|
1644
2198
|
}
|
|
1645
2199
|
}
|
|
2200
|
+
/**
|
|
2201
|
+
* Searches cached winning bids for an entry matching the given filters (creativeId,
|
|
2202
|
+
* adId, or mediaType), falling back to the most recent winning video bid.
|
|
2203
|
+
*/
|
|
2204
|
+
findCachedWinningBid(filter) {
|
|
2205
|
+
const now = Date.now();
|
|
2206
|
+
const isConsumed = (entry) => {
|
|
2207
|
+
return this.hasImpressionEmitted(
|
|
2208
|
+
entry.adUnitCode,
|
|
2209
|
+
void 0,
|
|
2210
|
+
entry.auctionId,
|
|
2211
|
+
entry.bidTrace.creativeId
|
|
2212
|
+
);
|
|
2213
|
+
};
|
|
2214
|
+
if (filter?.creativeId || filter?.adId) {
|
|
2215
|
+
for (const entry of Array.from(this.cachedWinningBids.values())) {
|
|
2216
|
+
if (now - entry.timestamp > CACHED_BID_TTL_MS) continue;
|
|
2217
|
+
if (filter.creativeId && (entry.bidTrace.creativeId === filter.creativeId || entry.rawBid?.creativeId === filter.creativeId) || filter.adId && (entry.rawBid?.adId === filter.adId || entry.adUnitCode === filter.adId)) {
|
|
2218
|
+
return entry;
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
let bestUnconsumedMatch;
|
|
2223
|
+
if (filter?.mediaType) {
|
|
2224
|
+
for (const entry of Array.from(this.cachedWinningBids.values())) {
|
|
2225
|
+
if (now - entry.timestamp > CACHED_BID_TTL_MS) continue;
|
|
2226
|
+
const isEntryVideo = entry.bidTrace.mediaType === filter.mediaType || entry.rawBid?.mediaType === filter.mediaType || filter.mediaType === "video" && entry.rawBid?.mediaTypes?.video !== void 0;
|
|
2227
|
+
if (isEntryVideo) {
|
|
2228
|
+
if (!isConsumed(entry)) {
|
|
2229
|
+
if (!bestUnconsumedMatch || entry.timestamp < bestUnconsumedMatch.timestamp) {
|
|
2230
|
+
bestUnconsumedMatch = entry;
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
if (bestUnconsumedMatch) return bestUnconsumedMatch;
|
|
2236
|
+
let bestFallbackMatch;
|
|
2237
|
+
for (const entry of Array.from(this.cachedWinningBids.values())) {
|
|
2238
|
+
if (now - entry.timestamp > CACHED_BID_TTL_MS) continue;
|
|
2239
|
+
const isEntryVideo = entry.bidTrace.mediaType === filter.mediaType || entry.rawBid?.mediaType === filter.mediaType || filter.mediaType === "video" && entry.rawBid?.mediaTypes?.video !== void 0;
|
|
2240
|
+
if (isEntryVideo) {
|
|
2241
|
+
if (!bestFallbackMatch || entry.timestamp > bestFallbackMatch.timestamp) {
|
|
2242
|
+
bestFallbackMatch = entry;
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
if (bestFallbackMatch) return bestFallbackMatch;
|
|
2247
|
+
}
|
|
2248
|
+
for (const entry of Array.from(this.cachedWinningBids.values())) {
|
|
2249
|
+
if (now - entry.timestamp > CACHED_BID_TTL_MS) continue;
|
|
2250
|
+
if (!isConsumed(entry)) {
|
|
2251
|
+
if (!bestUnconsumedMatch || entry.timestamp > bestUnconsumedMatch.timestamp) {
|
|
2252
|
+
bestUnconsumedMatch = entry;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
if (bestUnconsumedMatch) return bestUnconsumedMatch;
|
|
2257
|
+
let bestRecent;
|
|
2258
|
+
for (const entry of Array.from(this.cachedWinningBids.values())) {
|
|
2259
|
+
if (now - entry.timestamp > CACHED_BID_TTL_MS) continue;
|
|
2260
|
+
if (!bestRecent || entry.timestamp > bestRecent.timestamp) {
|
|
2261
|
+
bestRecent = entry;
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
return bestRecent;
|
|
2265
|
+
}
|
|
1646
2266
|
/** Records a dedup key, evicting oldest-first at the cap. */
|
|
1647
2267
|
addImpressionKey(key) {
|
|
1648
2268
|
if (this.slotEmittedImpressionKeys.has(key)) return;
|
|
@@ -1802,14 +2422,40 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1802
2422
|
return () => {
|
|
1803
2423
|
};
|
|
1804
2424
|
}
|
|
2425
|
+
if (!adsManager.__bidkernelAttachedInstances) {
|
|
2426
|
+
try {
|
|
2427
|
+
Object.defineProperty(adsManager, "__bidkernelAttachedInstances", {
|
|
2428
|
+
value: /* @__PURE__ */ new Set(),
|
|
2429
|
+
configurable: true,
|
|
2430
|
+
writable: true
|
|
2431
|
+
});
|
|
2432
|
+
} catch {
|
|
2433
|
+
adsManager.__bidkernelAttachedInstances = /* @__PURE__ */ new Set();
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
if (adsManager.__bidkernelAttachedInstances.has(this)) {
|
|
2437
|
+
return () => {
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
adsManager.__bidkernelAttachedInstances.add(this);
|
|
1805
2441
|
const slotId = options?.slotId || options?.adUnitCode || "video";
|
|
1806
2442
|
const adUnitCode = options?.adUnitCode || slotId;
|
|
1807
2443
|
const auctionId = options?.auctionId || "";
|
|
1808
2444
|
const transactionId = options?.transactionId || "";
|
|
1809
|
-
const getWinningBid = () => {
|
|
1810
|
-
|
|
2445
|
+
const getWinningBid = (adData) => {
|
|
2446
|
+
let cached = (auctionId ? this.getCachedBid(`${auctionId}:${adUnitCode}`) : void 0) || (auctionId && slotId !== adUnitCode ? this.getCachedBid(`${auctionId}:${slotId}`) : void 0) || (adUnitCode !== "video" ? this.getCachedBid(adUnitCode) : void 0) || (slotId !== adUnitCode && slotId !== "video" ? this.getCachedBid(slotId) : void 0);
|
|
2447
|
+
if (!cached) {
|
|
2448
|
+
cached = this.findCachedWinningBid({
|
|
2449
|
+
creativeId: adData?.creativeId,
|
|
2450
|
+
adId: adData?.adId,
|
|
2451
|
+
mediaType: "video"
|
|
2452
|
+
});
|
|
2453
|
+
}
|
|
2454
|
+
return cached;
|
|
1811
2455
|
};
|
|
2456
|
+
let adStarted = false;
|
|
1812
2457
|
const onAdStartedOrImpression = (event) => {
|
|
2458
|
+
adStarted = true;
|
|
1813
2459
|
this.log("DEBUG", "IMA AdEvent.STARTED / IMPRESSION received", event);
|
|
1814
2460
|
const ad = typeof event?.getAd === "function" ? event.getAd() : event?.ad;
|
|
1815
2461
|
const adData = {};
|
|
@@ -1820,16 +2466,20 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1820
2466
|
adData.duration = typeof ad.getDuration === "function" ? ad.getDuration() : ad.duration;
|
|
1821
2467
|
adData.advertiserName = typeof ad.getAdvertiserName === "function" ? ad.getAdvertiserName() : "";
|
|
1822
2468
|
}
|
|
1823
|
-
const cached = getWinningBid();
|
|
2469
|
+
const cached = getWinningBid(adData);
|
|
2470
|
+
const resolvedSlotId = options?.slotId && options.slotId !== "video" ? options.slotId : options?.adUnitCode && options.adUnitCode !== "video" ? options.adUnitCode : cached?.adUnitCode || options?.slotId || options?.adUnitCode || "video";
|
|
2471
|
+
const resolvedAdUnitCode = options?.adUnitCode && options.adUnitCode !== "video" ? options.adUnitCode : cached?.adUnitCode || resolvedSlotId;
|
|
2472
|
+
const resolvedAuctionId = auctionId || cached?.auctionId || "";
|
|
2473
|
+
const resolvedTransactionId = transactionId || cached?.transactionId || "";
|
|
1824
2474
|
const mergedBid = {
|
|
1825
2475
|
...cached?.rawBid || options?.bid,
|
|
1826
2476
|
mediaType: "video",
|
|
1827
2477
|
creativeId: adData.creativeId || cached?.bidTrace?.creativeId || options?.bid?.creativeId || ""
|
|
1828
2478
|
};
|
|
1829
|
-
const emitted = this.recordImpression(
|
|
1830
|
-
adUnitCode,
|
|
1831
|
-
auctionId:
|
|
1832
|
-
transactionId:
|
|
2479
|
+
const emitted = this.recordImpression(resolvedSlotId, {
|
|
2480
|
+
adUnitCode: resolvedAdUnitCode,
|
|
2481
|
+
auctionId: resolvedAuctionId,
|
|
2482
|
+
transactionId: resolvedTransactionId,
|
|
1833
2483
|
mediaType: "video",
|
|
1834
2484
|
bid: mergedBid,
|
|
1835
2485
|
metadata: {
|
|
@@ -1841,7 +2491,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1841
2491
|
});
|
|
1842
2492
|
if (emitted && options?.onImpression) {
|
|
1843
2493
|
try {
|
|
1844
|
-
options.onImpression(
|
|
2494
|
+
options.onImpression(resolvedSlotId, { ad, bid: mergedBid });
|
|
1845
2495
|
} catch (e) {
|
|
1846
2496
|
this.log("ERROR", "Error in onImpression callback", e);
|
|
1847
2497
|
}
|
|
@@ -1860,10 +2510,11 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1860
2510
|
const onAdClick = (event) => {
|
|
1861
2511
|
this.log("DEBUG", "IMA AdEvent.CLICK received", event);
|
|
1862
2512
|
const cached = getWinningBid();
|
|
2513
|
+
const resolvedAdUnitCode = options?.adUnitCode && options.adUnitCode !== "video" ? options.adUnitCode : cached?.adUnitCode || slotId;
|
|
1863
2514
|
this.enqueue(TraceEventType.CLICK, "click", {
|
|
1864
2515
|
auctionId: auctionId || cached?.auctionId,
|
|
1865
2516
|
transactionId: transactionId || cached?.transactionId,
|
|
1866
|
-
adUnitCode,
|
|
2517
|
+
adUnitCode: resolvedAdUnitCode,
|
|
1867
2518
|
bid: cached?.bidTrace || options?.bid,
|
|
1868
2519
|
metadata: {
|
|
1869
2520
|
...options?.metadata,
|
|
@@ -1877,14 +2528,16 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1877
2528
|
const msg = (err && typeof err.getMessage === "function" ? err.getMessage() : err?.message) || String(err || "IMA ad error");
|
|
1878
2529
|
const code = (err && typeof err.getErrorCode === "function" ? err.getErrorCode() : err?.code) || "";
|
|
1879
2530
|
const cached = getWinningBid();
|
|
2531
|
+
const resolvedAdUnitCode = options?.adUnitCode && options.adUnitCode !== "video" ? options.adUnitCode : cached?.adUnitCode || slotId;
|
|
1880
2532
|
this.enqueue(TraceEventType.AD_RENDER_FAILED, "adRenderFailed", {
|
|
1881
2533
|
auctionId: auctionId || cached?.auctionId,
|
|
1882
2534
|
transactionId: transactionId || cached?.transactionId,
|
|
1883
|
-
adUnitCode,
|
|
2535
|
+
adUnitCode: resolvedAdUnitCode,
|
|
1884
2536
|
bid: cached?.bidTrace || options?.bid,
|
|
1885
2537
|
metadata: {
|
|
1886
2538
|
...options?.metadata,
|
|
1887
|
-
reason: "ima_ad_error",
|
|
2539
|
+
reason: adStarted ? "ima_playback_error" : "ima_ad_error",
|
|
2540
|
+
playback_phase: adStarted ? "post_start" : "pre_start",
|
|
1888
2541
|
message: msg,
|
|
1889
2542
|
...code ? { ima_error_code: String(code) } : {}
|
|
1890
2543
|
},
|
|
@@ -1901,7 +2554,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1901
2554
|
const googleIma = typeof window !== "undefined" ? window.google?.ima : void 0;
|
|
1902
2555
|
const adEventType = googleIma?.AdEvent?.Type || {};
|
|
1903
2556
|
const adErrorEventType = googleIma?.AdErrorEvent?.Type || {};
|
|
1904
|
-
const
|
|
2557
|
+
const rawListeners = [
|
|
1905
2558
|
{ type: adEventType.STARTED || "started", handler: onAdStartedOrImpression },
|
|
1906
2559
|
{ type: adEventType.IMPRESSION || "impression", handler: onAdStartedOrImpression },
|
|
1907
2560
|
{
|
|
@@ -1917,6 +2570,14 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1917
2570
|
{ type: adEventType.CLICK || "click", handler: onAdClick },
|
|
1918
2571
|
{ type: adErrorEventType.AD_ERROR || "adError", handler: onAdError }
|
|
1919
2572
|
];
|
|
2573
|
+
const seenListenerTypes = /* @__PURE__ */ new Set();
|
|
2574
|
+
const listeners = [];
|
|
2575
|
+
for (const l of rawListeners) {
|
|
2576
|
+
if (!seenListenerTypes.has(l.type)) {
|
|
2577
|
+
seenListenerTypes.add(l.type);
|
|
2578
|
+
listeners.push(l);
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
1920
2581
|
for (const { type, handler } of listeners) {
|
|
1921
2582
|
try {
|
|
1922
2583
|
adsManager.addEventListener(type, handler);
|
|
@@ -1924,6 +2585,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1924
2585
|
}
|
|
1925
2586
|
}
|
|
1926
2587
|
const cleanup = () => {
|
|
2588
|
+
adsManager.__bidkernelAttachedInstances?.delete(this);
|
|
1927
2589
|
for (const { type, handler } of listeners) {
|
|
1928
2590
|
try {
|
|
1929
2591
|
adsManager.removeEventListener(type, handler);
|
|
@@ -2245,6 +2907,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2245
2907
|
} else {
|
|
2246
2908
|
this.pageUrl = "";
|
|
2247
2909
|
}
|
|
2910
|
+
this.logger.resetTiming();
|
|
2248
2911
|
extendSession();
|
|
2249
2912
|
this.enable();
|
|
2250
2913
|
}
|
|
@@ -2309,7 +2972,8 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2309
2972
|
const adUnitCode = data.adUnitCode || "";
|
|
2310
2973
|
const cpm = Number.isFinite(data.originalCpm) ? data.originalCpm : Number.isFinite(data.cpm) ? data.cpm : 0;
|
|
2311
2974
|
const latencyMs = Number.isFinite(data.timeToRespond) ? data.timeToRespond : 0;
|
|
2312
|
-
const
|
|
2975
|
+
const resMediaTypes = Object.keys(data.mediaTypes || {});
|
|
2976
|
+
const mediaType = data.mediaType || (data.mediaTypes?.video ? "video" : resMediaTypes.length > 0 ? resMediaTypes[0] : "banner");
|
|
2313
2977
|
if (auctionId && bidder) {
|
|
2314
2978
|
const auctionMap = this.getOrCreateAuctionOutcomes(auctionId);
|
|
2315
2979
|
const key = `${bidder}:${adUnitCode}`;
|
|
@@ -2382,13 +3046,15 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2382
3046
|
const auctionId = data.auctionId || "";
|
|
2383
3047
|
const transactionId = data.transactionId || "";
|
|
2384
3048
|
const adUnitCode = data.adUnitCode || data.adId || "";
|
|
3049
|
+
const wonMediaTypes = Object.keys(data.mediaTypes || {});
|
|
3050
|
+
const resolvedMediaType = data.mediaType || (data.mediaTypes?.video ? "video" : wonMediaTypes.length > 0 ? wonMediaTypes[0] : "banner");
|
|
2385
3051
|
const bidTrace = {
|
|
2386
3052
|
bidder: data.bidderCode || data.bidder || "",
|
|
2387
3053
|
cpm: Number.isFinite(data.originalCpm) ? data.originalCpm : Number.isFinite(data.cpm) ? data.cpm : 0,
|
|
2388
3054
|
currency: data.originalCurrency ?? data.currency ?? "USD",
|
|
2389
3055
|
...parseBidDimensions(data),
|
|
2390
3056
|
dealId: data.dealId || "",
|
|
2391
|
-
mediaType:
|
|
3057
|
+
mediaType: resolvedMediaType,
|
|
2392
3058
|
latencyMs: Number.isFinite(data.timeToRespond) ? data.timeToRespond : 0,
|
|
2393
3059
|
advertiserDomain: data.meta?.advertiserDomains?.[0] || "",
|
|
2394
3060
|
creativeId: data.creativeId || ""
|
|
@@ -2477,13 +3143,15 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2477
3143
|
const slotKey = data.adUnitCode || bid.adUnitCode || "";
|
|
2478
3144
|
const altKey = data.adId || bid.adId || "";
|
|
2479
3145
|
const cached = (auctionId && slotKey ? this.getCachedBid(`${auctionId}:${slotKey}`) : void 0) || (auctionId && altKey ? this.getCachedBid(`${auctionId}:${altKey}`) : void 0) || (slotKey ? this.getCachedBid(slotKey) : void 0) || (altKey ? this.getCachedBid(altKey) : void 0);
|
|
3146
|
+
const isVideo = mediaType === "video" || bid.mediaType === "video" || bid.mediaTypes?.video !== void 0 || cached?.bidTrace?.mediaType === "video" || cached?.rawBid?.mediaType === "video" || adUnitCode && this.slotViewabilityRecords.get(adUnitCode)?.mediaType === "video";
|
|
3147
|
+
const resolvedMediaType = isVideo ? "video" : mediaType || cached?.bidTrace?.mediaType || "banner";
|
|
2480
3148
|
const bidTrace = {
|
|
2481
3149
|
bidder: bid.bidderCode || bid.bidder || cached?.bidTrace?.bidder || "",
|
|
2482
3150
|
cpm: Number.isFinite(bid.originalCpm) ? bid.originalCpm : Number.isFinite(bid.cpm) ? bid.cpm : cached?.bidTrace?.cpm ?? 0,
|
|
2483
3151
|
currency: bid.originalCurrency ?? bid.currency ?? cached?.bidTrace?.currency ?? "USD",
|
|
2484
3152
|
...parseBidDimensions(bid).width ? parseBidDimensions(bid) : cached?.bidTrace ? { width: cached.bidTrace.width, height: cached.bidTrace.height } : parseBidDimensions(bid),
|
|
2485
3153
|
dealId: bid.dealId || cached?.bidTrace?.dealId || "",
|
|
2486
|
-
mediaType:
|
|
3154
|
+
mediaType: resolvedMediaType,
|
|
2487
3155
|
latencyMs: Number.isFinite(bid.timeToRespond) ? bid.timeToRespond : cached?.bidTrace?.latencyMs ?? 0,
|
|
2488
3156
|
advertiserDomain: bid.meta?.advertiserDomains?.[0] || cached?.bidTrace?.advertiserDomain || "",
|
|
2489
3157
|
creativeId: bid.creativeId || cached?.bidTrace?.creativeId || ""
|
|
@@ -2522,28 +3190,35 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2522
3190
|
}
|
|
2523
3191
|
}
|
|
2524
3192
|
const currentRefreshIndex = adUnitCode ? this.slotRefreshIndices.get(adUnitCode) ?? (record ? record.refreshIndex : 0) : 0;
|
|
2525
|
-
|
|
2526
|
-
adUnitCode
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
if (
|
|
2533
|
-
|
|
3193
|
+
if (!isVideo) {
|
|
3194
|
+
const alreadyEmitted = adUnitCode ? this.hasImpressionEmitted(
|
|
3195
|
+
adUnitCode,
|
|
3196
|
+
currentRefreshIndex,
|
|
3197
|
+
resolvedAuctionId,
|
|
3198
|
+
bidTrace.creativeId
|
|
3199
|
+
) : false;
|
|
3200
|
+
if (!alreadyEmitted) {
|
|
3201
|
+
if (adUnitCode) {
|
|
3202
|
+
this.markImpressionEmitted(
|
|
3203
|
+
adUnitCode,
|
|
3204
|
+
currentRefreshIndex,
|
|
3205
|
+
resolvedAuctionId,
|
|
3206
|
+
bidTrace.creativeId
|
|
3207
|
+
);
|
|
3208
|
+
}
|
|
3209
|
+
this.enqueue(TraceEventType.IMPRESSION, "impression", {
|
|
3210
|
+
auctionId: resolvedAuctionId,
|
|
3211
|
+
transactionId: resolvedTransactionId,
|
|
2534
3212
|
adUnitCode,
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
);
|
|
3213
|
+
bid: bidTrace,
|
|
3214
|
+
metadata: { refresh_index: String(currentRefreshIndex) }
|
|
3215
|
+
});
|
|
2539
3216
|
}
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
adUnitCode
|
|
2544
|
-
|
|
2545
|
-
metadata: { refresh_index: String(currentRefreshIndex) }
|
|
2546
|
-
});
|
|
3217
|
+
} else {
|
|
3218
|
+
this.log(
|
|
3219
|
+
"DEBUG",
|
|
3220
|
+
`adRenderSucceeded received for video ad unit ${adUnitCode || "unknown"}: suppressing IMPRESSION until verified video lifecycle event`
|
|
3221
|
+
);
|
|
2547
3222
|
}
|
|
2548
3223
|
if (this.config.viewabilityEnabled && typeof document !== "undefined") {
|
|
2549
3224
|
let el = null;
|
|
@@ -2579,7 +3254,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2579
3254
|
adUnitCode,
|
|
2580
3255
|
auctionId: resolvedAuctionId,
|
|
2581
3256
|
transactionId: resolvedTransactionId,
|
|
2582
|
-
mediaType,
|
|
3257
|
+
mediaType: resolvedMediaType,
|
|
2583
3258
|
bid: bidTrace,
|
|
2584
3259
|
refreshIndex: currentRefreshIndex,
|
|
2585
3260
|
emitRefreshEvent: false
|
|
@@ -2912,25 +3587,13 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2912
3587
|
}
|
|
2913
3588
|
}
|
|
2914
3589
|
log(level, msg, ...args) {
|
|
2915
|
-
|
|
2916
|
-
if (levels[level] < levels[this.config.logLevel]) return;
|
|
2917
|
-
const prefix = `[bidkernel][prebid-analytics][${level}]`;
|
|
2918
|
-
switch (level) {
|
|
2919
|
-
case "DEBUG":
|
|
2920
|
-
console.debug(prefix, msg, ...args);
|
|
2921
|
-
break;
|
|
2922
|
-
case "INFO":
|
|
2923
|
-
console.info(prefix, msg, ...args);
|
|
2924
|
-
break;
|
|
2925
|
-
case "WARN":
|
|
2926
|
-
console.warn(prefix, msg, ...args);
|
|
2927
|
-
break;
|
|
2928
|
-
case "ERROR":
|
|
2929
|
-
console.error(prefix, msg, ...args);
|
|
2930
|
-
break;
|
|
2931
|
-
}
|
|
3590
|
+
this.logger.log(level, msg, ...args);
|
|
2932
3591
|
}
|
|
2933
3592
|
};
|
|
3593
|
+
var defaultLogger = createLogger({
|
|
3594
|
+
prefix: "[bidkernel]",
|
|
3595
|
+
logLevel: "INFO"
|
|
3596
|
+
});
|
|
2934
3597
|
function extractAnalyticsOptions(config, allowProviderless = true) {
|
|
2935
3598
|
if (!config) return null;
|
|
2936
3599
|
if (Array.isArray(config)) {
|
|
@@ -2987,8 +3650,8 @@ function registerPrebidAnalytics(pbjsGlobalName = "pbjs", defaults) {
|
|
|
2987
3650
|
...options
|
|
2988
3651
|
};
|
|
2989
3652
|
if (pinnedEndpoint && !sameEndpointOrigin(merged.endpoint || "", pinnedEndpoint)) {
|
|
2990
|
-
|
|
2991
|
-
`
|
|
3653
|
+
defaultLogger.warn(
|
|
3654
|
+
`Ignoring analytics endpoint change to ${merged.endpoint || "(empty)"}: this page is pinned to ${pinnedEndpoint}. Reload to change the ingest endpoint.`
|
|
2992
3655
|
);
|
|
2993
3656
|
merged.endpoint = pinnedEndpoint;
|
|
2994
3657
|
}
|
|
@@ -2996,7 +3659,7 @@ function registerPrebidAnalytics(pbjsGlobalName = "pbjs", defaults) {
|
|
|
2996
3659
|
try {
|
|
2997
3660
|
previous.disable();
|
|
2998
3661
|
} catch (e) {
|
|
2999
|
-
|
|
3662
|
+
defaultLogger.warn("Failed to disable previous analytics instance:", e);
|
|
3000
3663
|
}
|
|
3001
3664
|
}
|
|
3002
3665
|
const analytics = new BidkernelPrebidAnalytics(merged);
|
|
@@ -3029,7 +3692,7 @@ function registerPrebidAnalytics(pbjsGlobalName = "pbjs", defaults) {
|
|
|
3029
3692
|
enableInstance(stashed);
|
|
3030
3693
|
}
|
|
3031
3694
|
} catch (e) {
|
|
3032
|
-
|
|
3695
|
+
defaultLogger.warn("Failed to register standard Prebid analytics adapter:", e);
|
|
3033
3696
|
}
|
|
3034
3697
|
};
|
|
3035
3698
|
if (pbjs.adapterManager && typeof pbjs.adapterManager.registerAnalyticsAdapter === "function") {
|
|
@@ -3076,6 +3739,8 @@ function getbidkernel(alias = "bidkernel") {
|
|
|
3076
3739
|
PrebidEventDeduper,
|
|
3077
3740
|
getPrebidEventKey,
|
|
3078
3741
|
getbidkernel,
|
|
3742
|
+
hookImaPrototype,
|
|
3743
|
+
initImaInterception,
|
|
3079
3744
|
isTrustedEndpoint,
|
|
3080
3745
|
registerPrebidAnalytics
|
|
3081
3746
|
});
|