Skip to content

Commit e4ea90f

Browse files
PulsePoint bid adapter: Multi-size support (prebid#4988)
* ET-1691: Pulsepoint Analytics adapter for Prebid. (#1) * ET-1691: Adding pulsepoint analytics and tests for pulsepoint adapter * ET-1691: Adding pulsepoint analytics and tests for pulsepoint adapter * ET-1691: cleanup * ET-1691: minor * ET-1691: revert package.json change * Adding bidRequest to bidFactory.createBid method as per prebid#509 * ET-1765: Adding support for additional params in PulsePoint adapter (#2) * ET-1850: Fixing prebid#866 * Minor fix * Adding mandatory parameters to Bid * PulsePoint: support for banner.format object * AdSize on response for banner responses * Fixing review comment * Reverting package-json changes
1 parent adda4e1 commit e4ea90f

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

modules/pulsepointBidAdapter.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ function bidResponseAvailable(request, response) {
133133
bid.height = idToBidMap[id].h;
134134
} else {
135135
bid.ad = idToBidMap[id].adm;
136-
bid.width = idToImpMap[id].banner.w;
137-
bid.height = idToImpMap[id].banner.h;
136+
bid.width = idToBidMap[id].w || idToImpMap[id].banner.w;
137+
bid.height = idToBidMap[id].h || idToImpMap[id].banner.h;
138138
}
139139
bids.push(bid);
140140
}
@@ -161,14 +161,30 @@ function impression(slot) {
161161
* Produces an OpenRTB Banner object for the slot given.
162162
*/
163163
function banner(slot) {
164-
const size = adSize(slot);
164+
const sizes = parseSizes(slot);
165+
const size = adSize(slot, sizes);
165166
return (slot.nativeParams || slot.params.video) ? null : {
166167
w: size[0],
167168
h: size[1],
168169
battr: slot.params.battr,
170+
format: sizes
169171
};
170172
}
171173

174+
/**
175+
* Produce openrtb format objects based on the sizes configured for the slot.
176+
*/
177+
function parseSizes(slot) {
178+
const sizes = utils.deepAccess(slot, 'mediaTypes.banner.sizes');
179+
if (sizes && utils.isArray(sizes)) {
180+
return sizes.filter(sz => utils.isArray(sz) && sz.length === 2).map(sz => ({
181+
w: sz[0],
182+
h: sz[1]
183+
}));
184+
}
185+
return null;
186+
}
187+
172188
/**
173189
* Produces an OpenRTB Video object for the slot given
174190
*/
@@ -372,12 +388,14 @@ function parse(rawResponse) {
372388
/**
373389
* Determines the AdSize for the slot.
374390
*/
375-
function adSize(slot) {
391+
function adSize(slot, sizes) {
376392
if (slot.params.cf) {
377393
const size = slot.params.cf.toUpperCase().split('X');
378394
const width = parseInt(slot.params.cw || size[0], 10);
379395
const height = parseInt(slot.params.ch || size[1], 10);
380396
return [width, height];
397+
} else if (sizes && sizes.length > 0) {
398+
return [sizes[0].w, sizes[0].h];
381399
}
382400
return [1, 1];
383401
}

test/spec/modules/pulsepointBidAdapter_spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import {deepClone} from 'src/utils.js';
66
describe('PulsePoint Adapter Tests', function () {
77
const slotConfigs = [{
88
placementCode: '/DfpAccount1/slot1',
9+
mediaTypes: {
10+
banner: {
11+
sizes: [[728, 90], [160, 600]]
12+
}
13+
},
914
bidId: 'bid12345',
1015
params: {
1116
cp: 'p10000',
@@ -655,4 +660,45 @@ describe('PulsePoint Adapter Tests', function () {
655660
userVerify(ortbRequest.user.ext.eids[4], 'parrable.com', 'parrable_id234');
656661
userVerify(ortbRequest.user.ext.eids[5], 'liveintent.com', 'liveintent_id123');
657662
});
663+
it('Verify multiple adsizes', function () {
664+
const bidRequests = deepClone(slotConfigs);
665+
const request = spec.buildRequests(bidRequests, bidderRequest);
666+
expect(request).to.be.not.null;
667+
expect(request.data).to.be.not.null;
668+
const ortbRequest = request.data;
669+
expect(ortbRequest.imp).to.have.lengthOf(2);
670+
// first impression has multi sizes
671+
expect(ortbRequest.imp[0].banner).to.not.be.null;
672+
expect(ortbRequest.imp[0].banner.w).to.equal(300);
673+
expect(ortbRequest.imp[0].banner.h).to.equal(250);
674+
expect(ortbRequest.imp[0].banner.format).to.not.be.null;
675+
expect(ortbRequest.imp[0].banner.format).to.have.lengthOf(2);
676+
expect(ortbRequest.imp[0].banner.format[0].w).to.equal(728);
677+
expect(ortbRequest.imp[0].banner.format[0].h).to.equal(90);
678+
expect(ortbRequest.imp[0].banner.format[1].w).to.equal(160);
679+
expect(ortbRequest.imp[0].banner.format[1].h).to.equal(600);
680+
// slot 2
681+
expect(ortbRequest.imp[1].banner).to.not.be.null;
682+
expect(ortbRequest.imp[1].banner.w).to.equal(728);
683+
expect(ortbRequest.imp[1].banner.h).to.equal(90);
684+
expect(ortbRequest.imp[1].banner.format).to.be.null;
685+
// adsize on response
686+
const ortbResponse = {
687+
seatbid: [{
688+
bid: [{
689+
impid: ortbRequest.imp[0].id,
690+
price: 1.25,
691+
adm: 'This is an Ad',
692+
crid: 'Creative#123',
693+
w: 728,
694+
h: 90
695+
}]
696+
}]
697+
};
698+
const bids = spec.interpretResponse({ body: ortbResponse }, request);
699+
expect(bids).to.have.lengthOf(1);
700+
const bid = bids[0];
701+
expect(bid.width).to.equal(728);
702+
expect(bid.height).to.equal(90);
703+
});
658704
});

0 commit comments

Comments
 (0)