@bidkernel/analytics 0.18.0 → 0.20.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 +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +127 -158
- package/dist/index.mjs +127 -158
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -290,7 +290,6 @@ var TraceEventType = {
|
|
|
290
290
|
TRACE_EVENT_TYPE_UNSPECIFIED: 0,
|
|
291
291
|
AUCTION_START: 1,
|
|
292
292
|
AUCTION_END: 2,
|
|
293
|
-
BID_RESPONSE: 3,
|
|
294
293
|
BID_WIN: 4,
|
|
295
294
|
/** IMPRESSION - ad rendered into DOM */
|
|
296
295
|
IMPRESSION: 5,
|
|
@@ -298,7 +297,6 @@ var TraceEventType = {
|
|
|
298
297
|
VIEWABLE: 6,
|
|
299
298
|
/** TIME_IN_VIEW - accumulated in-viewport duration (once per render cycle end) */
|
|
300
299
|
TIME_IN_VIEW: 7,
|
|
301
|
-
REFRESH: 8,
|
|
302
300
|
ERROR: 9,
|
|
303
301
|
SLOT_DEFINED: 10,
|
|
304
302
|
SLOT_DESTROYED: 11,
|
|
@@ -321,14 +319,14 @@ var BidderOutcome = {
|
|
|
321
319
|
};
|
|
322
320
|
function createBaseTraceEventBatch() {
|
|
323
321
|
return {
|
|
324
|
-
propertyId:
|
|
325
|
-
pageviewId:
|
|
326
|
-
sessionId:
|
|
322
|
+
propertyId: new Uint8Array(0),
|
|
323
|
+
pageviewId: new Uint8Array(0),
|
|
324
|
+
sessionId: new Uint8Array(0),
|
|
327
325
|
pageUrl: "",
|
|
328
326
|
country: "",
|
|
329
327
|
region: "",
|
|
330
328
|
deviceType: "",
|
|
331
|
-
userId:
|
|
329
|
+
userId: new Uint8Array(0),
|
|
332
330
|
domain: "",
|
|
333
331
|
events: [],
|
|
334
332
|
browser: "",
|
|
@@ -340,14 +338,14 @@ function createBaseTraceEventBatch() {
|
|
|
340
338
|
}
|
|
341
339
|
var TraceEventBatch = {
|
|
342
340
|
encode(message, writer = new BinaryWriter()) {
|
|
343
|
-
if (message.propertyId !== void 0 && message.propertyId !==
|
|
344
|
-
writer.uint32(10).
|
|
341
|
+
if (message.propertyId !== void 0 && message.propertyId.length !== 0) {
|
|
342
|
+
writer.uint32(10).bytes(message.propertyId);
|
|
345
343
|
}
|
|
346
|
-
if (message.pageviewId !== void 0 && message.pageviewId !==
|
|
347
|
-
writer.uint32(18).
|
|
344
|
+
if (message.pageviewId !== void 0 && message.pageviewId.length !== 0) {
|
|
345
|
+
writer.uint32(18).bytes(message.pageviewId);
|
|
348
346
|
}
|
|
349
|
-
if (message.sessionId !== void 0 && message.sessionId !==
|
|
350
|
-
writer.uint32(26).
|
|
347
|
+
if (message.sessionId !== void 0 && message.sessionId.length !== 0) {
|
|
348
|
+
writer.uint32(26).bytes(message.sessionId);
|
|
351
349
|
}
|
|
352
350
|
if (message.pageUrl !== void 0 && message.pageUrl !== "") {
|
|
353
351
|
writer.uint32(34).string(message.pageUrl);
|
|
@@ -361,8 +359,8 @@ var TraceEventBatch = {
|
|
|
361
359
|
if (message.deviceType !== void 0 && message.deviceType !== "") {
|
|
362
360
|
writer.uint32(58).string(message.deviceType);
|
|
363
361
|
}
|
|
364
|
-
if (message.userId !== void 0 && message.userId !==
|
|
365
|
-
writer.uint32(66).
|
|
362
|
+
if (message.userId !== void 0 && message.userId.length !== 0) {
|
|
363
|
+
writer.uint32(66).bytes(message.userId);
|
|
366
364
|
}
|
|
367
365
|
if (message.domain !== void 0 && message.domain !== "") {
|
|
368
366
|
writer.uint32(74).string(message.domain);
|
|
@@ -400,21 +398,21 @@ var TraceEventBatch = {
|
|
|
400
398
|
if (tag !== 10) {
|
|
401
399
|
break;
|
|
402
400
|
}
|
|
403
|
-
message.propertyId = reader.
|
|
401
|
+
message.propertyId = reader.bytes();
|
|
404
402
|
continue;
|
|
405
403
|
}
|
|
406
404
|
case 2: {
|
|
407
405
|
if (tag !== 18) {
|
|
408
406
|
break;
|
|
409
407
|
}
|
|
410
|
-
message.pageviewId = reader.
|
|
408
|
+
message.pageviewId = reader.bytes();
|
|
411
409
|
continue;
|
|
412
410
|
}
|
|
413
411
|
case 3: {
|
|
414
412
|
if (tag !== 26) {
|
|
415
413
|
break;
|
|
416
414
|
}
|
|
417
|
-
message.sessionId = reader.
|
|
415
|
+
message.sessionId = reader.bytes();
|
|
418
416
|
continue;
|
|
419
417
|
}
|
|
420
418
|
case 4: {
|
|
@@ -449,7 +447,7 @@ var TraceEventBatch = {
|
|
|
449
447
|
if (tag !== 66) {
|
|
450
448
|
break;
|
|
451
449
|
}
|
|
452
|
-
message.userId = reader.
|
|
450
|
+
message.userId = reader.bytes();
|
|
453
451
|
continue;
|
|
454
452
|
}
|
|
455
453
|
case 9: {
|
|
@@ -518,12 +516,12 @@ function createBaseTraceEvent() {
|
|
|
518
516
|
timestampMs: 0,
|
|
519
517
|
type: 0,
|
|
520
518
|
eventName: "",
|
|
521
|
-
auctionId:
|
|
522
|
-
transactionId:
|
|
519
|
+
auctionId: new Uint8Array(0),
|
|
520
|
+
transactionId: new Uint8Array(0),
|
|
523
521
|
adUnitCode: "",
|
|
524
522
|
bid: void 0,
|
|
525
523
|
namespace: "",
|
|
526
|
-
eventId:
|
|
524
|
+
eventId: new Uint8Array(0),
|
|
527
525
|
metadata: {},
|
|
528
526
|
viewableDurationMs: void 0,
|
|
529
527
|
bidderOutcomes: []
|
|
@@ -540,11 +538,11 @@ var TraceEvent = {
|
|
|
540
538
|
if (message.eventName !== void 0 && message.eventName !== "") {
|
|
541
539
|
writer.uint32(26).string(message.eventName);
|
|
542
540
|
}
|
|
543
|
-
if (message.auctionId !== void 0 && message.auctionId !==
|
|
544
|
-
writer.uint32(34).
|
|
541
|
+
if (message.auctionId !== void 0 && message.auctionId.length !== 0) {
|
|
542
|
+
writer.uint32(34).bytes(message.auctionId);
|
|
545
543
|
}
|
|
546
|
-
if (message.transactionId !== void 0 && message.transactionId !==
|
|
547
|
-
writer.uint32(42).
|
|
544
|
+
if (message.transactionId !== void 0 && message.transactionId.length !== 0) {
|
|
545
|
+
writer.uint32(42).bytes(message.transactionId);
|
|
548
546
|
}
|
|
549
547
|
if (message.adUnitCode !== void 0 && message.adUnitCode !== "") {
|
|
550
548
|
writer.uint32(50).string(message.adUnitCode);
|
|
@@ -555,8 +553,8 @@ var TraceEvent = {
|
|
|
555
553
|
if (message.namespace !== void 0 && message.namespace !== "") {
|
|
556
554
|
writer.uint32(66).string(message.namespace);
|
|
557
555
|
}
|
|
558
|
-
if (message.eventId !== void 0 && message.eventId !==
|
|
559
|
-
writer.uint32(74).
|
|
556
|
+
if (message.eventId !== void 0 && message.eventId.length !== 0) {
|
|
557
|
+
writer.uint32(74).bytes(message.eventId);
|
|
560
558
|
}
|
|
561
559
|
globalThis.Object.entries(message.metadata || {}).forEach(([key, value]) => {
|
|
562
560
|
TraceEvent_MetadataEntry.encode({ key, value }, writer.uint32(82).fork()).join();
|
|
@@ -603,14 +601,14 @@ var TraceEvent = {
|
|
|
603
601
|
if (tag !== 34) {
|
|
604
602
|
break;
|
|
605
603
|
}
|
|
606
|
-
message.auctionId = reader.
|
|
604
|
+
message.auctionId = reader.bytes();
|
|
607
605
|
continue;
|
|
608
606
|
}
|
|
609
607
|
case 5: {
|
|
610
608
|
if (tag !== 42) {
|
|
611
609
|
break;
|
|
612
610
|
}
|
|
613
|
-
message.transactionId = reader.
|
|
611
|
+
message.transactionId = reader.bytes();
|
|
614
612
|
continue;
|
|
615
613
|
}
|
|
616
614
|
case 6: {
|
|
@@ -638,7 +636,7 @@ var TraceEvent = {
|
|
|
638
636
|
if (tag !== 74) {
|
|
639
637
|
break;
|
|
640
638
|
}
|
|
641
|
-
message.eventId = reader.
|
|
639
|
+
message.eventId = reader.bytes();
|
|
642
640
|
continue;
|
|
643
641
|
}
|
|
644
642
|
case 10: {
|
|
@@ -721,24 +719,21 @@ var TraceEvent_MetadataEntry = {
|
|
|
721
719
|
}
|
|
722
720
|
};
|
|
723
721
|
function createBaseBidderOutcomeEntry() {
|
|
724
|
-
return {
|
|
722
|
+
return { adUnitCode: "", outcome: 0, bid: void 0, refreshIndex: 0 };
|
|
725
723
|
}
|
|
726
724
|
var BidderOutcomeEntry = {
|
|
727
725
|
encode(message, writer = new BinaryWriter()) {
|
|
728
|
-
if (message.bidder !== void 0 && message.bidder !== "") {
|
|
729
|
-
writer.uint32(10).string(message.bidder);
|
|
730
|
-
}
|
|
731
726
|
if (message.adUnitCode !== void 0 && message.adUnitCode !== "") {
|
|
732
727
|
writer.uint32(18).string(message.adUnitCode);
|
|
733
728
|
}
|
|
734
|
-
if (message.mediaType !== void 0 && message.mediaType !== "") {
|
|
735
|
-
writer.uint32(26).string(message.mediaType);
|
|
736
|
-
}
|
|
737
729
|
if (message.outcome !== void 0 && message.outcome !== 0) {
|
|
738
730
|
writer.uint32(32).int32(message.outcome);
|
|
739
731
|
}
|
|
740
|
-
if (message.
|
|
741
|
-
writer.uint32(
|
|
732
|
+
if (message.bid !== void 0) {
|
|
733
|
+
BidTrace.encode(message.bid, writer.uint32(50).fork()).join();
|
|
734
|
+
}
|
|
735
|
+
if (message.refreshIndex !== void 0 && message.refreshIndex !== 0) {
|
|
736
|
+
writer.uint32(56).int32(message.refreshIndex);
|
|
742
737
|
}
|
|
743
738
|
return writer;
|
|
744
739
|
},
|
|
@@ -749,13 +744,6 @@ var BidderOutcomeEntry = {
|
|
|
749
744
|
while (reader.pos < end) {
|
|
750
745
|
const tag = reader.uint32();
|
|
751
746
|
switch (tag >>> 3) {
|
|
752
|
-
case 1: {
|
|
753
|
-
if (tag !== 10) {
|
|
754
|
-
break;
|
|
755
|
-
}
|
|
756
|
-
message.bidder = reader.string();
|
|
757
|
-
continue;
|
|
758
|
-
}
|
|
759
747
|
case 2: {
|
|
760
748
|
if (tag !== 18) {
|
|
761
749
|
break;
|
|
@@ -763,25 +751,25 @@ var BidderOutcomeEntry = {
|
|
|
763
751
|
message.adUnitCode = reader.string();
|
|
764
752
|
continue;
|
|
765
753
|
}
|
|
766
|
-
case
|
|
767
|
-
if (tag !==
|
|
754
|
+
case 4: {
|
|
755
|
+
if (tag !== 32) {
|
|
768
756
|
break;
|
|
769
757
|
}
|
|
770
|
-
message.
|
|
758
|
+
message.outcome = reader.int32();
|
|
771
759
|
continue;
|
|
772
760
|
}
|
|
773
|
-
case
|
|
774
|
-
if (tag !==
|
|
761
|
+
case 6: {
|
|
762
|
+
if (tag !== 50) {
|
|
775
763
|
break;
|
|
776
764
|
}
|
|
777
|
-
message.
|
|
765
|
+
message.bid = BidTrace.decode(reader, reader.uint32());
|
|
778
766
|
continue;
|
|
779
767
|
}
|
|
780
|
-
case
|
|
781
|
-
if (tag !==
|
|
768
|
+
case 7: {
|
|
769
|
+
if (tag !== 56) {
|
|
782
770
|
break;
|
|
783
771
|
}
|
|
784
|
-
message.
|
|
772
|
+
message.refreshIndex = reader.int32();
|
|
785
773
|
continue;
|
|
786
774
|
}
|
|
787
775
|
}
|
|
@@ -928,8 +916,28 @@ var BidTrace = {
|
|
|
928
916
|
}
|
|
929
917
|
};
|
|
930
918
|
|
|
919
|
+
// src/ids.ts
|
|
920
|
+
var CANONICAL_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
921
|
+
var UUID_BYTES = 16;
|
|
922
|
+
var utf8Encoder = typeof TextEncoder !== "undefined" ? new TextEncoder() : null;
|
|
923
|
+
var utf8Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder() : null;
|
|
924
|
+
function idToBytes(id) {
|
|
925
|
+
if (!id) return new Uint8Array(0);
|
|
926
|
+
if (CANONICAL_UUID.test(id)) {
|
|
927
|
+
const hex = id.replace(/-/g, "");
|
|
928
|
+
const out2 = new Uint8Array(UUID_BYTES);
|
|
929
|
+
for (let i = 0; i < UUID_BYTES; i++) {
|
|
930
|
+
out2[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
931
|
+
}
|
|
932
|
+
return out2;
|
|
933
|
+
}
|
|
934
|
+
if (utf8Encoder) return utf8Encoder.encode(id);
|
|
935
|
+
const out = new Uint8Array(id.length);
|
|
936
|
+
for (let i = 0; i < id.length; i++) out[i] = id.charCodeAt(i) & 255;
|
|
937
|
+
return out;
|
|
938
|
+
}
|
|
939
|
+
|
|
931
940
|
// src/prebid-analytics.ts
|
|
932
|
-
var BATCH_SIZE = 20;
|
|
933
941
|
var FLUSH_INTERVAL_MS = 1e4;
|
|
934
942
|
var MAX_ERRORS_PER_SESSION = 50;
|
|
935
943
|
var MAX_QUEUE_SIZE = 200;
|
|
@@ -946,12 +954,10 @@ var PENDING_BATCH_CLEANUP_DELAY_MS = 1e4;
|
|
|
946
954
|
var EVENT_NAME_TO_TYPE = {
|
|
947
955
|
auctionStart: TraceEventType.AUCTION_START,
|
|
948
956
|
auctionEnd: TraceEventType.AUCTION_END,
|
|
949
|
-
bidResponse: TraceEventType.BID_RESPONSE,
|
|
950
957
|
bidWin: TraceEventType.BID_WIN,
|
|
951
958
|
adRenderFailed: TraceEventType.AD_RENDER_FAILED,
|
|
952
959
|
click: TraceEventType.CLICK,
|
|
953
960
|
impression: TraceEventType.IMPRESSION,
|
|
954
|
-
refresh: TraceEventType.REFRESH,
|
|
955
961
|
timeInView: TraceEventType.TIME_IN_VIEW,
|
|
956
962
|
viewable: TraceEventType.VIEWABLE
|
|
957
963
|
};
|
|
@@ -1615,8 +1621,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1615
1621
|
const record = this.slotViewabilityRecords.get(slotId);
|
|
1616
1622
|
if (record && record.element !== element) {
|
|
1617
1623
|
this.observeSlot(element, slotId, {
|
|
1618
|
-
refreshIndex: record.refreshIndex
|
|
1619
|
-
emitRefreshEvent: false
|
|
1624
|
+
refreshIndex: record.refreshIndex
|
|
1620
1625
|
});
|
|
1621
1626
|
}
|
|
1622
1627
|
}
|
|
@@ -1804,18 +1809,6 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1804
1809
|
this.flushSlotTimeInView(resolvedSlotId);
|
|
1805
1810
|
const nextRefreshIndex = options?.refreshIndex !== void 0 ? options.refreshIndex : (this.slotRefreshIndices.get(resolvedSlotId) ?? existing.refreshIndex) + 1;
|
|
1806
1811
|
this.slotRefreshIndices.set(resolvedSlotId, nextRefreshIndex);
|
|
1807
|
-
if (options?.emitRefreshEvent !== false) {
|
|
1808
|
-
this.enqueue(TraceEventType.REFRESH, "refresh", {
|
|
1809
|
-
auctionId: options?.auctionId || existing.auctionId,
|
|
1810
|
-
transactionId: options?.transactionId || existing.transactionId,
|
|
1811
|
-
adUnitCode: resolvedSlotId,
|
|
1812
|
-
bid: options?.bid ?? existing.bidPayload,
|
|
1813
|
-
metadata: {
|
|
1814
|
-
...options?.metadata,
|
|
1815
|
-
refresh_index: String(nextRefreshIndex)
|
|
1816
|
-
}
|
|
1817
|
-
});
|
|
1818
|
-
}
|
|
1819
1812
|
if (existing.dwellTimer) {
|
|
1820
1813
|
clearTimeout(existing.dwellTimer);
|
|
1821
1814
|
existing.dwellTimer = null;
|
|
@@ -2078,16 +2071,6 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2078
2071
|
rec.viewableFired = false;
|
|
2079
2072
|
rec.accumulatedTimeInViewMs = 0;
|
|
2080
2073
|
}
|
|
2081
|
-
this.enqueue(TraceEventType.REFRESH, "refresh", {
|
|
2082
|
-
auctionId,
|
|
2083
|
-
transactionId,
|
|
2084
|
-
adUnitCode: targetSlot,
|
|
2085
|
-
bid: bidTrace,
|
|
2086
|
-
metadata: {
|
|
2087
|
-
...options?.metadata,
|
|
2088
|
-
refresh_index: String(nextRefreshIndex)
|
|
2089
|
-
}
|
|
2090
|
-
});
|
|
2091
2074
|
} else if (targetSlot) {
|
|
2092
2075
|
if (auctionId) {
|
|
2093
2076
|
this.slotLastAuctionIds.set(targetSlot, auctionId);
|
|
@@ -2206,7 +2189,8 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2206
2189
|
}
|
|
2207
2190
|
}
|
|
2208
2191
|
trackRawEvent(level, eventName, data) {
|
|
2209
|
-
const eventType = EVENT_NAME_TO_TYPE[eventName] ?? (level === "ERROR" ? TraceEventType.ERROR :
|
|
2192
|
+
const eventType = EVENT_NAME_TO_TYPE[eventName] ?? (level === "ERROR" ? TraceEventType.ERROR : void 0);
|
|
2193
|
+
if (eventType === void 0) return;
|
|
2210
2194
|
this.enqueue(eventType, eventName, data, level);
|
|
2211
2195
|
}
|
|
2212
2196
|
setUserId(userId) {
|
|
@@ -2262,6 +2246,19 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2262
2246
|
bidderOutcomes
|
|
2263
2247
|
});
|
|
2264
2248
|
}
|
|
2249
|
+
/**
|
|
2250
|
+
* The render cycle an auction ending now would fill for an ad unit: 0 for
|
|
2251
|
+
* a slot that has never rendered on this pageview, otherwise one past the
|
|
2252
|
+
* cycle it last rendered. The index only advances when a creative renders,
|
|
2253
|
+
* so two unfilled refresh auctions in a row report the same cycle; both
|
|
2254
|
+
* count as refreshes, which is the point. Stamped on AUCTION_END bidder
|
|
2255
|
+
* outcomes in enqueue; there is no per-refresh event.
|
|
2256
|
+
*/
|
|
2257
|
+
auctionCycleIndex(adUnitCode) {
|
|
2258
|
+
if (!adUnitCode) return 0;
|
|
2259
|
+
const last = this.slotRefreshIndices.get(adUnitCode) ?? this.slotViewabilityRecords.get(adUnitCode)?.refreshIndex;
|
|
2260
|
+
return last === void 0 ? 0 : last + 1;
|
|
2261
|
+
}
|
|
2265
2262
|
handleBidRequested(data) {
|
|
2266
2263
|
if (this.isDuplicate("bidRequested", data)) return;
|
|
2267
2264
|
this.log("DEBUG", "bidRequested", data);
|
|
@@ -2277,11 +2274,9 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2277
2274
|
const key = `${bidder}:${adUnitCode}`;
|
|
2278
2275
|
if (!auctionMap.has(key)) {
|
|
2279
2276
|
auctionMap.set(key, {
|
|
2280
|
-
bidder,
|
|
2281
2277
|
adUnitCode,
|
|
2282
|
-
mediaType,
|
|
2283
2278
|
outcome: BidderOutcome.BIDDER_OUTCOME_NO_RESPONSE,
|
|
2284
|
-
latencyMs: 0
|
|
2279
|
+
bid: { bidder, mediaType, latencyMs: 0 }
|
|
2285
2280
|
});
|
|
2286
2281
|
}
|
|
2287
2282
|
});
|
|
@@ -2297,43 +2292,23 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2297
2292
|
const latencyMs = Number.isFinite(data.timeToRespond) ? data.timeToRespond : 0;
|
|
2298
2293
|
const resMediaTypes = Object.keys(data.mediaTypes || {});
|
|
2299
2294
|
const mediaType = data.mediaType || (data.mediaTypes?.video ? "video" : resMediaTypes.length > 0 ? resMediaTypes[0] : "banner");
|
|
2300
|
-
if (auctionId
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
}
|
|
2318
|
-
}
|
|
2319
|
-
if (cpm > 0) {
|
|
2320
|
-
this.enqueue(TraceEventType.BID_RESPONSE, "bidResponse", {
|
|
2321
|
-
auctionId,
|
|
2322
|
-
transactionId: data.transactionId || "",
|
|
2323
|
-
adUnitCode,
|
|
2324
|
-
bid: {
|
|
2325
|
-
bidder,
|
|
2326
|
-
cpm,
|
|
2327
|
-
currency: data.originalCurrency ?? data.currency ?? "USD",
|
|
2328
|
-
...parseBidDimensions(data),
|
|
2329
|
-
dealId: data.dealId || "",
|
|
2330
|
-
mediaType,
|
|
2331
|
-
latencyMs,
|
|
2332
|
-
advertiserDomain: data.meta?.advertiserDomains?.[0] || "",
|
|
2333
|
-
creativeId: data.creativeId || ""
|
|
2334
|
-
}
|
|
2335
|
-
});
|
|
2336
|
-
}
|
|
2295
|
+
if (!auctionId || !bidder) return;
|
|
2296
|
+
const bid = cpm > 0 ? {
|
|
2297
|
+
bidder,
|
|
2298
|
+
cpm,
|
|
2299
|
+
currency: data.originalCurrency ?? data.currency ?? "USD",
|
|
2300
|
+
...parseBidDimensions(data),
|
|
2301
|
+
dealId: data.dealId || "",
|
|
2302
|
+
mediaType,
|
|
2303
|
+
latencyMs,
|
|
2304
|
+
advertiserDomain: data.meta?.advertiserDomains?.[0] || "",
|
|
2305
|
+
creativeId: data.creativeId || ""
|
|
2306
|
+
} : { bidder, mediaType, latencyMs };
|
|
2307
|
+
this.getOrCreateAuctionOutcomes(auctionId).set(`${bidder}:${adUnitCode}`, {
|
|
2308
|
+
adUnitCode,
|
|
2309
|
+
outcome: cpm > 0 ? BidderOutcome.BIDDER_OUTCOME_BID : BidderOutcome.BIDDER_OUTCOME_NO_BID,
|
|
2310
|
+
bid
|
|
2311
|
+
});
|
|
2337
2312
|
}
|
|
2338
2313
|
handleBidTimeout(data) {
|
|
2339
2314
|
if (this.isDuplicate("bidTimeout", data)) return;
|
|
@@ -2350,14 +2325,12 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2350
2325
|
const entry = auctionMap.get(key);
|
|
2351
2326
|
if (entry) {
|
|
2352
2327
|
entry.outcome = BidderOutcome.BIDDER_OUTCOME_TIMEOUT;
|
|
2353
|
-
if (latencyMs > 0) entry.latencyMs = latencyMs;
|
|
2328
|
+
if (latencyMs > 0 && entry.bid) entry.bid.latencyMs = latencyMs;
|
|
2354
2329
|
} else {
|
|
2355
2330
|
auctionMap.set(key, {
|
|
2356
|
-
bidder,
|
|
2357
2331
|
adUnitCode,
|
|
2358
|
-
mediaType: "banner",
|
|
2359
2332
|
outcome: BidderOutcome.BIDDER_OUTCOME_TIMEOUT,
|
|
2360
|
-
latencyMs
|
|
2333
|
+
bid: { bidder, mediaType: "banner", latencyMs }
|
|
2361
2334
|
});
|
|
2362
2335
|
}
|
|
2363
2336
|
}
|
|
@@ -2426,11 +2399,9 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2426
2399
|
}
|
|
2427
2400
|
} else {
|
|
2428
2401
|
auctionMap.set(key, {
|
|
2429
|
-
bidder,
|
|
2430
2402
|
adUnitCode,
|
|
2431
|
-
mediaType: "banner",
|
|
2432
2403
|
outcome: BidderOutcome.BIDDER_OUTCOME_NO_BID,
|
|
2433
|
-
latencyMs: 0
|
|
2404
|
+
bid: { bidder, mediaType: "banner", latencyMs: 0 }
|
|
2434
2405
|
});
|
|
2435
2406
|
}
|
|
2436
2407
|
}
|
|
@@ -2497,13 +2468,6 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2497
2468
|
record.viewableFired = false;
|
|
2498
2469
|
record.accumulatedTimeInViewMs = 0;
|
|
2499
2470
|
}
|
|
2500
|
-
this.enqueue(TraceEventType.REFRESH, "refresh", {
|
|
2501
|
-
auctionId: resolvedAuctionId,
|
|
2502
|
-
transactionId: resolvedTransactionId,
|
|
2503
|
-
adUnitCode,
|
|
2504
|
-
bid: bidTrace,
|
|
2505
|
-
metadata: { refresh_index: String(nextRefreshIndex) }
|
|
2506
|
-
});
|
|
2507
2471
|
} else if (adUnitCode) {
|
|
2508
2472
|
if (resolvedAuctionId) {
|
|
2509
2473
|
this.slotLastAuctionIds.set(adUnitCode, resolvedAuctionId);
|
|
@@ -2579,8 +2543,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2579
2543
|
transactionId: resolvedTransactionId,
|
|
2580
2544
|
mediaType: resolvedMediaType,
|
|
2581
2545
|
bid: bidTrace,
|
|
2582
|
-
refreshIndex: currentRefreshIndex
|
|
2583
|
-
emitRefreshEvent: false
|
|
2546
|
+
refreshIndex: currentRefreshIndex
|
|
2584
2547
|
});
|
|
2585
2548
|
}
|
|
2586
2549
|
}
|
|
@@ -2593,12 +2556,14 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2593
2556
|
if (!this.shouldSample(type, level)) return;
|
|
2594
2557
|
extendSession();
|
|
2595
2558
|
const protoEvent = {
|
|
2596
|
-
eventId: generateUUID(),
|
|
2559
|
+
eventId: idToBytes(generateUUID()),
|
|
2597
2560
|
timestampMs: Date.now(),
|
|
2598
2561
|
type,
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2562
|
+
// Typed events have a fixed name that ingest derives from `type`; only
|
|
2563
|
+
// ERROR events carry theirs, which names the failure.
|
|
2564
|
+
eventName: type === TraceEventType.ERROR ? eventName : "",
|
|
2565
|
+
auctionId: idToBytes(String(data.auctionId || "")),
|
|
2566
|
+
transactionId: idToBytes(String(data.transactionId || "")),
|
|
2602
2567
|
adUnitCode: data.adUnitCode || data.elementId || "",
|
|
2603
2568
|
namespace: data.ns || data.namespace || ""
|
|
2604
2569
|
};
|
|
@@ -2606,9 +2571,9 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2606
2571
|
protoEvent.bid = {
|
|
2607
2572
|
bidder: data.bid.bidder || "",
|
|
2608
2573
|
cpm: Number.isFinite(data.bid.cpm) ? data.bid.cpm : 0,
|
|
2609
|
-
// No defaults here: handlers with a priced bid (
|
|
2610
|
-
//
|
|
2611
|
-
//
|
|
2574
|
+
// No defaults here: handlers with a priced bid (bidWon, impression)
|
|
2575
|
+
// set currency/mediaType themselves. Defaulting for the rest would
|
|
2576
|
+
// stamp fake "USD"/"banner" on rows that carried no bid.
|
|
2612
2577
|
currency: data.bid.currency || "",
|
|
2613
2578
|
width: Number.isFinite(data.bid.width) ? data.bid.width : 0,
|
|
2614
2579
|
height: Number.isFinite(data.bid.height) ? data.bid.height : 0,
|
|
@@ -2623,7 +2588,12 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2623
2588
|
protoEvent.viewableDurationMs = Number.isFinite(data.viewableDurationMs) ? data.viewableDurationMs : 0;
|
|
2624
2589
|
}
|
|
2625
2590
|
if (data.bidderOutcomes && Array.isArray(data.bidderOutcomes)) {
|
|
2626
|
-
protoEvent.bidderOutcomes = data.bidderOutcomes
|
|
2591
|
+
protoEvent.bidderOutcomes = data.bidderOutcomes.map(
|
|
2592
|
+
(entry) => ({
|
|
2593
|
+
...entry,
|
|
2594
|
+
refreshIndex: entry.refreshIndex ?? this.auctionCycleIndex(entry.adUnitCode || "")
|
|
2595
|
+
})
|
|
2596
|
+
);
|
|
2627
2597
|
}
|
|
2628
2598
|
const metadata = { ...data.metadata };
|
|
2629
2599
|
if (data.error !== void 0 && data.error !== null) {
|
|
@@ -2640,11 +2610,11 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2640
2610
|
protoEvent.metadata = boundedMetadata;
|
|
2641
2611
|
}
|
|
2642
2612
|
this.queue.push(protoEvent);
|
|
2643
|
-
if (this.queue.length
|
|
2644
|
-
this.queue.splice(0, this.queue.length - MAX_QUEUE_SIZE);
|
|
2645
|
-
}
|
|
2646
|
-
if (this.queue.length >= BATCH_SIZE) {
|
|
2613
|
+
if (this.queue.length >= MAX_QUEUE_SIZE) {
|
|
2647
2614
|
this.flush();
|
|
2615
|
+
if (this.queue.length > MAX_QUEUE_SIZE) {
|
|
2616
|
+
this.queue.splice(0, this.queue.length - MAX_QUEUE_SIZE);
|
|
2617
|
+
}
|
|
2648
2618
|
} else if (REVENUE_FLUSH_TYPES.has(type) && this.revenueFlushTimer === null) {
|
|
2649
2619
|
this.revenueFlushTimer = setTimeout(() => {
|
|
2650
2620
|
this.revenueFlushTimer = null;
|
|
@@ -2676,14 +2646,14 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2676
2646
|
if (this.queue.length === 0 || !this.config.endpoint) return null;
|
|
2677
2647
|
const domain = typeof window !== "undefined" ? window.location.hostname : "";
|
|
2678
2648
|
const buildBatch = (evts) => ({
|
|
2679
|
-
propertyId: this.config.propertyId,
|
|
2680
|
-
pageviewId: this.config.pageviewId,
|
|
2681
|
-
sessionId: this.config.sessionId,
|
|
2649
|
+
propertyId: idToBytes(this.config.propertyId),
|
|
2650
|
+
pageviewId: idToBytes(this.config.pageviewId),
|
|
2651
|
+
sessionId: idToBytes(this.config.sessionId),
|
|
2682
2652
|
pageUrl: this.pageUrl,
|
|
2683
2653
|
country: this.config.country,
|
|
2684
2654
|
region: this.config.region,
|
|
2685
2655
|
deviceType: this.config.deviceType,
|
|
2686
|
-
userId: this.config.userId,
|
|
2656
|
+
userId: idToBytes(this.config.userId),
|
|
2687
2657
|
domain,
|
|
2688
2658
|
events: evts
|
|
2689
2659
|
});
|
|
@@ -2703,7 +2673,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2703
2673
|
const [dropped] = this.queue.splice(0, 1);
|
|
2704
2674
|
this.log(
|
|
2705
2675
|
"WARN",
|
|
2706
|
-
`Dropping oversized event ${dropped?.
|
|
2676
|
+
`Dropping oversized event (type ${dropped?.type}, ${encoded.byteLength} bytes exceeds the ${MAX_PAYLOAD_BYTES}-byte cap on its own)`
|
|
2707
2677
|
);
|
|
2708
2678
|
continue;
|
|
2709
2679
|
}
|
|
@@ -3752,8 +3722,7 @@ function attachVideoPlayer(analytics, target, options) {
|
|
|
3752
3722
|
transactionId: transactionId || cachedInitial?.transactionId,
|
|
3753
3723
|
mediaType: "video",
|
|
3754
3724
|
bid: cachedInitial?.bidTrace || options?.bid,
|
|
3755
|
-
metadata: options?.metadata
|
|
3756
|
-
emitRefreshEvent: false
|
|
3725
|
+
metadata: options?.metadata
|
|
3757
3726
|
});
|
|
3758
3727
|
}
|
|
3759
3728
|
const cleanup = () => {
|
package/package.json
CHANGED