-
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
AdGrid Bid Adapter : initial release #12152
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import { _each, isEmpty, deepAccess } from '../src/utils.js'; | ||
import { config } from '../src/config.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { BANNER } from '../src/mediaTypes.js'; | ||
|
||
const BIDDER = Object.freeze({ | ||
CODE: 'adgrid', | ||
HOST: 'https://api-prebid.adgrid.io', | ||
REQUEST_METHOD: 'POST', | ||
REQUEST_ENDPOINT: '/api/v1/auction', | ||
SUPPORTED_MEDIA_TYPES: [BANNER], | ||
}); | ||
|
||
const CURRENCY = Object.freeze({ | ||
KEY: 'currency', | ||
US_DOLLAR: 'USD', | ||
}); | ||
|
||
function isBidRequestValid(bid) { | ||
if (!bid || !bid.params) { | ||
return false; | ||
} | ||
|
||
return !!bid.params.domainId; | ||
} | ||
|
||
/** | ||
* Return some extra params | ||
*/ | ||
function getAudience(validBidRequests, bidderRequest) { | ||
const params = { | ||
domain: deepAccess(bidderRequest, 'refererInfo.page') | ||
}; | ||
|
||
if (config.getConfig('coppa') === true) { | ||
params.coppa = 1; | ||
} | ||
|
||
if (deepAccess(bidderRequest, 'gdprConsent.gdprApplies')) { | ||
params.gdpr = 1; | ||
params.gdprConsent = deepAccess(bidderRequest, 'gdprConsent.consentString'); | ||
} | ||
|
||
if (deepAccess(bidderRequest, 'uspConsent')) { | ||
params.usp = deepAccess(bidderRequest, 'uspConsent'); | ||
} | ||
|
||
if (deepAccess(validBidRequests[0], 'schain')) { | ||
params.schain = deepAccess(validBidRequests[0], 'schain'); | ||
} | ||
|
||
if (deepAccess(validBidRequests[0], 'userId')) { | ||
params.userIds = deepAccess(validBidRequests[0], 'userId'); | ||
} | ||
|
||
if (deepAccess(validBidRequests[0], 'userIdAsEids')) { | ||
params.userEids = deepAccess(validBidRequests[0], 'userIdAsEids'); | ||
} | ||
|
||
if (bidderRequest.gppConsent) { | ||
params.gpp = bidderRequest.gppConsent.gppString; | ||
params.gppSid = bidderRequest.gppConsent.applicableSections?.toString(); | ||
} else if (bidderRequest.ortb2?.regs?.gpp) { | ||
params.gpp = bidderRequest.ortb2.regs.gpp; | ||
params.gppSid = bidderRequest.ortb2.regs.gpp_sid; | ||
} | ||
|
||
return params; | ||
} | ||
|
||
function buildRequests(validBidRequests, bidderRequest) { | ||
const currencyObj = config.getConfig(CURRENCY.KEY); | ||
const currency = (currencyObj && currencyObj.adServerCurrency) ? currencyObj.adServerCurrency : 'USD'; | ||
const bids = []; | ||
|
||
_each(validBidRequests, bid => { | ||
bids.push(getBidData(bid)) | ||
}); | ||
|
||
const bidsParams = Object.assign({}, { | ||
url: window.location.href, | ||
timeout: bidderRequest.timeout, | ||
ts: new Date().getTime(), | ||
device: { | ||
size: [ | ||
window.screen.width, | ||
window.screen.height | ||
] | ||
}, | ||
bids | ||
}); | ||
|
||
// Add currency if not USD | ||
if (currency != null && currency != CURRENCY.US_DOLLAR) { | ||
bidsParams.cur = currency; | ||
} | ||
|
||
bidsParams.audience = getAudience(validBidRequests, bidderRequest); | ||
|
||
// Passing geo location data if found in prebid config | ||
bidsParams.geodata = config.getConfig('adgGeodata') || {}; | ||
|
||
return Object.assign({}, bidderRequest, { | ||
method: BIDDER.REQUEST_METHOD, | ||
url: `${BIDDER.HOST}${BIDDER.REQUEST_ENDPOINT}`, | ||
data: bidsParams, | ||
currency: currency, | ||
options: { | ||
withCredentials: false, | ||
contentType: 'application/json' | ||
} | ||
}); | ||
} | ||
|
||
function interpretResponse(response, bidRequest) { | ||
let bids = response.body; | ||
const bidResponses = []; | ||
|
||
if (isEmpty(bids)) { | ||
return bidResponses; | ||
} | ||
|
||
if (typeof bids !== 'object') { | ||
return bidResponses; | ||
} | ||
|
||
bids = bids.bids; | ||
|
||
bids.forEach((adUnit) => { | ||
const bidResponse = { | ||
requestId: adUnit.bidId, | ||
cpm: Number(adUnit.cpm), | ||
width: adUnit.width, | ||
height: adUnit.height, | ||
ttl: 300, | ||
creativeId: adUnit.creativeId, | ||
netRevenue: true, | ||
currency: adUnit.currency || bidRequest.currency, | ||
mediaType: adUnit.mediaType, | ||
ad: adUnit.ad, | ||
}; | ||
|
||
bidResponses.push(bidResponse); | ||
}); | ||
|
||
return bidResponses; | ||
} | ||
|
||
function getBidData(bid) { | ||
const bidData = { | ||
requestId: bid.bidId, | ||
tid: bid.ortb2Imp?.ext?.tid, | ||
deviceW: bid.ortb2?.device?.w, | ||
deviceH: bid.ortb2?.device?.h, | ||
deviceUa: bid.ortb2?.device?.ua, | ||
domain: bid.ortb2?.site?.publisher?.domain, | ||
domainId: bid.params.domainId, | ||
code: bid.adUnitCode | ||
}; | ||
|
||
if (bid.mediaTypes != null) { | ||
if (bid.mediaTypes.banner != null) { | ||
bidData.mediaType = 'banner'; | ||
bidData.sizes = bid.mediaTypes.banner.sizes; | ||
} | ||
} | ||
|
||
return bidData; | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER.CODE, | ||
isBidRequestValid, | ||
buildRequests, | ||
interpretResponse, | ||
supportedMediaTypes: BIDDER.SUPPORTED_MEDIA_TYPES | ||
}; | ||
|
||
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,45 @@ | ||
# Overview | ||
|
||
**Module Name**: AdGrid Bidder Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: support@adgrid.io | ||
|
||
# Description | ||
|
||
The AdGrid Bidding Adapter requires setup and approval before beginning. Please reach out to <support@adgrid.io> for more details. | ||
|
||
# Test Parameters | ||
|
||
```javascript | ||
var adUnits = [ | ||
// Banner adUnit | ||
{ | ||
code: 'test-div-1', | ||
mediaTypes:{ | ||
banner:{ | ||
sizes: [[300, 250]] | ||
} | ||
} | ||
bids: [{ | ||
bidder: 'adgrid', | ||
params: { | ||
domainId: 12345 | ||
} | ||
}] | ||
}, | ||
{ | ||
code: 'test-div-2', | ||
mediaTypes:{ | ||
banner:{ | ||
sizes: [[728, 90], [320, 50]] | ||
} | ||
} | ||
bids: [{ | ||
bidder: 'adgrid', | ||
params: { | ||
domainId: 67890 | ||
} | ||
}] | ||
} | ||
]; | ||
``` |
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,100 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from '../../../modules/adgridBidAdapter.js' | ||
|
||
const globalConfig = { | ||
method: 'POST', | ||
endPoint: 'https://api-prebid.adgrid.io/api/v1/auction' | ||
}; | ||
|
||
describe('AdGrid Bid Adapter', function () { | ||
const bannerRequest = [{ | ||
bidId: 123456, | ||
auctionId: 98765, | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]], | ||
} | ||
}, | ||
params: { | ||
domainId: 12345 | ||
} | ||
}]; | ||
|
||
describe('isBidRequestValid', function () { | ||
it('Should return true when domainId exist inside params object', function () { | ||
const isBidValid = spec.isBidRequestValid(bannerRequest[0]); | ||
expect(isBidValid).to.be.true; | ||
}); | ||
|
||
it('Should return false when domainId is not exist inside params object', function () { | ||
const isBidNotValid = spec.isBidRequestValid(null); | ||
expect(isBidNotValid).to.be.false; | ||
}); | ||
}); | ||
|
||
describe('buildRequests', function () { | ||
const request = spec.buildRequests(bannerRequest, bannerRequest[0]); | ||
const payload = request.data; | ||
const apiURL = request.url; | ||
const method = request.method; | ||
|
||
it('Test the request is not empty', function () { | ||
expect(request).to.not.be.empty; | ||
}); | ||
|
||
it('Test the request payload is not empty', function () { | ||
expect(payload).to.not.be.empty; | ||
}); | ||
|
||
it('Test the API End Point', function () { | ||
expect(apiURL).to.equal(globalConfig.endPoint); | ||
}); | ||
|
||
it('Test the API Method', function () { | ||
expect(method).to.equal(globalConfig.method); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', function () { | ||
const responseObj = { | ||
bids: [ | ||
{ | ||
bidId: '4b99f3428651c1', | ||
cpm: 7.7, | ||
ad: '<div>Ad Content</div>', | ||
creativeId: '9004', | ||
currency: 'USD', | ||
mediaType: 'banner', | ||
width: 320, | ||
height: 50, | ||
domainId: '2002', | ||
marketplaceId: '703', | ||
devices: 'desktop' | ||
} | ||
] | ||
}; | ||
|
||
it('Test the interpretResponse function', function () { | ||
const receivedBid = responseObj.bids[0]; | ||
const response = {}; | ||
response.body = responseObj; | ||
|
||
const bidRequest = {}; | ||
bidRequest.currency = 'USD'; | ||
|
||
const bidResponse = spec.interpretResponse(response, bidRequest); | ||
expect(bidResponse).to.not.be.empty; | ||
|
||
const bid = bidResponse[0]; | ||
expect(bid).to.not.be.empty; | ||
expect(bid.requestId).to.equal(receivedBid.bidId); | ||
expect(bid.ad).to.equal(receivedBid.ad); | ||
expect(bid.cpm).to.equal(receivedBid.cpm); | ||
expect(bid.mediaType).to.equal(receivedBid.mediaType); | ||
expect(bid.creativeId).to.equal(receivedBid.creativeId); | ||
expect(bid.width).to.equal(receivedBid.width); | ||
expect(bid.height).to.equal(receivedBid.height); | ||
expect(bid.currency).to.equal(receivedBid.currency); | ||
}); | ||
}); | ||
}); |
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.
Can you please get coppa from
bidderRequest.ortb2.regs
instead ?