-
Notifications
You must be signed in to change notification settings - Fork 2.4k
TPC Adapter (DRAFT) - Opened in Error #14866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+585
−0
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1929227
Add Prebid.js build and deploy pipeline
mhc-gh e2ccd10
Fix deploy path from prebid to prod
mhc-gh 476e692
Fix branch name from main to master
mhc-gh f7085b5
git workflow fix 1
mhc-gh 34c8a9e
adding tpcBidAdapter files
mhc-gh f60ad86
workflow fix dist path
mhc-gh 0709ba2
add user id modules to build
mhc-gh 1f9322e
+ uid,criteo user id modules to build process
mhc-gh b95c62f
add criteo id fix to build process
mhc-gh 1d3240f
add uid fix to build process
mhc-gh 657a6f0
add architecture overview and command reference to CLAUDE.md
mhc-gh 53b6e32
Merge remote-tracking branch 'upstream/master' into chore/sync-upstre…
mhc-gh 687b104
AGENTS.md: revert to upstream parity
mhc-gh 5447701
ci: remove deploy workflow (moved to private deployments repo)
mhc-gh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| 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 }]; | ||
| }, | ||
|
|
||
| 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); | ||
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
| 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 | ||
| }, | ||
| }); | ||
| }); | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getUserSyncscurrently returnshttps://pbs.tpcsrv.com/cookie_sync?...directly as aniframe/imageURL, 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 ongetUserSyncswill lose cookie-match coverage; compare with existing PBS-style adapters in this repo (e.g.modules/tealBidAdapter.jsandmodules/relevantdigitalBidAdapter.js) that wrap/cookie_syncvia a load-cookie HTML endpoint or explicit redirect pixels.Useful? React with 👍 / 👎.