Skip to content

Commit 684cb4f

Browse files
MO-Thibaultclaude
andauthored
fix(analytics/ prototype): detect in-flight auctions as missed, remove bidWon (#293)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9a13671 commit 684cb4f

1 file changed

Lines changed: 14 additions & 25 deletions

File tree

lib/addons/prototypes/analytics.js

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class OptablePrebidAnalytics {
2121

2222
// Store auction data
2323
this.auctions = {};
24+
this.missedAuctionIds = new Set();
2425
this.maxAuctionDataSize = 20;
2526

2627
sessionStorage.optableSessionDepthIndex = (Number(sessionStorage?.optableSessionDepthIndex) || 0) + 1;
@@ -57,26 +58,25 @@ class OptablePrebidAnalytics {
5758
}
5859

5960
setHooks(pbjs) {
60-
this.log("Processing missed auctionEnd");
61+
this.log("Processing past events");
6162
pbjs.getEvents().forEach((event) => {
62-
if (event.eventType === "auctionEnd") {
63-
this.log("auction missed");
63+
if (event.eventType === "auctionInit") {
64+
this.missedAuctionIds.add(event.args.auctionId);
65+
} else if (event.eventType === "auctionEnd") {
66+
this.missedAuctionIds.delete(event.args.auctionId);
67+
this.log(`auction ${event.args.auctionId} missed (completed before hook)`);
6468
this.trackAuctionEnd(event.args, true);
6569
}
66-
if (event.eventType === "bidWon") {
67-
this.log("bid won missed");
68-
this.trackBidWon(event.args, true);
69-
}
7070
});
7171

7272
this.log("Hooking into Prebid.js events");
7373
pbjs.onEvent("auctionEnd", (event) => {
74-
this.log("auctionEnd event received");
75-
this.trackAuctionEnd(event);
76-
});
77-
pbjs.onEvent("bidWon", (event) => {
78-
this.log("bidWon event received");
79-
this.trackBidWon(event);
74+
const missed = this.missedAuctionIds.has(event.auctionId);
75+
if (missed) {
76+
this.missedAuctionIds.delete(event.auctionId);
77+
}
78+
this.log(`auctionEnd event received, missed=${missed}`);
79+
this.trackAuctionEnd(event, missed);
8080
});
8181
}
8282

@@ -302,18 +302,6 @@ class OptablePrebidAnalytics {
302302
}
303303
}
304304

305-
trackBidWon(event, missed) {
306-
const filteredEvent = {
307-
auctionId: event.auctionId,
308-
bidderCode: event.bidderCode,
309-
bidId: event.requestId,
310-
tenant: this.config.tenant,
311-
missed,
312-
};
313-
this.log("bidWon filtered event", filteredEvent);
314-
this.sendToWitnessAPI("bid_won", filteredEvent);
315-
}
316-
317305
/**
318306
* Clean up old auctions to prevent memory leaks
319307
*/
@@ -331,6 +319,7 @@ class OptablePrebidAnalytics {
331319
*/
332320
clearData() {
333321
this.auctions = {};
322+
this.missedAuctionIds.clear();
334323
this.log("All analytics data cleared");
335324
}
336325
}

0 commit comments

Comments
 (0)