Skip to content

Commit

Permalink
Add bidFloor to Yieldmo Adapter (prebid#3886)
Browse files Browse the repository at this point in the history
* change userid to pubcid

* removes consolelogs

* removes .txt file

* fixes test

* make the if statement useful

* fix indentation

* move return back to the correct place

* fix indent
  • Loading branch information
HolzAndrew authored and Alex committed Aug 1, 2019
1 parent 45c227f commit fe6d891
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
28 changes: 17 additions & 11 deletions modules/yieldmoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ export const spec = {

bidRequests.forEach((request) => {
serverRequest.p.push(addPlacement(request));
const userId = getUserId(request)
if (userId) {
const pubcid = userId.pubcid;
const pubcid = getPubcId(request)
if (pubcid) {
serverRequest.pubcid = pubcid;
} else if (request.crumbs) {
serverRequest.pubcid = request.crumbs.pubcid;
if (request.crumbs.pubcid) {
serverRequest.pubcid = request.crumbs.pubcid;
}
}
});
serverRequest.p = '[' + serverRequest.p.toString() + ']';
Expand Down Expand Up @@ -103,8 +104,13 @@ function addPlacement(request) {
callback_id: request.bidId,
sizes: request.sizes
}
if (request.params && request.params.placementId) {
placementInfo.ym_placement_id = request.params.placementId
if (request.params) {
if (request.params.placementId) {
placementInfo.ym_placement_id = request.params.placementId;
}
if (request.params.bidFloor) {
placementInfo.bidFloor = request.params.bidFloor;
}
}
return JSON.stringify(placementInfo);
}
Expand Down Expand Up @@ -311,10 +317,10 @@ function isMraid() {
return !!(window.mraid);
}

function getUserId(request) {
let userId;
if (request && request.userId && typeof request.userId === 'object') {
userId = request.userId;
function getPubcId(request) {
let pubcid;
if (request && request.userId && request.userId.pubcid && typeof request.userId === 'object') {
pubcid = request.userId.pubcid;
}
return userId;
return pubcid;
}
3 changes: 2 additions & 1 deletion modules/yieldmoBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ var adUnits = [
bids: [{
bidder: 'yieldmo',
params: {
placementId: '1779781193098233305' // string with at most 19 characters (may include numbers only)
placementId: '1779781193098233305', // string with at most 19 characters (may include numbers only)
bidFloor: .28 // optional param
}
}]
}
Expand Down
21 changes: 13 additions & 8 deletions test/spec/modules/yieldmoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ describe('YieldmoAdapter', function () {

let bid = {
bidder: 'yieldmo',
params: {},
params: {
bidFloor: 0.1
},
adUnitCode: 'adunit-code',
sizes: [[300, 250], [300, 600]],
bidId: '30b31c1838de1e',
Expand Down Expand Up @@ -59,11 +61,13 @@ describe('YieldmoAdapter', function () {

it('should place bid information into the p parameter of data', function () {
let placementInfo = spec.buildRequests(bidArray).data.p;
expect(placementInfo).to.equal('[{"placement_id":"adunit-code","callback_id":"30b31c1838de1e","sizes":[[300,250],[300,600]]}]');
expect(placementInfo).to.equal('[{"placement_id":"adunit-code","callback_id":"30b31c1838de1e","sizes":[[300,250],[300,600]],"bidFloor":0.1}]');

bidArray.push({
bidder: 'yieldmo',
params: {},
params: {
bidFloor: 0.2
},
adUnitCode: 'adunit-code-1',
sizes: [[300, 250], [300, 600]],
bidId: '123456789',
Expand All @@ -77,19 +81,19 @@ describe('YieldmoAdapter', function () {

// multiple placements
placementInfo = spec.buildRequests(bidArray).data.p;
expect(placementInfo).to.equal('[{"placement_id":"adunit-code","callback_id":"30b31c1838de1e","sizes":[[300,250],[300,600]]},{"placement_id":"adunit-code-1","callback_id":"123456789","sizes":[[300,250],[300,600]]}]');
expect(placementInfo).to.equal('[{"placement_id":"adunit-code","callback_id":"30b31c1838de1e","sizes":[[300,250],[300,600]],"bidFloor":0.1},{"placement_id":"adunit-code-1","callback_id":"123456789","sizes":[[300,250],[300,600]],"bidFloor":0.2}]');
});

it('should add placement id if given', function () {
bidArray[0].params.placementId = 'ym_1293871298';
let placementInfo = spec.buildRequests(bidArray).data.p;
expect(placementInfo).to.include('"ym_placement_id":"ym_1293871298"}');
expect(placementInfo).not.to.include('"ym_placement_id":"ym_0987654321"}');
expect(placementInfo).to.include('"ym_placement_id":"ym_1293871298"');
expect(placementInfo).not.to.include('"ym_placement_id":"ym_0987654321"');

bidArray[1].params.placementId = 'ym_0987654321';
placementInfo = spec.buildRequests(bidArray).data.p;
expect(placementInfo).to.include('"ym_placement_id":"ym_1293871298"}');
expect(placementInfo).to.include('"ym_placement_id":"ym_0987654321"}');
expect(placementInfo).to.include('"ym_placement_id":"ym_1293871298"');
expect(placementInfo).to.include('"ym_placement_id":"ym_0987654321"');
});

it('should add additional information to data parameter of request', function () {
Expand All @@ -104,6 +108,7 @@ describe('YieldmoAdapter', function () {
expect(data.hasOwnProperty('title')).to.be.true;
expect(data.hasOwnProperty('h')).to.be.true;
expect(data.hasOwnProperty('w')).to.be.true;
expect(data.hasOwnProperty('pubcid')).to.be.true;
})

it('should add pubcid as parameter of request', function () {
Expand Down

0 comments on commit fe6d891

Please sign in to comment.