-
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
New Adapter: bidglass #3861
Merged
Merged
New Adapter: bidglass #3861
Changes from all commits
Commits
Show all changes
3 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,134 @@ | ||
import * as utils from 'src/utils'; | ||
// import {config} from 'src/config'; | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'bidglass'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
aliases: ['bg'], // short code | ||
/** | ||
* 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.adUnitId && !isNaN(parseFloat(bid.params.adUnitId)) && isFinite(bid.params.adUnitId)); | ||
}, | ||
/** | ||
* 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) { | ||
/* | ||
Sample array entry for validBidRequests[]: | ||
[{ | ||
"bidder": "bidglass", | ||
"bidId": "51ef8751f9aead", | ||
"params": { | ||
"adUnitId": 11, | ||
... | ||
}, | ||
"adUnitCode": "div-gpt-ad-1460505748561-0", | ||
"transactionId": "d7b773de-ceaa-484d-89ca-d9f51b8d61ec", | ||
"sizes": [[320,50],[300,250],[300,600]], | ||
"bidderRequestId": "418b37f85e772c", | ||
"auctionId": "18fd8b8b0bd757", | ||
"bidRequestsCount": 1 | ||
}] | ||
*/ | ||
|
||
let imps = []; | ||
let getReferer = function() { | ||
return window === window.top ? window.location.href : window.parent === window.top ? document.referrer : null; | ||
}; | ||
let getOrigins = function() { | ||
var ori = [window.location.protocol + '//' + window.location.hostname]; | ||
|
||
if (window.location.ancestorOrigins) { | ||
for (var i = 0; i < window.location.ancestorOrigins.length; i++) { | ||
ori.push(window.location.ancestorOrigins[i]); | ||
} | ||
} else if (window !== window.top) { | ||
// Derive the parent origin | ||
var parts = document.referrer.split('/'); | ||
|
||
ori.push(parts[0] + '//' + parts[2]); | ||
|
||
if (window.parent !== window.top) { | ||
// Additional unknown origins exist | ||
ori.push('null'); | ||
} | ||
} | ||
|
||
return ori; | ||
}; | ||
|
||
utils._each(validBidRequests, function(bid) { | ||
bid.sizes = ((utils.isArray(bid.sizes) && utils.isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes]); | ||
bid.sizes = bid.sizes.filter(size => utils.isArray(size)); | ||
|
||
// Stuff to send: [bid id, sizes, adUnitId] | ||
imps.push({ | ||
bidId: bid.bidId, | ||
sizes: bid.sizes, | ||
adUnitId: utils.getBidIdParameter('adUnitId', bid.params) | ||
}); | ||
}); | ||
|
||
// Stuff to send: page URL | ||
const bidReq = { | ||
reqId: utils.getUniqueIdentifierStr(), | ||
imps: imps, | ||
ref: getReferer(), | ||
ori: getOrigins() | ||
}; | ||
|
||
let url = 'https://bid.glass/ad/hb.php?' + | ||
`src=$$REPO_AND_VERSION$$`; | ||
|
||
return { | ||
method: 'POST', | ||
url: url, | ||
data: JSON.stringify(bidReq), | ||
options: { | ||
contentType: 'text/plain', | ||
withCredentials: false | ||
} | ||
} | ||
}, | ||
|
||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {ServerResponse} serverResponse A successful response from the server. | ||
* @return {Bid[]} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: function(serverResponse) { | ||
const bidResponses = []; | ||
|
||
utils._each(serverResponse.body.bidResponses, function(bid) { | ||
bidResponses.push({ | ||
requestId: bid.requestId, | ||
cpm: parseFloat(bid.cpm), | ||
width: parseInt(bid.width, 10), | ||
height: parseInt(bid.height, 10), | ||
creativeId: bid.creativeId, | ||
dealId: bid.dealId || null, | ||
currency: bid.currency || 'USD', | ||
mediaType: bid.mediaType || 'banner', | ||
netRevenue: true, | ||
ttl: bid.ttl || 10, | ||
ad: bid.ad | ||
}); | ||
}); | ||
|
||
return bidResponses; | ||
} | ||
|
||
} | ||
|
||
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,34 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Bid Glass Bid Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: dliebner@gmail.com | ||
``` | ||
|
||
# Description | ||
|
||
Connects to Bid Glass and allows bids on ad units to compete within prebid. | ||
|
||
# Sample Ad Unit: For Publishers | ||
``` | ||
var adUnits = [{ | ||
code: 'bg-test-rectangle', | ||
sizes: [[300, 250]], | ||
bids: [{ | ||
bidder: 'bidglass', | ||
params: { | ||
adUnitId: '-1' | ||
} | ||
}] | ||
},{ | ||
code: 'bg-test-leaderboard', | ||
sizes: [[728, 90]], | ||
bids: [{ | ||
bidder: 'bidglass', | ||
params: { | ||
adUnitId: '-1' | ||
} | ||
}] | ||
}] | ||
``` |
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,103 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/bidglassBidAdapter'; | ||
import { newBidder } from 'src/adapters/bidderFactory'; | ||
|
||
describe('Bid Glass Adapter', function () { | ||
const adapter = newBidder(spec); | ||
|
||
describe('isBidRequestValid', function () { | ||
let bid = { | ||
'bidder': 'bidglass', | ||
'params': { | ||
'adUnitId': '3' | ||
}, | ||
'adUnitCode': 'bidglass-testunit', | ||
'sizes': [[300, 250], [300, 600]], | ||
'bidId': '30b31c1838de1e', | ||
'bidderRequestId': '22edbae2733bf6', | ||
'auctionId': '1d1a030790a475', | ||
}; | ||
|
||
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': 'bidglass', | ||
'params': { | ||
'adUnitId': '3' | ||
}, | ||
'adUnitCode': 'bidglass-testunit', | ||
'sizes': [[300, 250], [300, 600]], | ||
'bidId': '30b31c1838de1e', | ||
'bidderRequestId': '22edbae2733bf6', | ||
'auctionId': '1d1a030790a475', | ||
}]; | ||
|
||
const request = spec.buildRequests(bidRequests); | ||
|
||
it('sends bid request to our endpoint via POST', function () { | ||
expect(request.method).to.equal('POST'); | ||
}); | ||
|
||
it('sets withCredentials to false', function () { | ||
expect(request.options.withCredentials).to.equal(false); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', function () { | ||
let response; | ||
beforeEach(function () { | ||
response = { | ||
body: { | ||
'bidResponses': [{ | ||
'ad': '<!-- Creative -->', | ||
'cpm': '0.01', | ||
'creativeId': '-1', | ||
'width': '300', | ||
'height': '250', | ||
'requestId': '30b31c1838de1e' | ||
}] | ||
} | ||
}; | ||
}); | ||
|
||
it('should get the correct bid response', function () { | ||
let expectedResponse = [{ | ||
'requestId': '30b31c1838de1e', | ||
'cpm': 0.01, | ||
'width': 300, | ||
'height': 250, | ||
'creativeId': '-1', | ||
'dealId': null, | ||
'currency': 'USD', | ||
'mediaType': 'banner', | ||
'netRevenue': true, | ||
'ttl': 10, | ||
'ad': '<!-- Creative -->' | ||
}]; | ||
|
||
let result = spec.interpretResponse(response); | ||
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); | ||
}); | ||
|
||
it('handles empty bid response', function () { | ||
let response = { | ||
body: { | ||
'bidResponses': [] | ||
} | ||
}; | ||
let result = spec.interpretResponse(response); | ||
expect(result.length).to.equal(0); | ||
}); | ||
}); | ||
}); |
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.
We already pass this information in bidderRequest. Check http://prebid.org/dev-docs/bidder-adaptor.html#referrers
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.
Our rules for determining and reporting referer and origins vary slightly from prebid's built-in methods. We'd prefer to use our own methods for consistency's sake across our platform.