fix(prebid-analytics): populate bid cpm/status and track timeout bids correctly#302
Merged
Merged
Conversation
mosherBT
reviewed
Jul 16, 2026
| payload["bidWonAt"] = null; | ||
| payload["optableLoaded"] = !auction.missed; | ||
|
|
||
| navigator.sendBeacon( |
Contributor
There was a problem hiding this comment.
I think this would still miss. This is async so the unload might tear everything down. I think this needs to run Synchronous
Member
There was a problem hiding this comment.
My understanding is that this is the purpose of sendBeacon or fetch{keepalive: true}, it will still fire even if you close the tab.
|
|
||
| await disabledAnalytics.trackAuctionEnd(event); | ||
| window.dispatchEvent(new Event("beforeunload")); | ||
| await new Promise((resolve) => setTimeout(resolve, 10)); |
Contributor
There was a problem hiding this comment.
We don't nescesarily have the 10ms on browser though
Contributor
Author
There was a problem hiding this comment.
What do you suggest instead?
mosherBT
approved these changes
Jul 16, 2026
zapo
approved these changes
Jul 16, 2026
… correctly - Merge cpm, size, currency, and status from bidsReceived into each bid in toWitness, fixing the win_cpm fallback in the downstream Spark job which requires bid_status != REQUESTED and bid_cpm IS NOT NULL - Mark bidder request status as NO_BID or TIMEOUT from the respective sets - Track BID_TIMEOUT events via a new pendingTimeoutBids map (bidTimeout fires as a separate Prebid event before auctionEnd, not as a field on it) - Store timeoutBids on AuctionItem and clean up pendingTimeoutBids after trackAuctionEnd; replay missed bidTimeout events in setHooks - Add tests asserting the actual toWitness payload for cpm, size, currency, RECEIVED/NO_BID/TIMEOUT statuses, live bidTimeout listener, and missed event replay Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…eunload Auctions waiting for a bidWon event (held in a setTimeout up to bidWinTimeout) were silently dropped on page unload. Added a beforeunload listener that cancels pending timeouts and sends each unresolved auction immediately via navigator.sendBeacon, which is guaranteed to complete even as the page tears down. Sampling and analytics-enabled checks are respected. Includes tests for the flush path, the disabled/already-sent no-op paths, and global listener cleanup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…h via beacon The `sampled` boolean is now evaluated exactly once in `trackAuctionEnd` (analytics enabled AND shouldSample()) and stored on `AuctionItem`. The `handleBeforeUnload` beacon path, the delayed timeout callback, and `trackBidWon` all read `auction.sampled` instead of re-evaluating, so auctions in the sampling holdout can never be accidentally sent. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
visibilitychange fires reliably on mobile (where beforeunload often doesn't), and also catches tab switches and app backgrounding. The handler checks document.visibilityState === 'hidden' before flushing and deletes each flushed auction from the map to prevent a double-send if the user returns to the tab and a bidWon fires. Added a test for the 'visible' (no-op) case alongside the existing hidden/disabled/holdout/no-pending-timeout cases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Integrates origin/master restructuring (bidWonEvents accumulator, missedAuctionIds tracking, auctionInit replay, EID deduplication, originSlug field) while preserving our branch additions: bidTimeout tracking via pendingTimeoutBids, once-per-auction sampled flag, and visibilitychange beacon flush instead of beforeunload. Also fixes handleVisibilityChange to pass auction.bidWonEvents to toWitness and compute bidWonAt from them rather than hardcoding null. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jrosendahl-opt
force-pushed
the
fix/prebid-analytics-bid-cpm-status
branch
from
July 16, 2026 20:45
42f3cd5 to
793a673
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
toWitnesswas only mergingsplitTestAssignmentfrombidsReceived—cpm,size,currency, andstatuswere never populated on individual bids. The downstream Spark job (prebid_analytics_fact.go) usesbid.cpmandbid.status != REQUESTEDfor itswin_cpmfallback (Case 2:MAX(bid_cpm) + 0.01), so this causedwin_cpmto silently fall to0.0whenever nobidWonevent was received.timeoutBidswas destructured from theauctionEndevent where it doesn't exist in Prebid.js — it always defaulted to[]. Prebid firesBID_TIMEOUTas a separate event beforeauctionEnd. Added apendingTimeoutBidsmap that accumulates these via a newbidTimeoutlistener, stores them onAuctionItem, and cleans up aftertrackAuctionEnd.NO_BIDandTIMEOUTstatuses on the bidder request objects in the witness payload are now set correctly, fixingresponse_countinfact_bid.-Handle Page Unload: flush cache when page unloads