Skip to content

Commit

Permalink
Multiple changes added (prebid#7343)
Browse files Browse the repository at this point in the history
* Video request schain support
* Optional device.ip param support
* gpid support added
  • Loading branch information
ym-abaranov authored and Chris Pabst committed Jan 10, 2022
1 parent fdaa696 commit 7f39127
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
24 changes: 21 additions & 3 deletions modules/yieldmoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ function hasVideoMediaType(bidRequest) {
* @param request bid request
*/
function addPlacement(request) {
const gpid = utils.deepAccess(request, 'ortb2Imp.ext.data.pbadslot');
const placementInfo = {
placement_id: request.adUnitCode,
callback_id: request.bidId,
Expand All @@ -196,6 +197,9 @@ function addPlacement(request) {
placementInfo.bidFloor = bidfloor;
}
}
if (gpid) {
placementInfo.gpid = gpid;
}
return JSON.stringify(placementInfo);
}

Expand Down Expand Up @@ -315,12 +319,13 @@ function getId(request, idType) {
* @return Object OpenRTB request object
*/
function openRtbRequest(bidRequests, bidderRequest) {
const schain = bidRequests[0].schain;
let openRtbRequest = {
id: bidRequests[0].bidderRequestId,
at: 1,
imp: bidRequests.map(bidRequest => openRtbImpression(bidRequest)),
site: openRtbSite(bidRequests[0], bidderRequest),
device: openRtbDevice(),
device: openRtbDevice(bidRequests[0]),
badv: bidRequests[0].params.badv || [],
bcat: bidRequests[0].params.bcat || [],
ext: {
Expand All @@ -329,6 +334,10 @@ function openRtbRequest(bidRequests, bidderRequest) {
ats_envelope: bidRequests[0].params.lr_env,
};

if (schain) {
openRtbRequest.schain = schain;
}

populateOpenRtbGdpr(openRtbRequest, bidderRequest);

return openRtbRequest;
Expand All @@ -339,6 +348,7 @@ function openRtbRequest(bidRequests, bidderRequest) {
* @return Object OpenRTB's 'imp' (impression) object
*/
function openRtbImpression(bidRequest) {
const gpid = utils.deepAccess(bidRequest, 'ortb2Imp.ext.data.pbadslot');
const size = extractPlayerSize(bidRequest);
const imp = {
id: bidRequest.bidId,
Expand Down Expand Up @@ -372,6 +382,9 @@ function openRtbImpression(bidRequest) {
imp.video.startdelay = DEFAULT_START_DELAY;
imp.video.playbackmethod = [ DEFAULT_PLAYBACK_METHOD ];
}
if (gpid) {
imp.ext.gpid = gpid;
}
return imp;
}

Expand Down Expand Up @@ -433,11 +446,16 @@ function openRtbSite(bidRequest, bidderRequest) {
/**
* @return Object OpenRTB's 'device' object
*/
function openRtbDevice() {
return {
function openRtbDevice(bidRequest) {
const ip = utils.deepAccess(bidRequest, 'params.device.ip');
const deviceObj = {
ua: navigator.userAgent,
language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage),
};
if (ip) {
deviceObj.ip = ip;
}
return deviceObj;
}

/**
Expand Down
45 changes: 41 additions & 4 deletions test/spec/modules/yieldmoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,23 @@ describe('YieldmoAdapter', function () {

localWindow.document.title = originalTitle;
});

it('should add ats_envelope to banner bid request', function() {
const envelope = 'test_envelope';
const requests = build([mockBannerBid({}, { lr_env: envelope })]);

expect(requests[0].data.ats_envelope).to.equal(envelope);
});

it('should add gpid to the banner bid request', function () {
let bidArray = [mockBannerBid({
ortb2Imp: {
ext: { data: { pbadslot: '/6355419/Travel/Europe/France/Paris' } },
}
})];
let placementInfo = buildAndGetPlacementInfo(bidArray);
expect(placementInfo).to.include('"gpid":"/6355419/Travel/Europe/France/Paris"');
});
});

describe('Instream video:', function () {
Expand Down Expand Up @@ -439,11 +456,31 @@ describe('YieldmoAdapter', function () {
expect(requests[0].data.ats_envelope).to.equal(envelope);
});

it('should add ats_envelope to banner bid request', function() {
const envelope = 'test_envelope';
const requests = build([mockBannerBid({}, { lr_env: envelope })]);
it('should add schain if it is in the bidRequest', () => {
const schain = {
ver: '1.0',
complete: 1,
nodes: [{
asi: 'indirectseller.com',
sid: '00001',
hp: 1
}],
};
expect(buildAndGetData([mockVideoBid({schain})]).schain).to.deep.equal(schain);
});

expect(requests[0].data.ats_envelope).to.equal(envelope);
it('should add ip to the video bidRequest', () => {
const device = {
ip: '111.222.333.444'
};
expect(buildAndGetData([mockVideoBid(null, {device})]).device.ip).to.be.equal(device.ip);
});

it('should add gpid to the video request', function () {
const ortb2Imp = {
ext: { data: { pbadslot: '/6355419/Travel/Europe/France/Paris' } },
};
expect(buildAndGetData([mockVideoBid({ortb2Imp})]).imp[0].ext.gpid).to.be.equal(ortb2Imp.ext.data.pbadslot);
});
});
});
Expand Down

0 comments on commit 7f39127

Please sign in to comment.