Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion libraries/ortbConverter/processors/deal.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
import { isPlainObject } from '../../../src/utils.js';
import type { DealMeta } from '../../../src/bidfactory.ts';
import type { DealMeta, TakeoverMeta } from '../../../src/bidfactory.ts';
import type { ORTBBid } from '../../../src/types/ortb/response.d.ts';
import type { TakeoverExt } from '../../../src/types/ortb/ext/deal.d.ts';

function isNonNegativeNumber(value: unknown): value is number {
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
}

const TAKEOVER_MODES = ['all', 'max', 'viewport'];

function nonEmptyStrings(value: unknown): string[] | undefined {
if (!Array.isArray(value)) return;
const strings = value.filter(item => typeof item === 'string' && item !== '');
return strings.length > 0 ? strings : undefined;
}

function getTakeoverMeta(takeover: TakeoverExt | undefined): TakeoverMeta | undefined {
if (!isPlainObject(takeover)) {
return;
}
const { mode, min_slots: minSlots, exclusivity } = takeover;
const takeoverMeta: TakeoverMeta = {
mode: TAKEOVER_MODES.includes(mode) ? mode as TakeoverMeta['mode'] : 'max'
};
if (Number.isInteger(minSlots) && minSlots > 0) {
takeoverMeta.minSlots = minSlots;
}
if (isPlainObject(exclusivity)) {
const adomain = nonEmptyStrings(exclusivity.adomain);
const cat = nonEmptyStrings(exclusivity.cat);
if (adomain || cat) {
takeoverMeta.exclusivity = {
...(adomain && { adomain }),
...(cat && { cat })
};
}
}
return takeoverMeta;
}

/**
* Normalize ORTB `bid.ext.prebid.deal` into the shape used for `bidResponse.meta.deal`.
* Only known, correctly typed fields are copied. Deal metadata is ignored unless the bid has a `dealid`.
Expand Down Expand Up @@ -35,5 +68,9 @@ export function getDealMeta(bid: ORTBBid): DealMeta | undefined {
if (typeof deal.source === 'string' && deal.source !== '') {
dealMeta.source = deal.source;
}
const takeover = getTakeoverMeta(deal.takeover);
if (takeover) {
dealMeta.takeover = takeover;
}
return dealMeta;
}
96 changes: 96 additions & 0 deletions modules/takeover/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Overview

Module Name: takeover

Purpose: Let one takeover deal win several ad units of the same auction together, a programmatic page takeover or roadblock.

# Description

A takeover is a set of ordinary per-ad-unit deal bids from the same bidder that share a `dealid` and carry takeover terms in `ext.prebid.deal.takeover`:

```json
{
"dealid": "TKO-ACME-01",
"price": 18.00,
"ext": {
"prebid": {
"deal": {
"type": 3,
"takeover": {
"mode": "viewport",
"min_slots": 3,
"exclusivity": { "adomain": ["competitor.com"], "cat": ["IAB11-4"] }
}
}
}
}
}
```

When an auction ends, the module decides whether a takeover wins:

1. Takeovers are ranked against each other first, by priority and then total desirability. At most one wins an auction.
2. On each ad unit, the takeover's bid is compared with the best other bid by priority tier (`bid.priority`, lower wins). It takes ad units where it is in a higher tier and loses ad units where it is in a lower tier.
3. On ad units in the same tier, the takeover wins only if the sum of its bids' desirability beats the sum of the best other bids' desirability, plus the publisher's `premium` and the value of any bids its exclusivity keeps off the page.

Modes:

| Mode | Ad units covered |
| --- | --- |
| `all` | Every ad unit in the auction, or none. Rejected if an ad unit already rendered a bid from an earlier auction. |
| `max` | As many ad units as the takeover wins, at least `min_slots` and the publisher's `minSlotsFloor`. |
| `viewport` | Every ad unit at least `viewportPercent` in view when bids were requested; at least `min_slots`. |

A winning takeover's bids are the only bids left on the ad units it won, and get the `hb_tko=1` targeting key. Bids of takeovers that lose are removed, so a takeover never wins only part of what it bid for.

# Configuration

```javascript
pbjs.setConfig({
takeover: {
enabled: true,
acceptFrom: 'priority', // 'priority' (default) | 'allowlist' | 'deals'
acceptFromBidders: [], // with 'allowlist'
modes: ['all', 'max', 'viewport'],
minSlotsFloor: 2,
premium: 0,
excludeAdUnits: ['footer'],
collapseUnfilled: false,
blockRefresh: false,
allowExclusivity: false,
exclusivityLabels: { 'pol-opp': ['IAB11-4'] },
viewportPercent: 50
}
});
```

| Setting | Default | Description |
| --- | --- | --- |
| `enabled` | `false` | Turns the module on. |
| `acceptFrom` | `'priority'` | Whose takeovers are acted on: bidders trusted with priority bids (`allowPriorityBids` in `bidderSettings` or `s2sConfig`), the bidders in `acceptFromBidders`, or any bid with a deal ID. |
| `acceptFromBidders` | `[]` | Bidder codes for `acceptFrom: 'allowlist'`. |
| `modes` | `['max']` | Takeover modes the publisher accepts. |
| `minSlotsFloor` | `2` | Takeovers that would win fewer ad units are ignored. |
| `premium` | `0` | Extra margin, as a fraction, a takeover must beat other bids by within a priority tier. |
| `excludeAdUnits` | `[]` | Ad units never taken over. |
| `collapseUnfilled` | `false` | In `all` mode, leave ad units the takeover has no bid for empty instead of rejecting the takeover. |
| `blockRefresh` | `false` | Skip `requestBids` for ad units that rendered a takeover bid. |
| `allowExclusivity` | `false` | Let takeovers keep the advertisers and categories in their `exclusivity` out of the ad units they did not bid on. |
| `exclusivityLabels` | `{}` | Maps `hb_excl` targeting values to IAB categories, so the ad server can apply competitive exclusions. |
| `viewportPercent` | `50` | Percentage of an ad unit's element that must be in view for `viewport` mode. |

# Ad server setup

- Use GPT single-request mode, so the ad server sees every ad unit at once.
- Target dedicated line items to `hb_tko=1` at a priority above price priority and AdX, so the ad server does not split the takeover.
- If you restrict targeting keys with `targetingControls.allowTargetingKeys`, add `hb_tko` (and `hb_excl` if you use exclusivity labels).

# Analytics

Each winning bid keeps its own CPM, and its `meta.deal.takeover.groupId` ties it to the rest of the takeover. The module emits a `takeoverResult` event for every takeover in an auction:

```javascript
pbjs.onEvent('takeoverResult', ({ groupId, auctionId, bidderCode, dealId, mode, won, reason, adUnitCodes, totalCpm }) => {});
```

`reason` is set when the takeover lost: `outranked`, `notEnoughSlots`, `lostOnValue`, `slotAlreadyRendered` or `nothingInView`.
Loading