-
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
Bidfluence Adapter #1023
Merged
Merged
Bidfluence Adapter #1023
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8d73f66
Bidfluence Adapter
francescocristallo abc88f9
Bidfluence adapter
francescocristallo b3d8475
Fixed callback name
francescocristallo a099b3a
Final review
francescocristallo d1b2b1c
First commit, Test passed
francescocristallo 7951311
Addressed change request (all but the loader one)
francescocristallo 510cc0f
Update reflecting the adapter changes.
francescocristallo 1bcde3b
Final review, completed update requests.
francescocristallo 899fc40
Fixed Indentation
francescocristallo 1e23274
Fixed global variable causing validation error.
francescocristallo 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
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,64 @@ | ||
const bidmanager = require('../bidmanager.js'); | ||
const bidfactory = require('../bidfactory.js'); | ||
const utils = require('../utils.js'); | ||
|
||
var BidfluenceAdapter = function BidfluenceAdapter() { | ||
//Callback | ||
|
||
$$PREBID_GLOBAL$$.bfPbjsCB = function (bfr) { | ||
var bidRequest = utils.getBidRequest(bfr.cbID); | ||
var bidObject = null; | ||
if (bfr.cpm > 0) { | ||
bidObject = bidfactory.createBid(1, bidRequest); | ||
bidObject.bidderCode = 'bidfluence'; | ||
bidObject.cpm = bfr.cpm; | ||
bidObject.ad = bfr.ad; | ||
bidObject.width = bfr.width; | ||
bidObject.height = bfr.height; | ||
} else { | ||
bidObject = bidfactory.createBid(2, bidRequest); | ||
bidObject.bidderCode = 'bidfluence'; | ||
} | ||
|
||
bidmanager.addBidResponse(bfr.placementCode, bidObject); | ||
}; | ||
|
||
function _callBids(params) { | ||
var bfbids = params.bids || []; | ||
for (var i = 0; i < bfbids.length; i++) { | ||
var bid = bfbids[i]; | ||
call(bid); | ||
} | ||
} | ||
|
||
function call(bid) { | ||
var adunitId = utils.getBidIdParameter('adunitId', bid.params); | ||
/* jshint ignore:start */ | ||
var publisherId = utils.getBidIdParameter('pubId', bid.params); | ||
var reservePrice = utils.getBidIdParameter('reservePrice', bid.params); | ||
var pbjsBfobj = { | ||
placementCode: bid.placementCode, | ||
cbID: bid.bidId | ||
}; | ||
/* jshint ignore:end */ | ||
|
||
var s = document.createElement('script'); | ||
s.async = true; | ||
s.id = adunitId; | ||
s.onload = function () { | ||
/* jshint ignore:start */ | ||
FORGE.init([adunitId, publisherId, pbjsBfobj, reservePrice]); | ||
FORGE.fire(); | ||
/* jshint ignore:end */ | ||
}; | ||
s.src = "//bidfluence.azureedge.net/forge.js"; | ||
var b = document.getElementsByTagName('head')[0]; | ||
b.parentNode.insertBefore(s, b); | ||
} | ||
|
||
return { | ||
callBids: _callBids | ||
}; | ||
}; | ||
|
||
module.exports = BidfluenceAdapter; |
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,74 @@ | ||
describe('Bidfluence Adapter', () => { | ||
const expect = require('chai').expect; | ||
const adapter = require('src/adapters/bidfluence'); | ||
const bidmanager = require('src/bidmanager'); | ||
|
||
var REQUEST = { | ||
bidderCode: "bidfluence", | ||
sizes: [[300, 250]], | ||
placementCode: "div-1", | ||
bids: [{ | ||
bidder: 'bidfluence', | ||
params: { | ||
pubId: "747efe9c-5f8a-4b6e-872b-8e9939816298", | ||
adunitId: "c4bbd807-7d22-485f-80f1-ba008ef1c619" | ||
} | ||
}] | ||
}; | ||
|
||
var RESPONSE = { | ||
ad: "ad-code", | ||
cpm: 0.9, | ||
width: 300, | ||
height: 250, | ||
placementCode: "div-1" | ||
}; | ||
|
||
var NO_RESPONSE = { | ||
ad: "ad-code", | ||
cpm: 0, | ||
width: 300, | ||
height: 250, | ||
placementCode: "div-1" | ||
}; | ||
|
||
it('Should exist and be a function', function () { | ||
expect($$PREBID_GLOBAL$$.bfPbjsCB).to.exist.and.to.be.a('function'); | ||
}); | ||
|
||
it('Shoud push a valid bid', () => { | ||
|
||
var stubAddBidResponse = sinon.stub(bidmanager, "addBidResponse"); | ||
pbjs._bidsRequested.push(REQUEST); | ||
adapter(); | ||
$$PREBID_GLOBAL$$.bfPbjsCB(RESPONSE); | ||
|
||
var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; | ||
var bidObject1 = stubAddBidResponse.getCall(0).args[1]; | ||
|
||
expect(bidPlacementCode1).to.equal("div-1",); | ||
expect(bidObject1.getStatusCode()).to.equal(1); | ||
expect(bidObject1.bidderCode).to.equal('bidfluence'); | ||
|
||
stubAddBidResponse.restore(); | ||
}); | ||
|
||
it('Shoud push an empty bid', () => { | ||
|
||
var stubAddBidResponse = sinon.stub(bidmanager, "addBidResponse"); | ||
pbjs._bidsRequested.push(REQUEST); | ||
adapter(); | ||
|
||
$$PREBID_GLOBAL$$.bfPbjsCB(NO_RESPONSE); | ||
|
||
var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; | ||
var bidObject1 = stubAddBidResponse.getCall(0).args[1]; | ||
|
||
expect(bidPlacementCode1).to.equal("div-1",); | ||
expect(bidObject1.getStatusCode()).to.equal(2); | ||
expect(bidObject1.bidderCode).to.equal('bidfluence'); | ||
|
||
stubAddBidResponse.restore(); | ||
|
||
}); | ||
}); |
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.
It is recommended to use loadscript function
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.
I didn't use it because I need to set the Id of the new script element as per line 43, seems the loadscript function does not allow it.
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.
Alright, one question, why would you need an id on script element
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.
It was for legacy code, I spent some time today to fix that. The adapter now loadscript function as requested, all the update requested are complete. Thanks