Skip to content

Takeover Module: page takeover deals (#15719) - #16321

Open
WhimsicalCoder wants to merge 6 commits into
prebid:masterfrom
WhimsicalCoder:agent/takeover-module
Open

WhimsicalCoder wants to merge 6 commits into
prebid:masterfrom
WhimsicalCoder:agent/takeover-module

Conversation

@WhimsicalCoder

@WhimsicalCoder WhimsicalCoder commented Nov 24, 2026 •

Copy link
Copy Markdown

Implements #15719 (whole page takeover on deal response) as an optional module, following the design discussed there: https://github.com/WhimsicalCoder/prebid-bundle-auction/blob/main/SPEC.md

Type of change

  • Feature
  • Does this change affect user-facing APIs or examples documented on http://prebid.org?

Description of change

Core (minimal):

  • libraries/ortbConverter/processors/deal.ts: normalizes ext.prebid.deal.takeover (mode, min_slots, exclusivity) into bid.meta.deal.takeover; malformed fields are dropped.
  • src/bidfactory.ts, src/types/ortb/ext/deal.d.ts: TakeoverMeta / TakeoverExt types.
  • src/constants.ts: EVENTS.TAKEOVER_RESULT.

Module (modules/takeover):

  • A takeover = a bidder's deal bids sharing a dealid. Decided at auctionEnd; only one takeover wins an auction.
  • Ranking: takeovers against each other first (priority, then total desirability); then per ad unit by priority tier; within a tier, the takeover's summed desirability must beat the sum of the best other bids, plus an optional publisher premium and the value of bids its exclusivity removes.
  • Modes: all (every ad unit or none; rejected if a slot already rendered), max (min_slots / minSlotsFloor), viewport (ad units in view when bids are requested).
  • Trust: acceptFrom = priority (default, allowPriorityBids), allowlist, or deals.
  • Applies the decision through a before-hook on getHighestCpmBidsFromBidPool (same pattern as multibid); winners get hb_tko=1 (and hb_excl for exclusivity labels).
  • Analytics: meta.deal.takeover.groupId on winning bids, plus a takeoverResult event per takeover.
  • Optional blockRefresh, collapseUnfilled, excludeAdUnits.

Testing

  • New test/spec/modules/takeover_spec.js (43 tests, ~99% line coverage of the module), plus deal normalization tests in test/spec/ortbConverter/common_spec.js.
  • npx gulp test-only: 968 files, 30,582 tests passed.
  • npx gulp lint --nolintfix on changed files, npx gulp ts, npx gulp ts-strict: clean.
  • Tested in Chrome on a sample page with simulated bids (debugging module): all three modes, losing on value, exclusivity, and an untrusted bidder. Not yet tested with GAM.

Other information

Docs PR: prebid/prebid.github.io#7006

🤖 Design by WhimsicalCoder (see #15719); code and tests written with Claude Code.

WhimsicalCoder and others added 3 commits November 24, 2026 03:13
Read ext.prebid.deal.takeover into bid.meta.deal.takeover, add the
TakeoverMeta type and the takeoverResult event name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds the takeover module (modes all, max and viewport), its tests and docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T10:23:34.870646Z 252c653 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aeb3430bda

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread modules/takeover/index.ts Outdated
let won = outright;
if (sameTier.length > 0) {
const exclusivity = takeoverConfig.allowExclusivity ? group.terms.exclusivity : undefined;
const outside = eligibleCodes.filter(code => !matched.includes(code));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Count exclusions from matched slots the takeover loses

When allowExclusivity is enabled and a max/viewport group has enough outright wins to satisfy minSlots, it can still lose a matched lower-priority slot; only all rejects lostTier. This list omits that slot, but the winner path later removes matching competitor bids from every slot not in codes. Because the lost-tier bid is also excluded from sameTier, it contributes to neither value term, so the module can accept a takeover and delete the only competing bid from a slot it does not win. Include those exclusions in the hurdle or restrict the drop to winning slots.

AGENTS.md reference: AGENTS.md:L129-L129

Useful? React with 👍 / 👎.

Comment thread modules/takeover/index.ts Outdated

// takeovers are ranked against each other first; only one can win an auction
groups.sort((a, b) => (bestPriority(a) - bestPriority(b)) || (totalDesirability(b) - totalDesirability(a)));
const takeoverAdIds = new Set(groups.flatMap(group => [...group.bidByAdUnit.values()].map(bid => bid.adId)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove all bids from a rejected takeover group

When a bidder returns multiple responses with the same dealId for one ad unit, groupTakeovers retains only the best in bidByAdUnit, so this set leaves the alternates in otherBids. If that group is rejected (for example, it misses minSlots) and no other takeover wins that slot, decision.droppedAdIds contains only the representative; targetBidPoolHook therefore passes an alternate through, and the normal per-bidder targeting reduction can select it as a regular bid. A rejected page deal can then render on only part of the page; track and drop every response belonging to the group.

AGENTS.md reference: AGENTS.md:L129-L129

Useful? React with 👍 / 👎.

WhimsicalCoder added a commit to WhimsicalCoder/prebid.github.io that referenced this pull request Nov 24, 2026
Docs for prebid/Prebid.js#16321.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WhimsicalCoder and others added 2 commits November 24, 2026 03:55
Drop every bid of a rejected takeover, including repeat bids on an ad
unit, and apply exclusivity only to ad units the takeover did not bid on,
where its cost is counted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@WhimsicalCoder

Copy link
Copy Markdown
Author

🤖 This comment was written by an AI agent (Claude Code) on behalf of WhimsicalCoder.

Both findings fixed in the latest commits, with a regression test for each:

  1. Exclusivity is now only applied to, and charged for, ad units the takeover did not bid on, so a lost ad unit keeps its winning bid.
  2. A rejected takeover now drops every one of its bids, including repeat bids on the same ad unit.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c357221588

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread modules/takeover/index.ts Outdated
}
const matched = scope.filter(code => group.bidByAdUnit.has(code));
// exclusivity is only charged for, and only applied to, ad units the takeover did not bid on
const unmatched = eligibleCodes.filter(code => !matched.includes(code));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Base exclusivity on actual takeover bids

A remaining case is viewport: matched contains only in-view slots, so an eligible off-screen slot with a bid in group.bidByAdUnit is classified as unmatched. If it has an excluded competitor bid, that bid is removed even though the takeover's off-screen bid is also dropped; when it is the only competitor, the slot is left empty although the takeover did not win it. If there is a same-tier in-view slot, the off-screen bid is also charged in the value hurdle. Build the exclusion set from actual bid presence or keep exclusivity within the winning scope.

Useful? React with 👍 / 👎.

Comment thread modules/takeover/index.ts
if (!decision) return true;
if (decision.droppedAdIds.has(bid.adId)) return false;
const winner = decision.winnerByAdUnit.get(bid.adUnitCode);
return winner == null || winner === bid.adId;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Filter cached bids from takeover-winning slots

When useBidCache: true and an unexpired bid from an earlier auction is present for a slot this takeover wins, that bid can have no winner in its own decision and pass through this branch. getBidsReceived() includes cached bids, so an older bid can then beat the takeover in the targeting pool even though the current decision reports that slot as won. Suppress other-auction bids on takeover-winning slots or include cached bids in the decision.

Useful? React with 👍 / 👎.

Comment thread modules/takeover/index.ts Outdated
if (!exclusivity) return false;
const domains = bid.meta?.advertiserDomains ?? [];
const categories = [bid.meta?.primaryCatId, ...(bid.meta?.secondaryCatIds ?? [])].filter(Boolean);
return domains.some(domain => exclusivity.adomain?.includes(domain)) ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize advertiser domains before matching

When allowExclusivity is enabled and a bid reports an advertiser domain with different casing from the takeover's adomain list, this exact match misses it even though domain names are case-insensitive. The competitor is therefore neither charged nor dropped and can still be selected despite the exclusion; normalize both sides before comparing.

Useful? React with 👍 / 👎.

- Exclusivity only applies to ad units the takeover has no bid on, so
  off-screen ad units in viewport mode keep their competing bids.
- The latest auction for an ad unit decides whether a takeover holds it,
  so cached bids from earlier auctions cannot displace a takeover.
- Advertiser domains are matched case-insensitively.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@WhimsicalCoder

Copy link
Copy Markdown
Author

🤖 This comment was written by an AI agent (Claude Code) on behalf of WhimsicalCoder.

All three findings fixed in the latest commit, with a regression test for each:

  1. Exclusivity is based on the ad units the takeover actually has bids on, so off-screen ad units in viewport mode keep their competing bids.
  2. The latest auction for an ad unit decides whether a takeover holds it, so cached bids from earlier auctions can't displace a winning takeover, while a later auction without a takeover still competes normally.
  3. Advertiser domains are matched case-insensitively.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 252c653302

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread modules/takeover/index.ts
Comment on lines +374 to +376
decisions.forEach(decision => decision.adUnitCodes.forEach(code => {
const winner = decision.winnerByAdUnit.get(code);
winnerByAdUnit.set(code, winner != null && inPool.has(winner) ? winner : undefined);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Order decisions by auction start time

When auctions for the same ad unit overlap and the older one finishes last, onAuctionEnd inserts its decision after the newer one, so this traversal lets the stale decision overwrite the newer slot result. Core marks latestAuctionForAdUnit when requestBids starts; with useBidCache: true, the older response remains in getBidsReceived(), and an older no-takeover decision can clear the current takeover winner here, letting that cached bid compete. Order decisions by auction start or otherwise ignore results older than the latest request for each ad unit.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant