Skip to content

Commit

Permalink
adding GAM ad unit code to impression ext object (prebid#6861)
Browse files Browse the repository at this point in the history
Co-authored-by: punkiller <pankajkumar555@gmail.com>
  • Loading branch information
2 people authored and agrandes-tappx committed Sep 29, 2021
1 parent 46fb78a commit 086a88f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ function bidToVideoImp(bid) {
return imp;
}

/**
* Converts an incoming PBJS bid to an IX Impression
* @param {object} bid PBJS bid object
* @returns {object} IX impression object
*/
function bidToImp(bid) {
const imp = {};

Expand All @@ -127,6 +132,10 @@ function bidToImp(bid) {
imp.ext.sid = `${bid.params.size[0]}x${bid.params.size[1]}`;
}

const dfpAdUnitCode = utils.deepAccess(bid, 'ortb2Imp.ext.data.adserver.adslot');
if (dfpAdUnitCode) {
imp.ext.dfp_ad_unit_code = dfpAdUnitCode;
}
return imp;
}

Expand Down
26 changes: 26 additions & 0 deletions test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,32 @@ describe('IndexexchangeAdapter', function () {
expect(query.nf).not.to.exist;
});

it('should send dfp_adunit_code in request if ortb2Imp.ext.data.adserver.adslot exists', function () {
const AD_UNIT_CODE = '/19968336/some-adunit-path';
const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID);
validBids[0].ortb2Imp = {
ext: {
data: {
adserver: {
name: 'gam',
adslot: AD_UNIT_CODE
}
}
}
};
const requests = spec.buildRequests(validBids, DEFAULT_OPTION);
const { dfp_ad_unit_code } = JSON.parse(requests[0].data.r).imp[0].ext;
expect(dfp_ad_unit_code).to.equal(AD_UNIT_CODE);
});

it('should not send dfp_adunit_code in request if ortb2Imp.ext.data.adserver.adslot does not exists', function () {
const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID);
const requests = spec.buildRequests(validBids, DEFAULT_OPTION);
const { dfp_ad_unit_code } = JSON.parse(requests[0].data.r).imp[0].ext;

expect(dfp_ad_unit_code).to.not.exist;
});

it('payload should have correct format and value', function () {
const payload = JSON.parse(query.r);
expect(payload.id).to.equal(DEFAULT_BANNER_VALID_BID[0].bidderRequestId);
Expand Down

0 comments on commit 086a88f

Please sign in to comment.