Skip to content

Commit

Permalink
ucfunnel Bid Adapter: add support Price Floors Module
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhsiehucf committed May 21, 2021
1 parent 97421e1 commit 8fb460e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
36 changes: 34 additions & 2 deletions modules/ucfunnelBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const COOKIE_NAME = 'ucf_uid';
const VER = 'ADGENT_PREBID-2018011501';
const BIDDER_CODE = 'ucfunnel';
const GVLID = 607;
const CURRENCY = 'USD';
const VIDEO_CONTEXT = {
INSTREAM: 0,
OUSTREAM: 2
Expand Down Expand Up @@ -210,12 +211,39 @@ function getSupplyChain(schain) {
return supplyChain;
}

function getMediaType(mediaTypes) {
if (mediaTypes != null && mediaTypes.video) {
return 'video';
} else if (mediaTypes != null && mediaTypes.native) {
return 'native'
}
return 'banner';
}

function getFloor(bid, size, mediaTypes) {
if (bid.params.bidfloor) {
return bid.params.bidfloor;
}
if (typeof bid.getFloor === 'function') {
var bidFloor = bid.getFloor({
currency: CURRENCY,
mediaType: getMediaType(mediaTypes),
size: (size) ? [ size[0], size[1] ] : '*',
});
if (bidFloor.currency === CURRENCY) {
return bidFloor.floor;
}
}
return undefined;
}

function getRequestData(bid, bidderRequest) {
const size = parseSizes(bid);
const language = navigator.language;
const dnt = (navigator.doNotTrack == 'yes' || navigator.doNotTrack == '1' || navigator.msDoNotTrack == '1') ? 1 : 0;
const userIdTdid = (bid.userId && bid.userId.tdid) ? bid.userId.tdid : '';
const supplyChain = getSupplyChain(bid.schain);
const bidFloor = getFloor(bid, size, bid.mediaTypes);
// general bid data
let bidData = {
ver: VER,
Expand All @@ -225,9 +253,13 @@ function getRequestData(bid, bidderRequest) {
dnt: dnt,
adid: bid.params.adid,
tdid: userIdTdid,
schain: supplyChain,
fp: bid.params.bidfloor
schain: supplyChain
};

if (bidFloor) {
bidData.fp = bidFloor;
}

addUserId(bidData, bid.userId);
try {
bidData.host = window.top.location.hostname;
Expand Down
38 changes: 36 additions & 2 deletions test/spec/modules/ucfunnelBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const userId = {
const validBannerBidReq = {
bidder: BIDDER_CODE,
params: {
adid: 'ad-34BBD2AA24B678BBFD4E7B9EE3B872D',
bidfloor: 1.0
adid: 'ad-34BBD2AA24B678BBFD4E7B9EE3B872D'
},
sizes: [[300, 250]],
bidId: '263be71e91dd9d',
Expand Down Expand Up @@ -175,6 +174,41 @@ describe('ucfunnel Adapter', function () {
expect(data.w).to.equal(width);
expect(data.h).to.equal(height);
});

it('should set bidfloor if configured', function() {
let bid = Object.assign({}, validBannerBidReq);
bid.getFloor = function() {
return {
currency: 'USD',
floor: 2.02
}
};
const requests = spec.buildRequests([ bid ]);
const data = requests[0].data;
expect(data.fp).to.equal(2.02);
});

it('should set bidfloor if configured', function() {
let bid = Object.assign({}, validBannerBidReq);
bid.params.bidfloor = 2.01;
const requests = spec.buildRequests([ bid ]);
const data = requests[0].data;
expect(data.fp).to.equal(2.01);
});

it('should set bidfloor if configured', function() {
let bid = Object.assign({}, validBannerBidReq);
bid.getFloor = function() {
return {
currency: 'USD',
floor: 2.02
}
};
bid.params.bidfloor = 2.01;
const requests = spec.buildRequests([ bid ]);
const data = requests[0].data;
expect(data.fp).to.equal(2.01);
});
});

describe('interpretResponse', function () {
Expand Down

0 comments on commit 8fb460e

Please sign in to comment.