-
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
Gnet Bid Adapter: add new bid adapter #6536
Changes from 3 commits
6aee892
b45d8c0
8d7ec76
0c10d58
65596b0
4c0ae2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import * as utils from '../src/utils.js'; | ||
import { BANNER } from '../src/mediaTypes.js'; | ||
|
||
const BIDDER_CODE = 'gnet'; | ||
const ENDPOINT = 'https://grumft.cbykmedia.com/prebid/prebid.php'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
|
||
/** | ||
* Determines whether or not the given bid request is valid. | ||
* | ||
* @param {BidRequest} bid The bid params to validate. | ||
* @return boolean True if this is a valid bid, and false otherwise. | ||
*/ | ||
isBidRequestValid: function (bid) { | ||
return !!(bid.params.websiteId && bid.params.externalId); | ||
}, | ||
|
||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param {validBidRequests[]} - an array of bids | ||
* @return ServerRequest Info describing the request to the server. | ||
*/ | ||
buildRequests: function (validBidRequests, bidderRequest) { | ||
const bidRequests = []; | ||
const referer = bidderRequest.refererInfo.referer; | ||
|
||
utils._each(validBidRequests, (request) => { | ||
const data = Object(); | ||
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. Any reason to not just init using saves a couple chars for the built package. 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. Done! |
||
|
||
data.referer = referer; | ||
data.adUnitCode = request.adUnitCode; | ||
data.bidId = request.bidId; | ||
data.transactionId = request.transactionId; | ||
|
||
data.sizes = []; | ||
utils._each(request.sizes, (size) => { | ||
data.sizes.push(size[0] + 'x' + size[1]); | ||
}); | ||
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. there is a util function which I believe does this for you if you want to use it.
It is recommended to look into the mediaType.banner.sizes instead of the top level We did "deprecate" top level sizes on adUnits, but maintained it for use for bid adapters. So, it is just a recommendation if you do not wish to use it. 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. Nice! I'll change it.. Thanks! |
||
|
||
data.params = request.params; | ||
|
||
const payloadString = JSON.stringify(data); | ||
|
||
bidRequests.push({ | ||
method: 'POST', | ||
url: ENDPOINT, | ||
mode: 'no-cors', | ||
options: { | ||
withCredentials: false, | ||
}, | ||
data: payloadString | ||
}); | ||
}); | ||
|
||
return bidRequests; | ||
}, | ||
|
||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {*} serverResponse A successful response from the server. | ||
* @return {Bid[]} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: function (serverResponse, requests) { | ||
if (!serverResponse.body) { | ||
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. might be wise to handle case where So we do not throw an exception here? 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. Done! |
||
return []; | ||
} | ||
|
||
const res = serverResponse.body; | ||
|
||
if (utils.isEmpty(res)) { | ||
return []; | ||
} | ||
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. Probably best to combine these two into one check. const res = serverResponse && serverResponse.body;
if (utils.isEmpty(res)) {
return [];
} |
||
|
||
const bids = []; | ||
utils._each(res.bids, (bidData) => { | ||
const bid = { | ||
requestId: bidData.bidId, | ||
cpm: bidData.cpm, | ||
currency: bidData.currency, | ||
width: bidData.width, | ||
height: bidData.height, | ||
ad: bidData.ad, | ||
ttl: 300, | ||
creativeId: bidData.creativeId, | ||
netRevenue: true, | ||
}; | ||
bids.push(bid); | ||
}); | ||
|
||
return bids; | ||
}, | ||
|
||
/** | ||
* Register the user sync pixels which should be dropped after the auction. | ||
* | ||
* @param {SyncOptions} syncOptions Which user syncs are allowed? | ||
* @param {ServerResponse[]} serverResponses List of server's responses. | ||
* @return {UserSync[]} The user syncs which should be dropped. | ||
*/ | ||
getUserSyncs: function(syncOptions, serverResponses) { | ||
return []; | ||
}, | ||
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. If you are not going to run any user syncs, you can probably just remove this code. |
||
}; | ||
|
||
registerBidder(spec); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Gnet Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: roberto.wu@grumft.com | ||
``` | ||
|
||
# Description | ||
|
||
Module that connects to Example's demand sources | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: '/150790500/4_ZONA_IAB_300x250_5', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]], | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'gnet', | ||
params: { | ||
websiteId: '4', | ||
externalId: '4d52cccf30309282256012cf30309282' | ||
} | ||
} | ||
] | ||
} | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import { | ||
expect | ||
} from 'chai'; | ||
import { | ||
spec | ||
} from 'modules/gnetBidAdapter.js'; | ||
import { | ||
newBidder | ||
} from 'src/adapters/bidderFactory.js'; | ||
|
||
const ENDPOINT = 'https://grumft.cbykmedia.com/prebid/prebid.php'; | ||
|
||
describe('gnetAdapter', function () { | ||
const adapter = newBidder(spec); | ||
|
||
describe('inherited functions', function () { | ||
it('exists and is a function', function () { | ||
expect(adapter.callBids).to.exist.and.to.be.a('function'); | ||
}); | ||
}); | ||
|
||
describe('isBidRequestValid', function () { | ||
let bid = { | ||
bidder: 'gnet', | ||
params: { | ||
websiteId: '4', | ||
externalId: '4d52cccf30309282256012cf30309282' | ||
} | ||
}; | ||
|
||
it('should return true when required params found', function () { | ||
expect(spec.isBidRequestValid(bid)).to.equal(true); | ||
}); | ||
|
||
it('should return false when required params are not passed', function () { | ||
let bid = Object.assign({}, bid); | ||
delete bid.params; | ||
bid.params = {}; | ||
expect(spec.isBidRequestValid(bid)).to.equal(false); | ||
}); | ||
}); | ||
|
||
describe('buildRequests', function () { | ||
const bidRequests = [{ | ||
bidder: 'gnet', | ||
params: { | ||
websiteId: '4', | ||
externalId: '4d52cccf30309282256012cf30309282' | ||
}, | ||
adUnitCode: '/150790500/4_ZONA_IAB_300x250_5', | ||
sizes: [ | ||
[300, 250], | ||
], | ||
bidId: '2a19afd5173318', | ||
bidderRequestId: '1f4001782ac16c', | ||
auctionId: 'aba03555-4802-4c45-9f15-05ffa8594cff', | ||
transactionId: '894bdff6-61ec-4bec-a5a9-f36a5bfccef5' | ||
}]; | ||
|
||
const bidderRequest = { | ||
refererInfo: { | ||
referer: 'https://gnetproject.com/' | ||
} | ||
}; | ||
|
||
it('sends bid request to ENDPOINT via POST', function () { | ||
const requests = spec.buildRequests(bidRequests, bidderRequest); | ||
expect(requests[0].url).to.equal(ENDPOINT); | ||
expect(requests[0].method).to.equal('POST'); | ||
expect(requests[0].data).to.equal(JSON.stringify({ | ||
'referer': 'https://gnetproject.com/', | ||
'adUnitCode': '/150790500/4_ZONA_IAB_300x250_5', | ||
'bidId': '2a19afd5173318', | ||
'transactionId': '894bdff6-61ec-4bec-a5a9-f36a5bfccef5', | ||
'sizes': ['300x250'], | ||
'params': { | ||
'websiteId': '4', | ||
'externalId': '4d52cccf30309282256012cf30309282' | ||
} | ||
})); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', function () { | ||
const bidderRequests = [{ | ||
bidder: 'gnet', | ||
params: { | ||
clientId: '123456' | ||
}, | ||
adUnitCode: '/150790500/4_ZONA_IAB_300x250_5', | ||
sizes: [ | ||
[300, 250], | ||
], | ||
bidId: '2a19afd5173318', | ||
bidderRequestId: '1f4001782ac16c', | ||
auctionId: 'aba03555-4802-4c45-9f15-05ffa8594cff', | ||
transactionId: '894bdff6-61ec-4bec-a5a9-f36a5bfccef5' | ||
}]; | ||
|
||
it('should get correct banner bid response', function () { | ||
const response = { | ||
bids: [ | ||
{ | ||
bidId: '2a19afd5173318', | ||
cpm: 0.1, | ||
currency: 'BRL', | ||
width: 300, | ||
height: 250, | ||
ad: '<html><h3>I am an ad</h3></html>', | ||
creativeId: '173560700', | ||
} | ||
] | ||
}; | ||
|
||
const expectedResponse = [ | ||
{ | ||
requestId: '2a19afd5173318', | ||
cpm: 0.1, | ||
currency: 'BRL', | ||
width: 300, | ||
height: 250, | ||
ad: '<html><h3>I am an ad</h3></html>', | ||
ttl: 300, | ||
creativeId: '173560700', | ||
netRevenue: true | ||
} | ||
]; | ||
|
||
const result = spec.interpretResponse({ | ||
body: response | ||
}, bidderRequests); | ||
expect(result).to.have.lengthOf(1); | ||
expect(result).to.deep.have.same.members(expectedResponse); | ||
}); | ||
|
||
it('handles nobid responses', function () { | ||
const response = ''; | ||
|
||
const result = spec.interpretResponse({ | ||
body: response | ||
}, bidderRequests); | ||
expect(result.length).to.equal(0); | ||
}); | ||
}); | ||
}); |
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.
Does gnet have a registered GVL ID?
If so, it is recommended to add it to your spec so it functions accordingly in GDPR scenarios.
See https://github.com/prebid/Prebid.js/blob/master/modules/rubiconBidAdapter.js#L114 as an example
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.
No, we don't have a GVL ID yet