-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
RoundhouseAds Bid Adapter: Add new bidder adapter with tests #12400
Open
juliansalinas121
wants to merge
6
commits into
prebid:master
Choose a base branch
from
juliansalinas121:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+350
−1
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b8d6ec6
Add RoundhouseAds bidder adapter with tests
34239aa
Include all local changes before rebase
c681e57
Remove nested Git repository from Prebid.js
ec4d168
Add Prebid.js to .gitignore to avoid tracking as a sub-repo
4a7dd40
Finalized RoundhouseAds adapter build and bundling
3ae3d03
Remove Prebid.js from .gitignore
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 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 |
---|---|---|
|
@@ -80,3 +80,4 @@ typings/ | |
|
||
# MacOS system files | ||
.DS_Store | ||
Prebid.js/ | ||
This file contains 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
This file contains 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,127 @@ | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js'; | ||
|
||
/** | ||
* RoundhouseAds adapter configurations | ||
*/ | ||
|
||
const BIDDER_CODE = 'roundhouseads'; | ||
const BIDADAPTERVERSION = 'RHA-PREBID-2024.10.01'; | ||
const USER_SYNC_ENDPOINT = 'https://roundhouseads.com/sync'; | ||
|
||
const isLocalhost = typeof window !== 'undefined' && window.location.hostname === 'localhost'; | ||
const ENDPOINT_URL = isLocalhost | ||
? 'http://localhost:3000/bid' | ||
: 'https://Rhapbjsv3-env.eba-aqkfquti.us-east-1.elasticbeanstalk.com/bid'; | ||
|
||
/** | ||
* Validates a bid request for required parameters. | ||
* @param {Object} bid - The bid object from Prebid. | ||
* @returns {boolean} - True if the bid has required parameters, false otherwise. | ||
*/ | ||
function isBidRequestValid(bid) { | ||
return !!(bid.params && bid.params.publisherId && typeof bid.params.publisherId === 'string'); | ||
} | ||
|
||
/** | ||
* Constructs the bid request to send to the endpoint. | ||
* @param {Array} validBidRequests - Validated bid requests. | ||
* @param {Object} bidderRequest - Prebid's bidder request. | ||
* @returns {Array} - Array of request objects. | ||
*/ | ||
function buildRequests(validBidRequests, bidderRequest) { | ||
return validBidRequests.map(bid => { | ||
const data = { | ||
id: bid.bidId, | ||
publisherId: bid.params.publisherId, | ||
placementId: bid.params.placementId || '', | ||
currency: bid.params.currency || 'USD', | ||
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 support the openrtb location 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. This is not resolved |
||
referer: bidderRequest.refererInfo?.page, | ||
sizes: bid.mediaTypes?.banner?.sizes, | ||
video: bid.mediaTypes?.video || null, | ||
native: bid.mediaTypes?.native || null, | ||
ext: { | ||
ver: BIDADAPTERVERSION, | ||
} | ||
}; | ||
|
||
return { | ||
method: 'POST', | ||
url: ENDPOINT_URL, | ||
data, | ||
}; | ||
}); | ||
} | ||
|
||
/** | ||
* Interprets the server response for Prebid. | ||
* @param {Object} serverResponse - Server response from the bidder. | ||
* @param {Object} request - The original request. | ||
* @returns {Array} - Array of bid responses. | ||
*/ | ||
function interpretResponse(serverResponse, request) { | ||
juliansalinas121 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const bidResponses = []; | ||
const response = serverResponse.body; | ||
|
||
if (response && response.bids && Array.isArray(response.bids)) { | ||
response.bids.forEach(bid => { | ||
const bidResponse = { | ||
requestId: bid.requestId, | ||
cpm: bid.cpm || 0, | ||
width: bid.width || 300, | ||
height: bid.height || 250, | ||
creativeId: bid.creativeId || 'defaultCreative', | ||
currency: bid.currency || 'USD', | ||
netRevenue: true, | ||
ttl: bid.ttl || 360, | ||
ad: bid.ad || '<div>Test Ad</div>', | ||
mediaType: bid.mediaType || BANNER, | ||
}; | ||
|
||
if (bid.mediaType === VIDEO) { | ||
bidResponse.vastUrl = bid.vastUrl; | ||
} else if (bid.mediaType === NATIVE) { | ||
bidResponse.native = bid.native; | ||
} | ||
|
||
bidResponses.push(bidResponse); | ||
}); | ||
} | ||
|
||
return bidResponses; | ||
} | ||
|
||
/** | ||
* Provides user sync URL based on available sync options. | ||
* @param {Object} syncOptions - Sync options. | ||
* @param {Array} serverResponses - Server responses. | ||
* @param {Object} gdprConsent - GDPR consent data. | ||
* @param {string} uspConsent - USP consent data. | ||
* @returns {Array} - Array of user syncs. | ||
*/ | ||
function getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent) { | ||
const syncs = []; | ||
const gdprParams = gdprConsent | ||
? `&gdpr=${gdprConsent.gdprApplies ? 1 : 0}&gdpr_consent=${encodeURIComponent(gdprConsent.consentString)}` | ||
: ''; | ||
const uspParam = uspConsent ? `&us_privacy=${encodeURIComponent(uspConsent)}` : ''; | ||
|
||
if (syncOptions.iframeEnabled) { | ||
syncs.push({ type: 'iframe', url: `${USER_SYNC_ENDPOINT}?${gdprParams}${uspParam}` }); | ||
} else if (syncOptions.pixelEnabled) { | ||
syncs.push({ type: 'image', url: `${USER_SYNC_ENDPOINT}?${gdprParams}${uspParam}` }); | ||
} | ||
|
||
return syncs; | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER, VIDEO, NATIVE], | ||
isBidRequestValid, | ||
buildRequests, | ||
interpretResponse, | ||
getUserSyncs, | ||
}; | ||
|
||
registerBidder(spec); |
This file contains 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,153 @@ | ||
# RoundhouseAds Bidder Adapter | ||
|
||
## Overview | ||
|
||
- **Module Name**: RoundhouseAds Bidder Adapter | ||
- **Module Type**: Bidder Adapter | ||
- **Maintainer**: info@roundhouseads.com | ||
|
||
# Description | ||
|
||
Module that connects to RoundhouseAds' demand sources to fetch bids. | ||
|
||
The RoundhouseAds bid adapter supports Banner, Video, and Native ad formats. | ||
|
||
# Test Parameters | ||
|
||
```js | ||
var adUnits = [ | ||
// Banner adUnit with only required parameters | ||
{ | ||
code: 'test-div-banner-minimal', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]] | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'roundhouseads', | ||
params: { | ||
publisherId: 'your-publisher-id' | ||
} | ||
} | ||
] | ||
}, | ||
// Banner adUnit with all optional parameters provided | ||
{ | ||
code: 'test-div-banner-full', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[728, 90]] | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'roundhouseads', | ||
params: { | ||
publisherId: 'your-publisher-id', | ||
placementId: 'your-placement-id', | ||
bidfloor: 0.50, | ||
banner: { | ||
pos: 1 | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
// Native adUnit with only required parameters | ||
{ | ||
code: 'test-div-native-minimal', | ||
mediaTypes: { | ||
native: { | ||
title: { required: true, len: 80 }, | ||
image: { required: true, sizes: [150, 150] }, | ||
sponsoredBy: { required: true } | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'roundhouseads', | ||
params: { | ||
publisherId: 'your-publisher-id' | ||
} | ||
} | ||
] | ||
}, | ||
// Native adUnit with all optional parameters provided | ||
{ | ||
code: 'test-div-native-full', | ||
mediaTypes: { | ||
native: { | ||
title: { required: true, len: 80 }, | ||
body: { required: true, len: 200 }, | ||
image: { required: true, sizes: [300, 250] }, | ||
icon: { required: false, sizes: [50, 50] }, | ||
sponsoredBy: { required: true }, | ||
clickUrl: { required: true } | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'roundhouseads', | ||
params: { | ||
publisherId: 'your-publisher-id', | ||
placementId: 'your-placement-id', | ||
native: { | ||
language: 'en' | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
// Video adUnit with only required parameters | ||
{ | ||
code: 'test-div-video-minimal', | ||
mediaTypes: { | ||
video: { | ||
context: 'instream', | ||
playerSize: [640, 480], | ||
mimes: ['video/mp4'], | ||
protocols: [2, 3, 5, 6] | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'roundhouseads', | ||
params: { | ||
publisherId: 'your-publisher-id' | ||
} | ||
} | ||
] | ||
}, | ||
// Video adUnit with all optional parameters provided | ||
{ | ||
code: 'test-div-video-full', | ||
mediaTypes: { | ||
video: { | ||
minduration: 1, | ||
maxduration: 60, | ||
playerSize: [640, 480], | ||
api: [1, 2], | ||
mimes: ['video/mp4'], | ||
protocols: [2, 3, 5, 6], | ||
skip: 1, | ||
skipmin: 5, | ||
skipafter: 15 | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'roundhouseads', | ||
params: { | ||
publisherId: 'your-publisher-id', | ||
placementId: 'your-placement-id', | ||
bidfloor: 0.75, | ||
video: { | ||
language: 'en' | ||
} | ||
} | ||
} | ||
] | ||
} | ||
]; |
This file contains 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,80 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/roundhouseadsBidAdapter.js'; | ||
|
||
describe('RoundhouseAdsAdapter', function () { | ||
function makeBid() { | ||
return { | ||
bidder: 'roundhouseads', | ||
params: { | ||
placementId: 'testPlacement', | ||
publisherId: '123456', | ||
}, | ||
mediaTypes: { | ||
banner: { sizes: [[300, 250], [728, 90]] }, | ||
}, | ||
adUnitCode: 'adunit-code', | ||
bidId: 'bid123', | ||
bidderRequestId: 'request123', | ||
auctionId: 'auction123', | ||
}; | ||
} | ||
|
||
describe('isBidRequestValid', function () { | ||
it('should return true when required params are found', function () { | ||
const bid = makeBid(); | ||
expect(spec.isBidRequestValid(bid)).to.equal(true); | ||
}); | ||
|
||
it('should return false when publisherId is missing', function () { | ||
const bid = makeBid(); | ||
delete bid.params.publisherId; | ||
expect(spec.isBidRequestValid(bid)).to.equal(false); | ||
}); | ||
}); | ||
|
||
describe('buildRequests', function () { | ||
it('should build a request with correct data', function () { | ||
const bidRequests = [makeBid()]; | ||
const bidderRequest = { refererInfo: { page: 'http://example.com' } }; | ||
const request = spec.buildRequests(bidRequests, bidderRequest); | ||
expect(request[0].url).to.equal('http://localhost:3000/bid'); | ||
expect(request[0].data.publisherId).to.equal('123456'); | ||
expect(request[0].data.placementId).to.equal('testPlacement'); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', function () { | ||
it('should interpret the server response correctly', function () { | ||
const serverResponse = { | ||
body: { | ||
bids: [ | ||
{ | ||
requestId: 'bid123', | ||
cpm: 1.0, | ||
width: 300, | ||
height: 250, | ||
creativeId: 'creative123', | ||
currency: 'USD', | ||
ttl: 360, | ||
ad: '<div>Test Ad</div>', | ||
}, | ||
], | ||
}, | ||
}; | ||
const request = { data: { id: 'bid123' } }; | ||
const result = spec.interpretResponse(serverResponse, request); | ||
expect(result[0].requestId).to.equal('bid123'); | ||
expect(result[0].cpm).to.equal(1.0); | ||
expect(result[0].ad).to.equal('<div>Test Ad</div>'); | ||
}); | ||
}); | ||
|
||
describe('getUserSyncs', function () { | ||
it('should return user sync iframe if iframeEnabled', function () { | ||
const syncOptions = { iframeEnabled: true }; | ||
const result = spec.getUserSyncs(syncOptions); | ||
expect(result[0].type).to.equal('iframe'); | ||
expect(result[0].url).to.contain('https://roundhouseads.com/sync'); | ||
}); | ||
}); | ||
}); |
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.
Please remove this change and your change to the creative