-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Asterio Bid Adapter: add initial bidder adapter #14691
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
Merged
+439
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
86b708b
Asterio Bid Adapter: add initial bid adapter
mihanikw2g f1c2864
Asterio Bid Adapter: corrected documentation
danoykin 7a78ddd
Asterio Bid Adapter: review fixes
mihanikw2g 03a1d19
Merge branch 'master' into master
mihanikw2g 2e7b6d8
Asterio Bid Adapter: migrating to typescript
mihanikw2g 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,35 @@ | ||
| # Overview | ||
|
|
||
| ``` | ||
| Module Name: Asterio Bidder Adapter | ||
| Module Type: Bidder Adapter | ||
| Maintainer: mnikulin@asteriosoft.com | ||
| ``` | ||
|
|
||
| # Description | ||
|
|
||
| Connects to Asterio Bidder for bids. | ||
| Asterio bid adapter supports Banner and Video ads. | ||
|
|
||
| # Bid Params | ||
|
|
||
| | Name | Scope | Type | Description | | ||
| | ---- | ----- | ---- | ----------- | | ||
| | `adUnitToken` | required | String | Asterio ad unit token provided by Asterio. | | ||
| | `pos` | optional | Number | Ad position override. When omitted, the adapter uses `mediaTypes.banner.pos` or `mediaTypes.video.pos` from the ad unit. | | ||
|
|
||
| # Test Parameters | ||
| ``` | ||
| const adUnits = [ | ||
| { | ||
| bids: [ | ||
| { | ||
| bidder: 'asterio', | ||
| params: { | ||
| adUnitToken: '????????-????-????-????-????????????', // adUnitToken provided by Asterio | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ]; | ||
| ``` | ||
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,149 @@ | ||
| import { type AdapterRequest, type BidderSpec, type ServerResponse, registerBidder } from '../src/adapters/bidderFactory.js'; | ||
| import { deepAccess, deepClone } from '../src/utils.js'; | ||
| import { ajax } from '../src/ajax.js'; | ||
| import { BANNER, VIDEO } from '../src/mediaTypes.js'; | ||
| import type { BidRequest } from '../src/adapterManager.js'; | ||
| import type { Size } from '../src/types/common.d.ts'; | ||
|
|
||
| const BIDDER_CODE = 'asterio'; | ||
| export const ENDPOINT = 'https://bid.asterio.ai/prebid/bid'; | ||
|
|
||
| export type AsterioBidParams = { | ||
| adUnitToken: string; | ||
| pos?: number; | ||
| }; | ||
|
|
||
| declare module '../src/adUnits' { | ||
| interface BidderParams { | ||
| [BIDDER_CODE]: AsterioBidParams; | ||
| } | ||
| } | ||
|
|
||
| type AsterioBidPayload = { | ||
| bidId: string; | ||
| adUnitToken: string; | ||
| pos?: number; | ||
| sizes: Array<{ width: number; height: number }>; | ||
| }; | ||
|
|
||
| type AsterioServerBid = { | ||
| ad?: string; | ||
| requestId: string; | ||
| cpm: string | number; | ||
| currency?: string; | ||
| width: number; | ||
| height: number; | ||
| ttl: number; | ||
| creativeId: string; | ||
| netRevenue?: boolean; | ||
| mediaType?: string; | ||
| format?: string; | ||
| adomain?: string[]; | ||
| }; | ||
|
|
||
| export const spec: BidderSpec<typeof BIDDER_CODE> = { | ||
| code: BIDDER_CODE, | ||
| supportedMediaTypes: [BANNER, VIDEO], | ||
|
|
||
| isBidRequestValid: function (bid) { | ||
| return !!(bid.params && bid.params.adUnitToken); | ||
| }, | ||
|
|
||
| buildRequests: function (validBidRequests, bidderRequest) { | ||
| const bids: AsterioBidPayload[] = validBidRequests.map(bidRequest => ({ | ||
| bidId: bidRequest.bidId, | ||
| adUnitToken: bidRequest.params.adUnitToken, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please define or import type definitions on your bidder params, eg #14773
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adapter has been migrated to TypeScript |
||
| pos: getPosition(bidRequest), | ||
| sizes: prepareSizes(bidRequest.sizes) | ||
| })); | ||
|
|
||
| const payload: { | ||
| requestId: string; | ||
| bids: AsterioBidPayload[]; | ||
| referer: string; | ||
| schain: unknown; | ||
| gdprConsent?: { | ||
| consentRequired: boolean; | ||
| consentString?: string; | ||
| }; | ||
| } = { | ||
| requestId: bidderRequest.bidderRequestId, | ||
| bids, | ||
| referer: bidderRequest.refererInfo?.page, | ||
| schain: validBidRequests[0]?.ortb2?.source?.ext?.schain | ||
| }; | ||
|
|
||
| if (bidderRequest?.gdprConsent) { | ||
| payload.gdprConsent = { | ||
| consentRequired: typeof bidderRequest.gdprConsent.gdprApplies === 'boolean' ? bidderRequest.gdprConsent.gdprApplies : false, | ||
| consentString: bidderRequest.gdprConsent.consentString | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| method: 'POST', | ||
| url: ENDPOINT, | ||
| data: payload, | ||
| options: { | ||
| contentType: 'text/plain', | ||
| customHeaders: { | ||
| 'Rtb-Direct': 'true' | ||
| } | ||
| } | ||
| }; | ||
| }, | ||
|
|
||
| interpretResponse: function (serverResponse: ServerResponse, _request: AdapterRequest) { | ||
| const serverBody = serverResponse.body; | ||
| if (!serverBody || typeof serverBody !== 'object' || !Array.isArray(serverBody.bids)) { | ||
| return []; | ||
| } | ||
|
|
||
| return serverBody.bids.map((bidResponse: AsterioServerBid) => { | ||
| const bid = deepClone(bidResponse); | ||
|
|
||
| bid.cpm = parseFloat(String(bidResponse.cpm)); | ||
| bid.requestId = bidResponse.requestId; | ||
| bid.ad = bidResponse.ad; | ||
| bid.width = bidResponse.width; | ||
| bid.height = bidResponse.height; | ||
| bid.currency = bidResponse.currency || 'USD'; | ||
| bid.netRevenue = typeof bidResponse.netRevenue === 'boolean' ? bidResponse.netRevenue : true; | ||
| bid.ttl = bidResponse.ttl; | ||
| bid.creativeId = bidResponse.creativeId; | ||
| bid.mediaType = bidResponse.mediaType || bidResponse.format || 'banner'; | ||
|
|
||
| if (VIDEO === bid.mediaType && bidResponse.ad) { | ||
| bid.vastXml = bidResponse.ad; | ||
| } | ||
|
|
||
| bid.meta = {}; | ||
| bid.meta.advertiserDomains = bid.adomain || []; | ||
|
|
||
| return bid; | ||
| }); | ||
| }, | ||
|
|
||
| onBidWon: function (bid: { winUrl?: string; cpm: number }) { | ||
| if (bid.winUrl) { | ||
| const winUrl = bid.winUrl.replace(/\$\{AUCTION_PRICE}/, String(bid.cpm)); | ||
| ajax(winUrl, null, undefined, { keepalive: true }); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| function prepareSizes(sizes: Size | Size[]) { | ||
| if (!Array.isArray(sizes) || sizes.length === 0) { | ||
| return []; | ||
| } | ||
| const normalizedSizes = typeof sizes[0] === 'number' ? [sizes] : sizes; | ||
| return normalizedSizes.map(size => ({ width: size[0], height: size[1] })); | ||
| } | ||
|
|
||
| function getPosition(bidRequest: BidRequest<typeof BIDDER_CODE>): number | undefined { | ||
| return bidRequest.params.pos ?? deepAccess(bidRequest, 'mediaTypes.banner.pos') ?? deepAccess(bidRequest, 'mediaTypes.video.pos'); | ||
| } | ||
|
|
||
| registerBidder(spec); | ||
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.
The adapter implementation supports additional bidder params beyond
adUnitToken(e.g.,posand anendpointoverride), but the module docs only mentionadUnitToken. Please document the full set of supported params (required vs optional), and ifendpointoverride is intended only for testing, explicitly call that out to avoid production misconfiguration.