-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add bucksense Adapter #3785
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
Add bucksense Adapter #3785
Changes from 2 commits
9421e12
317d082
fc1d4e4
48e4ccb
236bd35
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,171 @@ | ||
import { registerBidder } from 'src/adapters/bidderFactory'; | ||
import { BANNER } from 'src/mediaTypes'; | ||
|
||
const WHOIS = 'BKSHBID-008'; | ||
const BIDDER_CODE = 'bucksense'; | ||
const URL = 'https://prebid.bksn.se:445/prebid'; | ||
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. Is this the correct endpoint URL for your adapter? When I tried to test the adapter, the POST requests to this URL were resulting in a 301 Moved Permanently response. 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. Yes request is doing a 301 but then got redirect to the script that return the BID. I have tested the prebid on the Hello World example. Let me know if you do not see the response at all from your test. |
||
var bksdebug = false; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
|
||
/** | ||
* Determines whether or not the given bid request is valid. | ||
* | ||
* @param {object} bid The bid to validate. | ||
* @return boolean True if this is a valid bid, and false otherwise. | ||
*/ | ||
isBidRequestValid: function (bid) { | ||
if (isNaN(bid)) { | ||
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. The Can you review this logic and adjust it accordingly? 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. fixed with new Push |
||
return false; | ||
} | ||
if (bid.params.debug) { | ||
bksdebug = bid.params.debug; | ||
} | ||
if (bksdebug) console.log(WHOIS + ' isBidRequestValid() - INPUT bid:', bid); | ||
return Boolean(bid.bidId && bid.params && !isNaN(bid.params.placementId)); | ||
}, | ||
|
||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param {BidRequest[]} validBidRequests A non-empty list of valid bid requests that should be sent to the Server. | ||
* @return ServerRequest Info describing the request to the server. | ||
*/ | ||
buildRequests: function (validBidRequests, bidderRequest) { | ||
if (bksdebug) console.log(WHOIS + ' buildRequests() - INPUT validBidRequests:', validBidRequests, 'INPUT bidderRequest:', bidderRequest); | ||
let requests = []; | ||
|
||
const len = validBidRequests.length; | ||
for (let i = 0; i < len; i++) { | ||
var bid = validBidRequests[i]; | ||
|
||
requests.push({ | ||
method: 'POST', | ||
url: URL, | ||
data: { | ||
'pub_id': location.host, | ||
'pl_id': bid.params.placementId, | ||
'sys_href': encodeURI(location.href), | ||
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 haven't already looked at it, there are a set of data points you can use in your adapter to get information on the webpage loading the adapter. Please see the link below and consider using them if they would fit your needs: 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. Thanks for point to this but in this release we would like to keep using the location object if it is not a problem |
||
'sys_bid_id': bid.bidId, | ||
'test_cpm': bid.params.testcpm | ||
} | ||
}) | ||
} | ||
if (bksdebug) console.log(WHOIS + ' buildRequests() - requests:', requests); | ||
return requests; | ||
}, | ||
|
||
/** | ||
* 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, request) { | ||
if (bksdebug) console.log(WHOIS + ' interpretResponse() - INPUT serverResponse:', serverResponse, 'INPUT request:', request); | ||
|
||
const bidResponses = []; | ||
|
||
if (serverResponse.body) { | ||
var oResponse = serverResponse.body; | ||
|
||
var sRequestID = oResponse.requestId || ''; | ||
var nCPM = oResponse.cpm || 0; | ||
var nWidth = oResponse.width || 0; | ||
var nHeight = oResponse.height || 0; | ||
var nTTL = oResponse.ttl || 0; | ||
var sCreativeID = oResponse.creativeId || 0; | ||
var sCurrency = oResponse.currency || 'USD'; | ||
var bNetRevenue = oResponse.netRevenue || true; | ||
var sAd = oResponse.ad || ''; | ||
|
||
if (sRequestID.length == 0 && !isNaN(request)) { | ||
if (bksdebug) console.log(WHOIS + ' interpretResponse() - use RequestID from Placments'); | ||
sRequestID = request.data.sys_bid_id || ''; | ||
} | ||
|
||
if (!isNaN(request) && request.data.test_cpm > 0) { | ||
if (bksdebug) console.log(WHOIS + ' interpretResponse() - use Test CPM '); | ||
nCPM = request.data.test_cpm; | ||
} | ||
|
||
let bidResponse = { | ||
requestId: sRequestID, | ||
cpm: nCPM, | ||
width: nWidth, | ||
height: nHeight, | ||
ttl: nTTL, | ||
creativeId: sCreativeID, | ||
currency: sCurrency, | ||
netRevenue: bNetRevenue, | ||
ad: sAd | ||
}; | ||
bidResponses.push(bidResponse); | ||
} else { | ||
if (bksdebug) console.log(WHOIS + ' interpretResponse() - serverResponse not valid'); | ||
} | ||
if (bksdebug) console.log(WHOIS + ' interpretResponse() - return', bidResponses); | ||
return bidResponses; | ||
}, | ||
|
||
/** | ||
* ... | ||
* | ||
* @param {object} bid The bid to validate. | ||
* @return ... | ||
*/ | ||
onSetTargeting: function (bid) { | ||
if (bksdebug) console.log(WHOIS + ' onSetTargeting() - INPUT bid:', bid); | ||
}, | ||
|
||
/** | ||
* 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) { | ||
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. Is this code still a work-in-progress? If not and you're not planning to support userSyncs (at least at this time) - you can just remove this function entirely from your adapter. 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. function not needed on this release, we removed. |
||
if (bksdebug) console.log(WHOIS + ' getUserSyncs() - INPUT syncOptions:', syncOptions, 'INPUT serverResponses:', serverResponses); | ||
const syncs = [] | ||
/* | ||
if (syncOptions.iframeEnabled) { | ||
syncs.push({ | ||
type: 'iframe', | ||
url: '//' | ||
}); | ||
} | ||
if (syncOptions.pixelEnabled && serverResponses.length > 0) { | ||
syncs.push({ | ||
type: 'image', | ||
url: serverResponses[0].body.userSync.url | ||
}); | ||
} | ||
*/ | ||
return syncs; | ||
}, | ||
|
||
/** | ||
* ... | ||
* | ||
* @param {object} bid The bid to validate. | ||
* @return ... | ||
*/ | ||
onBidWon: function(bid) { | ||
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. Similar to the getUserSyncs function - you can remove this function if you're not planning 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. function not needed on this release, we removed. |
||
if (bksdebug) console.log(WHOIS + ' onBidWon() - INPUT bid:', bid); | ||
}, | ||
|
||
/** | ||
* ... | ||
* | ||
* @param ... | ||
* @return ... | ||
*/ | ||
onTimeout: function(timeoutData) { | ||
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. Similar to the getUserSyncs function - you can remove this function if you're not planning 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. function not needed on this release, we removed. |
||
if (bksdebug) console.log(WHOIS + ' onTimeout() - INPUT timeoutData:', timeoutData); | ||
}, | ||
}; | ||
|
||
registerBidder(spec); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Bucksense Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: [email protected] | ||
``` | ||
|
||
# Description | ||
|
||
Use `bucksense` as bidder. | ||
|
||
`placementId` is required, use the Placement ID received by Bucksense. | ||
|
||
|
||
Module that connects to Example's demand sources | ||
|
||
## AdUnits configuration example | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'test-div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]], | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: "bucksense", | ||
params: { | ||
placementId : 1000 | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import {expect} from 'chai'; | ||
import {spec} from 'modules/bucksenseBidAdapter'; | ||
|
||
describe('the bucksense adapter', function() { | ||
function getValidBidObject() { | ||
return { | ||
bidId: 12345, | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]] | ||
} | ||
}, | ||
params: { | ||
placementId: 1000, | ||
} | ||
}; | ||
}; | ||
|
||
describe('isBidRequestValid', function() { | ||
var bid; | ||
|
||
beforeEach(function() { | ||
bid = getValidBidObject(); | ||
}); | ||
|
||
it('should fail validation if the bid isn\'t defined or not an object', function() { | ||
var result = spec.isBidRequestValid(); | ||
|
||
expect(result).to.equal(false); | ||
|
||
result = spec.isBidRequestValid('not an object'); | ||
|
||
expect(result).to.equal(false); | ||
}); | ||
}); | ||
|
||
describe('buildRequests', function() { | ||
var bid, bidRequestObj; | ||
|
||
beforeEach(function() { | ||
bid = getValidBidObject(); | ||
bidRequestObj = {}; | ||
}); | ||
|
||
it('should build a very basic request', function() { | ||
var request = spec.buildRequests([bid], bidRequestObj); | ||
expect(request[0].method).to.equal('POST'); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', function() { | ||
var serverResponse; | ||
|
||
beforeEach(function() { | ||
serverResponse = { | ||
body: { | ||
'requestId': '', | ||
'cpm': 0.3, | ||
'width': 300, | ||
'height': 250, | ||
'ttl': 360, | ||
'creativeId': 'creative002', | ||
'currency': 'USD', | ||
'netRevenue': false, | ||
'ad': '<div id=\"bks-banner\"><a href=\"https://www.bucksense.com\" target=\"_blank\"><img src=\"https://i.bksn.se/s/1334/c5acdc75ba096bk.jpg\" width=\"300\" height=\"250\"/></a></div>' | ||
} | ||
}; | ||
}); | ||
|
||
it('should return an array of bid responses', function() { | ||
var responses = spec.interpretResponse(serverResponse); | ||
expect(responses).to.be.an('array').with.length(1); | ||
}); | ||
}); | ||
}); |
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.
In lieu of this PR #3435, any imported files within a modules file needs to use the relative style path.
Can you please update these imports accordingly?
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.
fixed with new Push