@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.js
CHANGED
|
@@ -327,7 +327,6 @@ var TraceEventType = {
|
|
|
327
327
|
TRACE_EVENT_TYPE_UNSPECIFIED: 0,
|
|
328
328
|
AUCTION_START: 1,
|
|
329
329
|
AUCTION_END: 2,
|
|
330
|
-
BID_RESPONSE: 3,
|
|
331
330
|
BID_WIN: 4,
|
|
332
331
|
/** IMPRESSION - ad rendered into DOM */
|
|
333
332
|
IMPRESSION: 5,
|
|
@@ -335,7 +334,6 @@ var TraceEventType = {
|
|
|
335
334
|
VIEWABLE: 6,
|
|
336
335
|
/** TIME_IN_VIEW - accumulated in-viewport duration (once per render cycle end) */
|
|
337
336
|
TIME_IN_VIEW: 7,
|
|
338
|
-
REFRESH: 8,
|
|
339
337
|
ERROR: 9,
|
|
340
338
|
SLOT_DEFINED: 10,
|
|
341
339
|
SLOT_DESTROYED: 11,
|
|
@@ -358,14 +356,14 @@ var BidderOutcome = {
|
|
|
358
356
|
};
|
|
359
357
|
function createBaseTraceEventBatch() {
|
|
360
358
|
return {
|
|
361
|
-
propertyId:
|
|
362
|
-
pageviewId:
|
|
363
|
-
sessionId:
|
|
359
|
+
propertyId: new Uint8Array(0),
|
|
360
|
+
pageviewId: new Uint8Array(0),
|
|
361
|
+
sessionId: new Uint8Array(0),
|
|
364
362
|
pageUrl: "",
|
|
365
363
|
country: "",
|
|
366
364
|
region: "",
|
|
367
365
|
deviceType: "",
|
|
368
|
-
userId:
|
|
366
|
+
userId: new Uint8Array(0),
|
|
369
367
|
domain: "",
|
|
370
368
|
events: [],
|
|
371
369
|
browser: "",
|
|
@@ -377,14 +375,14 @@ function createBaseTraceEventBatch() {
|
|
|
377
375
|
}
|
|
378
376
|
var TraceEventBatch = {
|
|
379
377
|
encode(message, writer = new import_wire.BinaryWriter()) {
|
|
380
|
-
if (message.propertyId !== void 0 && message.propertyId !==
|
|
381
|
-
writer.uint32(10).
|
|
378
|
+
if (message.propertyId !== void 0 && message.propertyId.length !== 0) {
|
|
379
|
+
writer.uint32(10).bytes(message.propertyId);
|
|
382
380
|
}
|
|
383
|
-
if (message.pageviewId !== void 0 && message.pageviewId !==
|
|
384
|
-
writer.uint32(18).
|
|
381
|
+
if (message.pageviewId !== void 0 && message.pageviewId.length !== 0) {
|
|
382
|
+
writer.uint32(18).bytes(message.pageviewId);
|
|
385
383
|
}
|
|
386
|
-
if (message.sessionId !== void 0 && message.sessionId !==
|
|
387
|
-
writer.uint32(26).
|
|
384
|
+
if (message.sessionId !== void 0 && message.sessionId.length !== 0) {
|
|
385
|
+
writer.uint32(26).bytes(message.sessionId);
|
|
388
386
|
}
|
|
389
387
|
if (message.pageUrl !== void 0 && message.pageUrl !== "") {
|
|
390
388
|
writer.uint32(34).string(message.pageUrl);
|
|
@@ -398,8 +396,8 @@ var TraceEventBatch = {
|
|
|
398
396
|
if (message.deviceType !== void 0 && message.deviceType !== "") {
|
|
399
397
|
writer.uint32(58).string(message.deviceType);
|
|
400
398
|
}
|
|
401
|
-
if (message.userId !== void 0 && message.userId !==
|
|
402
|
-
writer.uint32(66).
|
|
399
|
+
if (message.userId !== void 0 && message.userId.length !== 0) {
|
|
400
|
+
writer.uint32(66).bytes(message.userId);
|
|
403
401
|
}
|
|
404
402
|
if (message.domain !== void 0 && message.domain !== "") {
|
|
405
403
|
writer.uint32(74).string(message.domain);
|
|
@@ -437,21 +435,21 @@ var TraceEventBatch = {
|
|
|
437
435
|
if (tag !== 10) {
|
|
438
436
|
break;
|
|
439
437
|
}
|
|
440
|
-
message.propertyId = reader.
|
|
438
|
+
message.propertyId = reader.bytes();
|
|
441
439
|
continue;
|
|
442
440
|
}
|
|
443
441
|
case 2: {
|
|
444
442
|
if (tag !== 18) {
|
|
445
443
|
break;
|
|
446
444
|
}
|
|
447
|
-
message.pageviewId = reader.
|
|
445
|
+
message.pageviewId = reader.bytes();
|
|
448
446
|
continue;
|
|
449
447
|
}
|
|
450
448
|
case 3: {
|
|
451
449
|
if (tag !== 26) {
|
|
452
450
|
break;
|
|
453
451
|
}
|
|
454
|
-
message.sessionId = reader.
|
|
452
|
+
message.sessionId = reader.bytes();
|
|
455
453
|
continue;
|
|
456
454
|
}
|
|
457
455
|
case 4: {
|
|
@@ -486,7 +484,7 @@ var TraceEventBatch = {
|
|
|
486
484
|
if (tag !== 66) {
|
|
487
485
|
break;
|
|
488
486
|
}
|
|
489
|
-
message.userId = reader.
|
|
487
|
+
message.userId = reader.bytes();
|
|
490
488
|
continue;
|
|
491
489
|
}
|
|
492
490
|
case 9: {
|
|
@@ -555,12 +553,12 @@ function createBaseTraceEvent() {
|
|
|
555
553
|
timestampMs: 0,
|
|
556
554
|
type: 0,
|
|
557
555
|
eventName: "",
|
|
558
|
-
auctionId:
|
|
559
|
-
transactionId:
|
|
556
|
+
auctionId: new Uint8Array(0),
|
|
557
|
+
transactionId: new Uint8Array(0),
|
|
560
558
|
adUnitCode: "",
|
|
561
559
|
bid: void 0,
|
|
562
560
|
namespace: "",
|
|
563
|
-
eventId:
|
|
561
|
+
eventId: new Uint8Array(0),
|
|
564
562
|
metadata: {},
|
|
565
563
|
viewableDurationMs: void 0,
|
|
566
564
|
bidderOutcomes: []
|
|
@@ -577,11 +575,11 @@ var TraceEvent = {
|
|
|
577
575
|
if (message.eventName !== void 0 && message.eventName !== "") {
|
|
578
576
|
writer.uint32(26).string(message.eventName);
|
|
579
577
|
}
|
|
580
|
-
if (message.auctionId !== void 0 && message.auctionId !==
|
|
581
|
-
writer.uint32(34).
|
|
578
|
+
if (message.auctionId !== void 0 && message.auctionId.length !== 0) {
|
|
579
|
+
writer.uint32(34).bytes(message.auctionId);
|
|
582
580
|
}
|
|
583
|
-
if (message.transactionId !== void 0 && message.transactionId !==
|
|
584
|
-
writer.uint32(42).
|
|
581
|
+
if (message.transactionId !== void 0 && message.transactionId.length !== 0) {
|
|
582
|
+
writer.uint32(42).bytes(message.transactionId);
|
|
585
583
|
}
|
|
586
584
|
if (message.adUnitCode !== void 0 && message.adUnitCode !== "") {
|
|
587
585
|
writer.uint32(50).string(message.adUnitCode);
|
|
@@ -592,8 +590,8 @@ var TraceEvent = {
|
|
|
592
590
|
if (message.namespace !== void 0 && message.namespace !== "") {
|
|
593
591
|
writer.uint32(66).string(message.namespace);
|
|
594
592
|
}
|
|
595
|
-
if (message.eventId !== void 0 && message.eventId !==
|
|
596
|
-
writer.uint32(74).
|
|
593
|
+
if (message.eventId !== void 0 && message.eventId.length !== 0) {
|
|
594
|
+
writer.uint32(74).bytes(message.eventId);
|
|
597
595
|
}
|
|
598
596
|
globalThis.Object.entries(message.metadata || {}).forEach(([key, value]) => {
|
|
599
597
|
TraceEvent_MetadataEntry.encode({ key, value }, writer.uint32(82).fork()).join();
|
|
@@ -640,14 +638,14 @@ var TraceEvent = {
|
|
|
640
638
|
if (tag !== 34) {
|
|
641
639
|
break;
|
|
642
640
|
}
|
|
643
|
-
message.auctionId = reader.
|
|
641
|
+
message.auctionId = reader.bytes();
|
|
644
642
|
continue;
|
|
645
643
|
}
|
|
646
644
|
case 5: {
|
|
647
645
|
if (tag !== 42) {
|
|
648
646
|
break;
|
|
649
647
|
}
|
|
650
|
-
message.transactionId = reader.
|
|
648
|
+
message.transactionId = reader.bytes();
|
|
651
649
|
continue;
|
|
652
650
|
}
|
|
653
651
|
case 6: {
|
|
@@ -675,7 +673,7 @@ var TraceEvent = {
|
|
|
675
673
|
if (tag !== 74) {
|
|
676
674
|
break;
|
|
677
675
|
}
|
|
678
|
-
message.eventId = reader.
|
|
676
|
+
message.eventId = reader.bytes();
|
|
679
677
|
continue;
|
|
680
678
|
}
|
|
681
679
|
case 10: {
|
|
@@ -758,24 +756,21 @@ var TraceEvent_MetadataEntry = {
|
|
|
758
756
|
}
|
|
759
757
|
};
|
|
760
758
|
function createBaseBidderOutcomeEntry() {
|
|
761
|
-
return {
|
|
759
|
+
return { adUnitCode: "", outcome: 0, bid: void 0, refreshIndex: 0 };
|
|
762
760
|
}
|
|
763
761
|
var BidderOutcomeEntry = {
|
|
764
762
|
encode(message, writer = new import_wire.BinaryWriter()) {
|
|
765
|
-
if (message.bidder !== void 0 && message.bidder !== "") {
|
|
766
|
-
writer.uint32(10).string(message.bidder);
|
|
767
|
-
}
|
|
768
763
|
if (message.adUnitCode !== void 0 && message.adUnitCode !== "") {
|
|
769
764
|
writer.uint32(18).string(message.adUnitCode);
|
|
770
765
|
}
|
|
771
|
-
if (message.mediaType !== void 0 && message.mediaType !== "") {
|
|
772
|
-
writer.uint32(26).string(message.mediaType);
|
|
773
|
-
}
|
|
774
766
|
if (message.outcome !== void 0 && message.outcome !== 0) {
|
|
775
767
|
writer.uint32(32).int32(message.outcome);
|
|
776
768
|
}
|
|
777
|
-
if (message.
|
|
778
|
-
writer.uint32(
|
|
769
|
+
if (message.bid !== void 0) {
|
|
770
|
+
BidTrace.encode(message.bid, writer.uint32(50).fork()).join();
|
|
771
|
+
}
|
|
772
|
+
if (message.refreshIndex !== void 0 && message.refreshIndex !== 0) {
|
|
773
|
+
writer.uint32(56).int32(message.refreshIndex);
|
|
779
774
|
}
|
|
780
775
|
return writer;
|
|
781
776
|
},
|
|
@@ -786,13 +781,6 @@ var BidderOutcomeEntry = {
|
|
|
786
781
|
while (reader.pos < end) {
|
|
787
782
|
const tag = reader.uint32();
|
|
788
783
|
switch (tag >>> 3) {
|
|
789
|
-
case 1: {
|
|
790
|
-
if (tag !== 10) {
|
|
791
|
-
break;
|
|
792
|
-
}
|
|
793
|
-
message.bidder = reader.string();
|
|
794
|
-
continue;
|
|
795
|
-
}
|
|
796
784
|
case 2: {
|
|
797
785
|
if (tag !== 18) {
|
|
798
786
|
break;
|
|
@@ -800,25 +788,25 @@ var BidderOutcomeEntry = {
|
|
|
800
788
|
message.adUnitCode = reader.string();
|
|
801
789
|
continue;
|
|
802
790
|
}
|
|
803
|
-
case
|
|
804
|
-
if (tag !==
|
|
791
|
+
case 4: {
|
|
792
|
+
if (tag !== 32) {
|
|
805
793
|
break;
|
|
806
794
|
}
|
|
807
|
-
message.
|
|
795
|
+
message.outcome = reader.int32();
|
|
808
796
|
continue;
|
|
809
797
|
}
|
|
810
|
-
case
|
|
811
|
-
if (tag !==
|
|
798
|
+
case 6: {
|
|
799
|
+
if (tag !== 50) {
|
|
812
800
|
break;
|
|
813
801
|
}
|
|
814
|
-
message.
|
|
802
|
+
message.bid = BidTrace.decode(reader, reader.uint32());
|
|
815
803
|
continue;
|
|
816
804
|
}
|
|
817
|
-
case
|
|
818
|
-
if (tag !==
|
|
805
|
+
case 7: {
|
|
806
|
+
if (tag !== 56) {
|
|
819
807
|
break;
|
|
820
808
|
}
|
|
821
|
-
message.
|
|
809
|
+
message.refreshIndex = reader.int32();
|
|
822
810
|
continue;
|
|
823
811
|
}
|
|
824
812
|
}
|
|
@@ -965,8 +953,28 @@ var BidTrace = {
|
|
|
965
953
|
}
|
|
966
954
|
};
|
|
967
955
|
|
|
956
|
+
// src/ids.ts
|
|
957
|
+
var CANONICAL_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
958
|
+
var UUID_BYTES = 16;
|
|
959
|
+
var utf8Encoder = typeof TextEncoder !== "undefined" ? new TextEncoder() : null;
|
|
960
|
+
var utf8Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder() : null;
|
|
961
|
+
function idToBytes(id) {
|
|
962
|
+
if (!id) return new Uint8Array(0);
|
|
963
|
+
if (CANONICAL_UUID.test(id)) {
|
|
964
|
+
const hex = id.replace(/-/g, "");
|
|
965
|
+
const out2 = new Uint8Array(UUID_BYTES);
|
|
966
|
+
for (let i = 0; i < UUID_BYTES; i++) {
|
|
967
|
+
out2[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
968
|
+
}
|
|
969
|
+
return out2;
|
|
970
|
+
}
|
|
971
|
+
if (utf8Encoder) return utf8Encoder.encode(id);
|
|
972
|
+
const out = new Uint8Array(id.length);
|
|
973
|
+
for (let i = 0; i < id.length; i++) out[i] = id.charCodeAt(i) & 255;
|
|
974
|
+
return out;
|
|
975
|
+
}
|
|
976
|
+
|
|
968
977
|
// src/prebid-analytics.ts
|
|
969
|
-
var BATCH_SIZE = 20;
|
|
970
978
|
var FLUSH_INTERVAL_MS = 1e4;
|
|
971
979
|
var MAX_ERRORS_PER_SESSION = 50;
|
|
972
980
|
var MAX_QUEUE_SIZE = 200;
|
|
@@ -983,12 +991,10 @@ var PENDING_BATCH_CLEANUP_DELAY_MS = 1e4;
|
|
|
983
991
|
var EVENT_NAME_TO_TYPE = {
|
|
984
992
|
auctionStart: TraceEventType.AUCTION_START,
|
|
985
993
|
auctionEnd: TraceEventType.AUCTION_END,
|
|
986
|
-
bidResponse: TraceEventType.BID_RESPONSE,
|
|
987
994
|
bidWin: TraceEventType.BID_WIN,
|
|
988
995
|
adRenderFailed: TraceEventType.AD_RENDER_FAILED,
|
|
989
996
|
click: TraceEventType.CLICK,
|
|
990
997
|
impression: TraceEventType.IMPRESSION,
|
|
991
|
-
refresh: TraceEventType.REFRESH,
|
|
992
998
|
timeInView: TraceEventType.TIME_IN_VIEW,
|
|
993
999
|
viewable: TraceEventType.VIEWABLE
|
|
994
1000
|
};
|
|
@@ -1652,8 +1658,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1652
1658
|
const record = this.slotViewabilityRecords.get(slotId);
|
|
1653
1659
|
if (record && record.element !== element) {
|
|
1654
1660
|
this.observeSlot(element, slotId, {
|
|
1655
|
-
refreshIndex: record.refreshIndex
|
|
1656
|
-
emitRefreshEvent: false
|
|
1661
|
+
refreshIndex: record.refreshIndex
|
|
1657
1662
|
});
|
|
1658
1663
|
}
|
|
1659
1664
|
}
|
|
@@ -1841,18 +1846,6 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
1841
1846
|
this.flushSlotTimeInView(resolvedSlotId);
|
|
1842
1847
|
const nextRefreshIndex = options?.refreshIndex !== void 0 ? options.refreshIndex : (this.slotRefreshIndices.get(resolvedSlotId) ?? existing.refreshIndex) + 1;
|
|
1843
1848
|
this.slotRefreshIndices.set(resolvedSlotId, nextRefreshIndex);
|
|
1844
|
-
if (options?.emitRefreshEvent !== false) {
|
|
1845
|
-
this.enqueue(TraceEventType.REFRESH, "refresh", {
|
|
1846
|
-
auctionId: options?.auctionId || existing.auctionId,
|
|
1847
|
-
transactionId: options?.transactionId || existing.transactionId,
|
|
1848
|
-
adUnitCode: resolvedSlotId,
|
|
1849
|
-
bid: options?.bid ?? existing.bidPayload,
|
|
1850
|
-
metadata: {
|
|
1851
|
-
...options?.metadata,
|
|
1852
|
-
refresh_index: String(nextRefreshIndex)
|
|
1853
|
-
}
|
|
1854
|
-
});
|
|
1855
|
-
}
|
|
1856
1849
|
if (existing.dwellTimer) {
|
|
1857
1850
|
clearTimeout(existing.dwellTimer);
|
|
1858
1851
|
existing.dwellTimer = null;
|
|
@@ -2115,16 +2108,6 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2115
2108
|
rec.viewableFired = false;
|
|
2116
2109
|
rec.accumulatedTimeInViewMs = 0;
|
|
2117
2110
|
}
|
|
2118
|
-
this.enqueue(TraceEventType.REFRESH, "refresh", {
|
|
2119
|
-
auctionId,
|
|
2120
|
-
transactionId,
|
|
2121
|
-
adUnitCode: targetSlot,
|
|
2122
|
-
bid: bidTrace,
|
|
2123
|
-
metadata: {
|
|
2124
|
-
...options?.metadata,
|
|
2125
|
-
refresh_index: String(nextRefreshIndex)
|
|
2126
|
-
}
|
|
2127
|
-
});
|
|
2128
2111
|
} else if (targetSlot) {
|
|
2129
2112
|
if (auctionId) {
|
|
2130
2113
|
this.slotLastAuctionIds.set(targetSlot, auctionId);
|
|
@@ -2243,7 +2226,8 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2243
2226
|
}
|
|
2244
2227
|
}
|
|
2245
2228
|
trackRawEvent(level, eventName, data) {
|
|
2246
|
-
const eventType = EVENT_NAME_TO_TYPE[eventName] ?? (level === "ERROR" ? TraceEventType.ERROR :
|
|
2229
|
+
const eventType = EVENT_NAME_TO_TYPE[eventName] ?? (level === "ERROR" ? TraceEventType.ERROR : void 0);
|
|
2230
|
+
if (eventType === void 0) return;
|
|
2247
2231
|
this.enqueue(eventType, eventName, data, level);
|
|
2248
2232
|
}
|
|
2249
2233
|
setUserId(userId) {
|
|
@@ -2299,6 +2283,19 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2299
2283
|
bidderOutcomes
|
|
2300
2284
|
});
|
|
2301
2285
|
}
|
|
2286
|
+
/**
|
|
2287
|
+
* The render cycle an auction ending now would fill for an ad unit: 0 for
|
|
2288
|
+
* a slot that has never rendered on this pageview, otherwise one past the
|
|
2289
|
+
* cycle it last rendered. The index only advances when a creative renders,
|
|
2290
|
+
* so two unfilled refresh auctions in a row report the same cycle; both
|
|
2291
|
+
* count as refreshes, which is the point. Stamped on AUCTION_END bidder
|
|
2292
|
+
* outcomes in enqueue; there is no per-refresh event.
|
|
2293
|
+
*/
|
|
2294
|
+
auctionCycleIndex(adUnitCode) {
|
|
2295
|
+
if (!adUnitCode) return 0;
|
|
2296
|
+
const last = this.slotRefreshIndices.get(adUnitCode) ?? this.slotViewabilityRecords.get(adUnitCode)?.refreshIndex;
|
|
2297
|
+
return last === void 0 ? 0 : last + 1;
|
|
2298
|
+
}
|
|
2302
2299
|
handleBidRequested(data) {
|
|
2303
2300
|
if (this.isDuplicate("bidRequested", data)) return;
|
|
2304
2301
|
this.log("DEBUG", "bidRequested", data);
|
|
@@ -2314,11 +2311,9 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2314
2311
|
const key = `${bidder}:${adUnitCode}`;
|
|
2315
2312
|
if (!auctionMap.has(key)) {
|
|
2316
2313
|
auctionMap.set(key, {
|
|
2317
|
-
bidder,
|
|
2318
2314
|
adUnitCode,
|
|
2319
|
-
mediaType,
|
|
2320
2315
|
outcome: BidderOutcome.BIDDER_OUTCOME_NO_RESPONSE,
|
|
2321
|
-
latencyMs: 0
|
|
2316
|
+
bid: { bidder, mediaType, latencyMs: 0 }
|
|
2322
2317
|
});
|
|
2323
2318
|
}
|
|
2324
2319
|
});
|
|
@@ -2334,43 +2329,23 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2334
2329
|
const latencyMs = Number.isFinite(data.timeToRespond) ? data.timeToRespond : 0;
|
|
2335
2330
|
const resMediaTypes = Object.keys(data.mediaTypes || {});
|
|
2336
2331
|
const mediaType = data.mediaType || (data.mediaTypes?.video ? "video" : resMediaTypes.length > 0 ? resMediaTypes[0] : "banner");
|
|
2337
|
-
if (auctionId
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
}
|
|
2355
|
-
}
|
|
2356
|
-
if (cpm > 0) {
|
|
2357
|
-
this.enqueue(TraceEventType.BID_RESPONSE, "bidResponse", {
|
|
2358
|
-
auctionId,
|
|
2359
|
-
transactionId: data.transactionId || "",
|
|
2360
|
-
adUnitCode,
|
|
2361
|
-
bid: {
|
|
2362
|
-
bidder,
|
|
2363
|
-
cpm,
|
|
2364
|
-
currency: data.originalCurrency ?? data.currency ?? "USD",
|
|
2365
|
-
...parseBidDimensions(data),
|
|
2366
|
-
dealId: data.dealId || "",
|
|
2367
|
-
mediaType,
|
|
2368
|
-
latencyMs,
|
|
2369
|
-
advertiserDomain: data.meta?.advertiserDomains?.[0] || "",
|
|
2370
|
-
creativeId: data.creativeId || ""
|
|
2371
|
-
}
|
|
2372
|
-
});
|
|
2373
|
-
}
|
|
2332
|
+
if (!auctionId || !bidder) return;
|
|
2333
|
+
const bid = cpm > 0 ? {
|
|
2334
|
+
bidder,
|
|
2335
|
+
cpm,
|
|
2336
|
+
currency: data.originalCurrency ?? data.currency ?? "USD",
|
|
2337
|
+
...parseBidDimensions(data),
|
|
2338
|
+
dealId: data.dealId || "",
|
|
2339
|
+
mediaType,
|
|
2340
|
+
latencyMs,
|
|
2341
|
+
advertiserDomain: data.meta?.advertiserDomains?.[0] || "",
|
|
2342
|
+
creativeId: data.creativeId || ""
|
|
2343
|
+
} : { bidder, mediaType, latencyMs };
|
|
2344
|
+
this.getOrCreateAuctionOutcomes(auctionId).set(`${bidder}:${adUnitCode}`, {
|
|
2345
|
+
adUnitCode,
|
|
2346
|
+
outcome: cpm > 0 ? BidderOutcome.BIDDER_OUTCOME_BID : BidderOutcome.BIDDER_OUTCOME_NO_BID,
|
|
2347
|
+
bid
|
|
2348
|
+
});
|
|
2374
2349
|
}
|
|
2375
2350
|
handleBidTimeout(data) {
|
|
2376
2351
|
if (this.isDuplicate("bidTimeout", data)) return;
|
|
@@ -2387,14 +2362,12 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2387
2362
|
const entry = auctionMap.get(key);
|
|
2388
2363
|
if (entry) {
|
|
2389
2364
|
entry.outcome = BidderOutcome.BIDDER_OUTCOME_TIMEOUT;
|
|
2390
|
-
if (latencyMs > 0) entry.latencyMs = latencyMs;
|
|
2365
|
+
if (latencyMs > 0 && entry.bid) entry.bid.latencyMs = latencyMs;
|
|
2391
2366
|
} else {
|
|
2392
2367
|
auctionMap.set(key, {
|
|
2393
|
-
bidder,
|
|
2394
2368
|
adUnitCode,
|
|
2395
|
-
mediaType: "banner",
|
|
2396
2369
|
outcome: BidderOutcome.BIDDER_OUTCOME_TIMEOUT,
|
|
2397
|
-
latencyMs
|
|
2370
|
+
bid: { bidder, mediaType: "banner", latencyMs }
|
|
2398
2371
|
});
|
|
2399
2372
|
}
|
|
2400
2373
|
}
|
|
@@ -2463,11 +2436,9 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2463
2436
|
}
|
|
2464
2437
|
} else {
|
|
2465
2438
|
auctionMap.set(key, {
|
|
2466
|
-
bidder,
|
|
2467
2439
|
adUnitCode,
|
|
2468
|
-
mediaType: "banner",
|
|
2469
2440
|
outcome: BidderOutcome.BIDDER_OUTCOME_NO_BID,
|
|
2470
|
-
latencyMs: 0
|
|
2441
|
+
bid: { bidder, mediaType: "banner", latencyMs: 0 }
|
|
2471
2442
|
});
|
|
2472
2443
|
}
|
|
2473
2444
|
}
|
|
@@ -2534,13 +2505,6 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2534
2505
|
record.viewableFired = false;
|
|
2535
2506
|
record.accumulatedTimeInViewMs = 0;
|
|
2536
2507
|
}
|
|
2537
|
-
this.enqueue(TraceEventType.REFRESH, "refresh", {
|
|
2538
|
-
auctionId: resolvedAuctionId,
|
|
2539
|
-
transactionId: resolvedTransactionId,
|
|
2540
|
-
adUnitCode,
|
|
2541
|
-
bid: bidTrace,
|
|
2542
|
-
metadata: { refresh_index: String(nextRefreshIndex) }
|
|
2543
|
-
});
|
|
2544
2508
|
} else if (adUnitCode) {
|
|
2545
2509
|
if (resolvedAuctionId) {
|
|
2546
2510
|
this.slotLastAuctionIds.set(adUnitCode, resolvedAuctionId);
|
|
@@ -2616,8 +2580,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2616
2580
|
transactionId: resolvedTransactionId,
|
|
2617
2581
|
mediaType: resolvedMediaType,
|
|
2618
2582
|
bid: bidTrace,
|
|
2619
|
-
refreshIndex: currentRefreshIndex
|
|
2620
|
-
emitRefreshEvent: false
|
|
2583
|
+
refreshIndex: currentRefreshIndex
|
|
2621
2584
|
});
|
|
2622
2585
|
}
|
|
2623
2586
|
}
|
|
@@ -2630,12 +2593,14 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2630
2593
|
if (!this.shouldSample(type, level)) return;
|
|
2631
2594
|
extendSession();
|
|
2632
2595
|
const protoEvent = {
|
|
2633
|
-
eventId: generateUUID(),
|
|
2596
|
+
eventId: idToBytes(generateUUID()),
|
|
2634
2597
|
timestampMs: Date.now(),
|
|
2635
2598
|
type,
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2599
|
+
// Typed events have a fixed name that ingest derives from `type`; only
|
|
2600
|
+
// ERROR events carry theirs, which names the failure.
|
|
2601
|
+
eventName: type === TraceEventType.ERROR ? eventName : "",
|
|
2602
|
+
auctionId: idToBytes(String(data.auctionId || "")),
|
|
2603
|
+
transactionId: idToBytes(String(data.transactionId || "")),
|
|
2639
2604
|
adUnitCode: data.adUnitCode || data.elementId || "",
|
|
2640
2605
|
namespace: data.ns || data.namespace || ""
|
|
2641
2606
|
};
|
|
@@ -2643,9 +2608,9 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2643
2608
|
protoEvent.bid = {
|
|
2644
2609
|
bidder: data.bid.bidder || "",
|
|
2645
2610
|
cpm: Number.isFinite(data.bid.cpm) ? data.bid.cpm : 0,
|
|
2646
|
-
// No defaults here: handlers with a priced bid (
|
|
2647
|
-
//
|
|
2648
|
-
//
|
|
2611
|
+
// No defaults here: handlers with a priced bid (bidWon, impression)
|
|
2612
|
+
// set currency/mediaType themselves. Defaulting for the rest would
|
|
2613
|
+
// stamp fake "USD"/"banner" on rows that carried no bid.
|
|
2649
2614
|
currency: data.bid.currency || "",
|
|
2650
2615
|
width: Number.isFinite(data.bid.width) ? data.bid.width : 0,
|
|
2651
2616
|
height: Number.isFinite(data.bid.height) ? data.bid.height : 0,
|
|
@@ -2660,7 +2625,12 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2660
2625
|
protoEvent.viewableDurationMs = Number.isFinite(data.viewableDurationMs) ? data.viewableDurationMs : 0;
|
|
2661
2626
|
}
|
|
2662
2627
|
if (data.bidderOutcomes && Array.isArray(data.bidderOutcomes)) {
|
|
2663
|
-
protoEvent.bidderOutcomes = data.bidderOutcomes
|
|
2628
|
+
protoEvent.bidderOutcomes = data.bidderOutcomes.map(
|
|
2629
|
+
(entry) => ({
|
|
2630
|
+
...entry,
|
|
2631
|
+
refreshIndex: entry.refreshIndex ?? this.auctionCycleIndex(entry.adUnitCode || "")
|
|
2632
|
+
})
|
|
2633
|
+
);
|
|
2664
2634
|
}
|
|
2665
2635
|
const metadata = { ...data.metadata };
|
|
2666
2636
|
if (data.error !== void 0 && data.error !== null) {
|
|
@@ -2677,11 +2647,11 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2677
2647
|
protoEvent.metadata = boundedMetadata;
|
|
2678
2648
|
}
|
|
2679
2649
|
this.queue.push(protoEvent);
|
|
2680
|
-
if (this.queue.length
|
|
2681
|
-
this.queue.splice(0, this.queue.length - MAX_QUEUE_SIZE);
|
|
2682
|
-
}
|
|
2683
|
-
if (this.queue.length >= BATCH_SIZE) {
|
|
2650
|
+
if (this.queue.length >= MAX_QUEUE_SIZE) {
|
|
2684
2651
|
this.flush();
|
|
2652
|
+
if (this.queue.length > MAX_QUEUE_SIZE) {
|
|
2653
|
+
this.queue.splice(0, this.queue.length - MAX_QUEUE_SIZE);
|
|
2654
|
+
}
|
|
2685
2655
|
} else if (REVENUE_FLUSH_TYPES.has(type) && this.revenueFlushTimer === null) {
|
|
2686
2656
|
this.revenueFlushTimer = setTimeout(() => {
|
|
2687
2657
|
this.revenueFlushTimer = null;
|
|
@@ -2713,14 +2683,14 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2713
2683
|
if (this.queue.length === 0 || !this.config.endpoint) return null;
|
|
2714
2684
|
const domain = typeof window !== "undefined" ? window.location.hostname : "";
|
|
2715
2685
|
const buildBatch = (evts) => ({
|
|
2716
|
-
propertyId: this.config.propertyId,
|
|
2717
|
-
pageviewId: this.config.pageviewId,
|
|
2718
|
-
sessionId: this.config.sessionId,
|
|
2686
|
+
propertyId: idToBytes(this.config.propertyId),
|
|
2687
|
+
pageviewId: idToBytes(this.config.pageviewId),
|
|
2688
|
+
sessionId: idToBytes(this.config.sessionId),
|
|
2719
2689
|
pageUrl: this.pageUrl,
|
|
2720
2690
|
country: this.config.country,
|
|
2721
2691
|
region: this.config.region,
|
|
2722
2692
|
deviceType: this.config.deviceType,
|
|
2723
|
-
userId: this.config.userId,
|
|
2693
|
+
userId: idToBytes(this.config.userId),
|
|
2724
2694
|
domain,
|
|
2725
2695
|
events: evts
|
|
2726
2696
|
});
|
|
@@ -2740,7 +2710,7 @@ var BidkernelPrebidAnalytics = class _BidkernelPrebidAnalytics {
|
|
|
2740
2710
|
const [dropped] = this.queue.splice(0, 1);
|
|
2741
2711
|
this.log(
|
|
2742
2712
|
"WARN",
|
|
2743
|
-
`Dropping oversized event ${dropped?.
|
|
2713
|
+
`Dropping oversized event (type ${dropped?.type}, ${encoded.byteLength} bytes exceeds the ${MAX_PAYLOAD_BYTES}-byte cap on its own)`
|
|
2744
2714
|
);
|
|
2745
2715
|
continue;
|
|
2746
2716
|
}
|
|
@@ -3789,8 +3759,7 @@ function attachVideoPlayer(analytics, target, options) {
|
|
|
3789
3759
|
transactionId: transactionId || cachedInitial?.transactionId,
|
|
3790
3760
|
mediaType: "video",
|
|
3791
3761
|
bid: cachedInitial?.bidTrace || options?.bid,
|
|
3792
|
-
metadata: options?.metadata
|
|
3793
|
-
emitRefreshEvent: false
|
|
3762
|
+
metadata: options?.metadata
|
|
3794
3763
|
});
|
|
3795
3764
|
}
|
|
3796
3765
|
const cleanup = () => {
|