Skip to content
Closed
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
148 changes: 148 additions & 0 deletions modules/tpcBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { pbsExtensions } from '../libraries/pbsExtensions/pbsExtensions.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js';
import { deepAccess, deepSetValue, deepClone, logWarn, logError, triggerPixel, isEmpty, shuffle } from '../src/utils.js';

const BIDDER_CODE = 'tpc';
const PBS_ENDPOINT = 'https://pbs.tpcsrv.com/openrtb2/auction';
const USER_SYNC_ENDPOINT = 'https://pbs.tpcsrv.com/cookie_sync';
const MAX_SYNC_COUNT = 10;

const converter = ortbConverter({
processors: pbsExtensions,
context: {
netRevenue: true,
ttl: 300,
},
imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
const { placementId, bidder } = bidRequest.params;
if (placementId) {
deepSetValue(imp, 'ext.prebid.bidder.tpc.placementId', placementId);
}
if (bidder) {
deepSetValue(imp, 'ext.prebid.bidder.tpc.bidder', bidder);
}
return imp;
},
overrides: {
bidResponse: {
bidderCode(orig, bidResponse, bid, { bidRequest }) {
const useSourceBidderCode = deepAccess(bidRequest, 'params.useSourceBidderCode', false);
if (useSourceBidderCode) {
orig.apply(this, [...arguments].slice(1));
}
},
},
},
});

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
aliases: [],

isBidRequestValid(bid) {
if (!deepAccess(bid, 'params.accountId')) {
logWarn(`${BIDDER_CODE}: bid missing required params.accountId`, bid);
return false;
}
return true;
},

buildRequests(validBidRequests, bidderRequest) {
const { bidder } = validBidRequests[0];
const data = converter.toORTB({ bidRequests: validBidRequests, bidderRequest });
const accountId = deepAccess(validBidRequests[0], 'params.accountId');
if (accountId) {
deepSetValue(data, 'site.publisher.id', accountId);
}
data.ext.prebid.passthrough = {
...data.ext.prebid.passthrough,
tpc: { bidder },
};
data.tmax = (bidderRequest.timeout || 1500) - 100;
return {
method: 'POST',
url: PBS_ENDPOINT,
data,
};
},

interpretResponse(serverResponse, request) {
if (!serverResponse?.body) return [];
const resp = deepClone(serverResponse.body);
const { bidder } = request.data.ext.prebid.passthrough.tpc;
const modifiers = {
responsetimemillis: (values) => Math.max(...values),
errors: (values) => [].concat(...values),
};
Object.entries(modifiers).forEach(([field, combineFn]) => {
const obj = resp.ext?.[field];
if (!isEmpty(obj)) {
resp.ext[field] = { [bidder]: combineFn(Object.values(obj)) };
}
});
return converter.fromORTB({ response: resp, request: request.data }).bids;
},

getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) {
if (!syncOptions.iframeEnabled && !syncOptions.pixelEnabled) return [];

let bidders = [];
serverResponses.forEach(({ body }) => {
Object.keys(body?.ext?.responsetimemillis || {}).forEach(b => {
if (!bidders.includes(b)) bidders.push(b);
});
});

if (!bidders.length) return [];

bidders = shuffle(bidders).slice(0, MAX_SYNC_COUNT);

const params = new URLSearchParams();
params.set('bidders', bidders.join(','));
params.set('max_sync_count', MAX_SYNC_COUNT);

if (gdprConsent) {
params.set('gdpr', gdprConsent.gdprApplies ? '1' : '0');
if (gdprConsent.consentString) {
params.set('gdpr_consent', gdprConsent.consentString);
}
}
if (uspConsent) {
params.set('us_privacy', uspConsent);
}
if (gppConsent?.gppString) {
params.set('gpp', gppConsent.gppString);
}
if (Array.isArray(gppConsent?.applicableSections)) {
params.set('gpp_sid', gppConsent.applicableSections.join(','));
}

const syncUrl = `${USER_SYNC_ENDPOINT}?${params.toString()}`;
if (syncOptions.iframeEnabled) {
return [{ type: 'iframe', url: syncUrl }];
}
return [{ type: 'image', url: syncUrl }];
Comment on lines +124 to +128
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Route PBS cookie sync through an executable sync page

getUserSyncs currently returns https://pbs.tpcsrv.com/cookie_sync?... directly as an iframe/image URL, but that endpoint returns sync instructions rather than performing bidder redirects itself, so the browser never executes the downstream sync URLs and user ID matching is effectively skipped. In practice this means auctions that rely on getUserSyncs will lose cookie-match coverage; compare with existing PBS-style adapters in this repo (e.g. modules/tealBidAdapter.js and modules/relevantdigitalBidAdapter.js) that wrap /cookie_sync via a load-cookie HTML endpoint or explicit redirect pixels.

Useful? React with 👍 / 👎.

},

onBidWon(bid) {
if (bid.pbsWurl) triggerPixel(bid.pbsWurl);
if (bid.burl) triggerPixel(bid.burl);
},

onBidderError({ error }) {
if (error.status === 400 && error.responseText) {
const match = error.responseText.match(/found for id: (.*)/);
if (match?.[1]) {
logError(`${BIDDER_CODE}: account '${match[1]}' not found. Please verify your accountId.`, error);
return;
}
}
logError(`${BIDDER_CODE} bidder error`, error);
},
};

registerBidder(spec);
157 changes: 157 additions & 0 deletions modules/tpcBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Overview

```
Module Name: TPC Bid Adapter
Module Type: Bidder Adapter
Maintainer: your-team@tpcsrv.com
```

Connects to the TPC Prebid Server at `pbs.tpcsrv.com` for header bidding.
Supports **banner**, **video** (instream & outstream), and **native** ad formats.

---

## Consent & Privacy Support

| Signal | Support |
|--------|---------|
| TCF / GDPR | ✅ Passed in `regs.ext.gdpr` + `user.ext.consent` |
| US Privacy (legacy) | ✅ Passed in `regs.ext.us_privacy` |
| GPP (Global Privacy Platform) | ✅ Passed in `regs.gpp` + `regs.gpp_sid` |
| COPPA | ✅ Reads `pbjs.setConfig({ coppa: true })` |

---

## User ID & Identity

Any EIDs collected by the Prebid.js **User ID module** are forwarded to Prebid Server in `user.eids`.

---

## User Syncing

After each auction the adapter triggers a single **iframe** (preferred) or **pixel** sync with the
PBS `/cookie_sync` endpoint. Bidder codes are derived automatically from the auction response, so
PBS syncs only the seats that actually responded.

---

## Bid Params

| Name | Scope | Type | Description |
|------|-------|------|-------------|
| `accountId` | **Required** | string | Publisher account ID on pbs.tpcsrv.com |
| `placementId` | Optional | string | Placement / tag identifier |
| `bidder` | Optional | string | Downstream PBS bidder code for single-bidder passthrough |

---

## Ad Unit Examples

### Banner

```js
var adUnits = [{
code: 'banner-div',
mediaTypes: {
banner: { sizes: [[300, 250], [728, 90]] },
},
bids: [{
bidder: 'tpc',
params: {
accountId: 'pub-1234',
placementId: 'homepage-leaderboard',
},
}],
}];
```

### Video (instream)

```js
var adUnits = [{
code: 'video-div',
mediaTypes: {
video: {
playerSize: [[640, 480]],
context: 'instream',
mimes: ['video/mp4'],
protocols: [1, 2, 3, 4, 5, 6],
playbackmethod: [2],
skip: 1,
},
},
bids: [{
bidder: 'tpc',
params: {
accountId: 'pub-1234',
placementId: 'pre-roll-640',
},
}],
}];
```

### Native

```js
var adUnits = [{
code: 'native-div',
mediaTypes: {
native: {
ortb: {
assets: [
{ id: 1, required: 1, title: { len: 80 } },
{ id: 2, required: 1, img: { type: 3, w: 300, h: 250 } },
{ id: 3, required: 0, data: { type: 2 } }, // description
],
},
},
},
bids: [{
bidder: 'tpc',
params: {
accountId: 'pub-1234',
},
}],
}];
```

### Multi-format

```js
var adUnits = [{
code: 'multi-div',
mediaTypes: {
banner: { sizes: [[300, 250]] },
video: {
playerSize: [[300, 250]],
context: 'outstream',
mimes: ['video/mp4'],
protocols: [1, 2, 3, 4],
},
},
bids: [{
bidder: 'tpc',
params: {
accountId: 'pub-1234',
placementId: 'sidebar-multi',
},
}],
}];
```

---

## Full Example Setup

```js
pbjs.que.push(function () {
pbjs.addAdUnits(adUnits);

pbjs.requestBids({
bidsBackHandler: function (bids) {
// ... send targeting to ad server
},
});
});
```
Loading
Loading